ImageJ how can i draw a polygon on a new picture?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

ImageJ how can i draw a polygon on a new picture?

greendoki
Hi

i'm new in the imageJ, and i have to make a plugin in java which: if you have a polygon slection, it makes a mask which is the same size as the picture and make the selection black and the not selected is white...

so i have made:
1.: open an image
1/b.: make a polygon slection
2.: make a new mask
3.: triing to draw a new polygon, but gut a null pointer exeption.
(Graphics g=null;
g.drawPolygon(p.xpoints, p.ypoints, p.npoints);)

please help me how can i make polygon on the mask?
Reply | Threaded
Open this post in threaded view
|

Re: ImageJ how can i draw a polygon on a new picture?

Michael Schmid
Hi David,

if you write
> Graphics g=null;
> g.drawPolygon(p.xpoints, p.ypoints, p.npoints);
must get a NullPointerException because g = null, so you can't call a method of the Object g.

Why not simply use
  IJ.run("Create Mask");
It will create an ImagePlus with the mask.

If you don't want an ImagePlus but only an ImageProcessor, type lowercase L in ImageJ, search for 'create mask" select 'show full information' and type 'Source'. YOu can then have a look at the sourcecode, in this case ij.plugin.Selection.createMask.

There you can steal the code for how to create an ImageProcessor with the mask, basically
  Roi roi = imp.getRoi();
  ImageProcessor ip = new ByteProcessor(imp.getWidth(), imp.getHeight());
  ip.setRoi(roi);
  ip.setValue(255);
  ip.fill(ip.getMask());


Michael
________________________________________________________________
On Nov 28, 2012, at 16:33, greendoki wrote:

> Hi
>
> i'm new in the imageJ, and i have to make a plugin in java which: if you
> have a polygon slection, it makes a mask which is the same size as the
> picture and make the selection black and the not selected is white...
>
> so i have made:
> 1.: open an image
> 1/b.: make a polygon slection
> 2.: make a new mask
> 3.: triing to draw a new polygon, but gut a null pointer exeption.
> (Graphics g=null;
> g.drawPolygon(p.xpoints, p.ypoints, p.npoints);)
>
> please help me how can i make polygon on the mask?
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: ImageJ how can i draw a polygon on a new picture?

greendoki
2012.11.29. 10:33 keltezéssel, Michael Schmid-3 [via ImageJ] írta:
Hi David,

if you write
> Graphics g=null;
> g.drawPolygon(p.xpoints, p.ypoints, p.npoints);
must get a NullPointerException because g = null, so you can't call a method of the Object g.

Why not simply use
  IJ.run("Create Mask");
It will create an ImagePlus with the mask.

If you don't want an ImagePlus but only an ImageProcessor, type lowercase L in ImageJ, search for 'create mask" select 'show full information' and type 'Source'. YOu can then have a look at the sourcecode, in this case ij.plugin.Selection.createMask.

There you can steal the code for how to create an ImageProcessor with the mask, basically
  Roi roi = imp.getRoi();
  ImageProcessor ip = new ByteProcessor(imp.getWidth(), imp.getHeight());
  ip.setRoi(roi);
  ip.setValue(255);
  ip.fill(ip.getMask());


Michael
________________________________________________________________
On Nov 28, 2012, at 16:33, greendoki wrote:

> Hi
>
> i'm new in the imageJ, and i have to make a plugin in java which: if you
> have a polygon slection, it makes a mask which is the same size as the
> picture and make the selection black and the not selected is white...
>
> so i have made:
> 1.: open an image
> 1/b.: make a polygon slection
> 2.: make a new mask
> 3.: triing to draw a new polygon, but gut a null pointer exeption.
> (Graphics g=null;
> g.drawPolygon(p.xpoints, p.ypoints, p.npoints);)
>
> please help me how can i make polygon on the mask?
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html



If you reply to this email, your message will be added to the discussion below:
http://imagej.1557.n6.nabble.com/ImageJ-how-can-i-draw-a-polygon-on-a-new-picture-tp5000988p5001005.html
To unsubscribe from ImageJ how can i draw a polygon on a new picture?, click here.
NAML
Can u pls tell me how can i save this mask?

Thanks for your answers!

-- 
Üdvözlettel:
Lakatos Dávid
[hidden email]