Hello Everyone
I am kind of new in Java and imageJ. I have been trying to implement one plugin that can calculate some parameters of image. I dont know how can i do that but i want the roi to be divided into three equivalent parts when i am drawing it with the mouse on the image. Like the rectangle that i am drawing shall also have two more lines in between dividing the rectangle into three equivalent parts. I'll be really thankful if some one can help me out with that. I have been trying to override the drawpixels() funtion in the ROI class but i guess that wont help me achieving my target on runtime because i want the roi to be divided into three parts what i am drawing the rectangle with mouse on image. thanks Ahsan |
Hello,
Have a look to ROI API: http://rsbweb.nih.gov/ij/developer/api/ij/gui/Roi.html There you can see the ROI types and the way to build them from different shapes. Maybe you can create three rectangles from the original ROI (to get the original one: <imageplus>.getRoi().getBounds(): Rectangle) and then use a ShapeRoi... The stuff related to events, so you can draw the "splitted roi" while dragging the mouse, might be difficult. I don't know if ImageCanvas has something like "drawRois()" which can be overriden. In that case you might find this code interesting (I adapted it from RoiManager and my plugin invokes it when items from a list are selected): private static void drawROIs(ImagePlus imp, Object rois[], int indexes[]) { ImageCanvas canvas = imp.getCanvas(); Graphics g = canvas.getGraphics(); canvas.update(g); g.setColor(roisColor); for (int i = 0; i < rois.length; i++) { String label = "[" + (indexes != null ? indexes[i] : i) + "]"; Roi roi = rois[i]; if (roi.getType() == Roi.COMPOSITE) { roi.setImage(imp); Color c = roi.getColor(); roi.setColor(roisColor); roi.draw(g); roi.setColor(c); } else { Polygon p = roi.getPolygon(); int x1 = 0, y1 = 0, x2 = 0, y2 = 0; for (int j = 0; j < p.npoints; j++) { x2 = canvas.screenX(p.xpoints[j]); y2 = canvas.screenY(p.ypoints[j]); if (j > 0) { g.drawLine(x1, y1, x2, y2); } x1 = x2; y1 = y2; } if (roi.isArea() && p.npoints > 0) { int x0 = canvas.screenX(p.xpoints[0]); int y0 = canvas.screenY(p.ypoints[0]); g.drawLine(x1, y1, x0, y0); } } drawRoiLabel(label, canvas, roi.getBounds()); } } private static void drawRoiLabel(String label, ImageCanvas canvas, Rectangle r) { Graphics g = canvas.getGraphics(); int x = canvas.screenX(r.x); int y = canvas.screenY(r.y); double mag = canvas.getMagnification(); int width = (int) (r.width * mag); int height = (int) (r.height * mag); int size = width > 40 && height > 40 ? 12 : 9; if (size == 12) { g.setFont(largeFont); } else { g.setFont(smallFont); } FontMetrics metrics = g.getFontMetrics(); int labelW = metrics.stringWidth(label); int labelH = metrics.getHeight(); g.setColor(roisColor); g.fillRect(x, y, labelW, labelH); y += labelH - 3; g.setColor(labelColor); g.drawString(label, x, y); } Good luck!! Juanjo. On Aug 5, 2011, at 12:25 PM, ashamim wrote: > Hello Everyone > > I am kind of new in Java and imageJ. I have been trying to implement one > plugin that can calculate some parameters of image. I dont know how can i do > that but i want the roi to be divided into three equivalent parts when i am > drawing it with the mouse on the image. Like the rectangle that i am drawing > shall also have two more lines in between dividing the rectangle into three > equivalent parts. I'll be really thankful if some one can help me out with > that. I have been trying to override the drawpixels() funtion in the ROI > class but i guess that wont help me achieving my target on runtime because i > want the roi to be divided into three parts what i am drawing the rectangle > with mouse on image. > > thanks > > Ahsan > > ----- > Ahsan > -- > View this message in context: http://imagej.588099.n2.nabble.com/How-Can-I-modify-the-ROI-tp6655988p6655988.html > Sent from the ImageJ mailing list archive at Nabble.com. ------------------------------------------------------------ Juanjo Vega ([hidden email]) Unidad de Biocomputación. Laboratorio B-13. Centro Nacional de Biotecnología. CNB-CSIC. C\ Darwin, 3. Campus de Cantoblanco. Universidad Autónoma de Madrid. 28049, Madrid, Spain. http://www.cnb.csic.es http://www.biocomp.cnb.csic.es +34 91 585 4510 "Las mejores almas son capaces de los mayores vicios como de las mayores virtudes, y aquellos que caminan despacio por el camino recto pueden llegar más lejos que los que corren pero se apartan de él." - Discurso del Método, René Descartes. |
In reply to this post by ashamim
Hi,
I wouldlike to transfer one or more of the Images opened in IJ to another JVM. The way I think is best suited here is to use the system clipboard. As the class that is to be copied into the clipboard needs to implement Serializable, I wanted to be clever and defined a new class that holds an array of ImagePlus and implements Serializable: public class imparraytranse implements Serializable { // ImagePlus[] theImpArray; public imparraytranse(ImagePlus[] totransfer){ theImpArray = totransfer; } public imparraytranse(int length){ theImpArray = new ImagePlus[length]; } public void setImps(ImagePlus[] totransfer){ for (int i=0;i<theImpArray.length;i++){ theImpArray[i] = totransfer[i].createImagePlus(); // somehow, duplicate() doesn't work theImpArray[i].setImage(totransfer[i].getImage()); } } public ImagePlus[] getTheThing(){ return theImpArray; } } this, I used in my transferable: class impATransferable implements Transferable { public impATransferable(imparraytranse transimpArray) { ImagePlus[] dummy = transimpArray.getTheThing(); theimpArray = new imparraytranse(dummy.length); theimpArray.setImps(dummy); } public DataFlavor[] getTransferDataFlavors() { return supportedFlavors; } public boolean isDataFlavorSupported(DataFlavor flavor) { return flavor.equals(imparFlavor); } public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException { if (flavor.equals(imparFlavor)) { return theimpArray; } else { throw new UnsupportedFlavorException(flavor); } } private imparraytranse theimpArray; protected static DataFlavor imparFlavor = new DataFlavor(imparraytranse.class, "impArrayFlavor"); protected static DataFlavor[] supportedFlavors = {imparFlavor}; } in my program, I copy an ImagePlus Array into the clipboard Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); imparraytranse totrans = new imparraytranse(imps.length); totrans.setImps(imps); impATransferable selection = new impATransferable(totrans); clipboard.setContents(selection, null); which seems ok. I can check what is in the clipboard: DataFlavor[] dfs = clipboard.getAvailableDataFlavors(); and get something out which looks fine. but when I want to retrieve the clipboard content: imparraytranse imptrans = (imparraytranse) clipboard.getData(flavor); I get an exception "java.io.NotSerializableException: ij.ImagePlus" The whole thing works, though, when I do the very same thing with an array of strings instead of ImagePluses. So was my idea with going via the extra class implementing serializable bad? How else could I do this? i wouldlike to keep the metadata - that is why I do not use an array of simple java images. Best Heinrich |
In reply to this post by Juanjo Vega
thanks alot Juanjo. I'll just have a look in it and c if it could help.
|
In reply to this post by Heerpa
On Aug 5, 2011, at 8:47 AM, Heinrich Grabmayr wrote:
> Hi, > > I wouldlike to transfer one or more of the Images opened in IJ to > another JVM. The way I think is best suited here is to use the system > clipboard. > As the class that is to be copied into the clipboard needs to implement > Serializable, I wanted to be clever and defined a new class that holds > an array of ImagePlus and implements Serializable: The ImageJ 1.45m daily build adds methods for serializing (as a TIFF-encoded array of bytes) and deserializing ImagePlus objects. Here is a JavaScript example: imp = IJ.getImage(); bytes = new FileSaver(imp).serialize(); imp2 = new Opener().deserialize(bytes); imp2.show(); -wayne > public class imparraytranse implements Serializable > { > // > ImagePlus[] theImpArray; > public imparraytranse(ImagePlus[] totransfer){ > theImpArray = totransfer; > } > public imparraytranse(int length){ > theImpArray = new ImagePlus[length]; > } > public void setImps(ImagePlus[] totransfer){ > for (int i=0;i<theImpArray.length;i++){ > theImpArray[i] = totransfer[i].createImagePlus(); // > somehow, duplicate() doesn't work > theImpArray[i].setImage(totransfer[i].getImage()); > } > } > public ImagePlus[] getTheThing(){ > return theImpArray; > } > } > > > this, I used in my transferable: > > class impATransferable implements Transferable { > > public impATransferable(imparraytranse transimpArray) { > ImagePlus[] dummy = transimpArray.getTheThing(); > theimpArray = new imparraytranse(dummy.length); > theimpArray.setImps(dummy); > } > > public DataFlavor[] getTransferDataFlavors() { > return supportedFlavors; > } > > public boolean isDataFlavorSupported(DataFlavor flavor) { > return flavor.equals(imparFlavor); > } > > public Object getTransferData(DataFlavor flavor) throws > UnsupportedFlavorException { > if (flavor.equals(imparFlavor)) { > return theimpArray; > } > else { > throw new UnsupportedFlavorException(flavor); > } > } > > private imparraytranse theimpArray; > protected static DataFlavor imparFlavor = new > DataFlavor(imparraytranse.class, "impArrayFlavor"); > protected static DataFlavor[] supportedFlavors = {imparFlavor}; > } > > > > in my program, I copy an ImagePlus Array into the clipboard > > Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); > imparraytranse totrans = new imparraytranse(imps.length); > totrans.setImps(imps); > impATransferable selection = new impATransferable(totrans); > clipboard.setContents(selection, null); > > which seems ok. I can check what is in the clipboard: > > DataFlavor[] dfs = clipboard.getAvailableDataFlavors(); > > and get something out which looks fine. > > but when I want to retrieve the clipboard content: > > imparraytranse imptrans = (imparraytranse) clipboard.getData(flavor); > > I get an exception "java.io.NotSerializableException: ij.ImagePlus" > > > The whole thing works, though, when I do the very same thing with an > array of strings instead of ImagePluses. > So was my idea with going via the extra class implementing serializable > bad? How else could I do this? i wouldlike to keep the metadata - that > is why I do not use an array of simple java images. > > Best > Heinrich |
Hi wayne,
thanks for the hint. I have now tried to make it work, but even with a 1.45m version of ij.jar, the compiler tells me it doesn't know FileSaver nor opener, nor the .serialize() function. Is there a trick to that? best Heinrich Am 05.08.2011 20:28, schrieb Rasband, Wayne (NIH/NIMH) [E]: > On Aug 5, 2011, at 8:47 AM, Heinrich Grabmayr wrote: > >> Hi, >> >> I wouldlike to transfer one or more of the Images opened in IJ to >> another JVM. The way I think is best suited here is to use the system >> clipboard. >> As the class that is to be copied into the clipboard needs to implement >> Serializable, I wanted to be clever and defined a new class that holds >> an array of ImagePlus and implements Serializable: > The ImageJ 1.45m daily build adds methods for serializing (as a TIFF-encoded array of bytes) and deserializing ImagePlus objects. Here is a JavaScript example: > > imp = IJ.getImage(); > bytes = new FileSaver(imp).serialize(); > imp2 = new Opener().deserialize(bytes); > imp2.show(); > > -wayne > > >> public class imparraytranse implements Serializable >> { >> // >> ImagePlus[] theImpArray; >> public imparraytranse(ImagePlus[] totransfer){ >> theImpArray = totransfer; >> } >> public imparraytranse(int length){ >> theImpArray = new ImagePlus[length]; >> } >> public void setImps(ImagePlus[] totransfer){ >> for (int i=0;i<theImpArray.length;i++){ >> theImpArray[i] = totransfer[i].createImagePlus(); // >> somehow, duplicate() doesn't work >> theImpArray[i].setImage(totransfer[i].getImage()); >> } >> } >> public ImagePlus[] getTheThing(){ >> return theImpArray; >> } >> } >> >> >> this, I used in my transferable: >> >> class impATransferable implements Transferable { >> >> public impATransferable(imparraytranse transimpArray) { >> ImagePlus[] dummy = transimpArray.getTheThing(); >> theimpArray = new imparraytranse(dummy.length); >> theimpArray.setImps(dummy); >> } >> >> public DataFlavor[] getTransferDataFlavors() { >> return supportedFlavors; >> } >> >> public boolean isDataFlavorSupported(DataFlavor flavor) { >> return flavor.equals(imparFlavor); >> } >> >> public Object getTransferData(DataFlavor flavor) throws >> UnsupportedFlavorException { >> if (flavor.equals(imparFlavor)) { >> return theimpArray; >> } >> else { >> throw new UnsupportedFlavorException(flavor); >> } >> } >> >> private imparraytranse theimpArray; >> protected static DataFlavor imparFlavor = new >> DataFlavor(imparraytranse.class, "impArrayFlavor"); >> protected static DataFlavor[] supportedFlavors = {imparFlavor}; >> } >> >> >> >> in my program, I copy an ImagePlus Array into the clipboard >> >> Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); >> imparraytranse totrans = new imparraytranse(imps.length); >> totrans.setImps(imps); >> impATransferable selection = new impATransferable(totrans); >> clipboard.setContents(selection, null); >> >> which seems ok. I can check what is in the clipboard: >> >> DataFlavor[] dfs = clipboard.getAvailableDataFlavors(); >> >> and get something out which looks fine. >> >> but when I want to retrieve the clipboard content: >> >> imparraytranse imptrans = (imparraytranse) clipboard.getData(flavor); >> >> I get an exception "java.io.NotSerializableException: ij.ImagePlus" >> >> >> The whole thing works, though, when I do the very same thing with an >> array of strings instead of ImagePluses. >> So was my idea with going via the extra class implementing serializable >> bad? How else could I do this? i wouldlike to keep the metadata - that >> is why I do not use an array of simple java images. >> >> Best >> Heinrich |
I think you may need to update to the daily build, because versions
1.45m# are earlier than version 1.45m (the final "m" subversion). Bill On 8/25/11 12:42 PM, Heinrich Grabmayr wrote: > Hi wayne, > > thanks for the hint. > I have now tried to make it work, but even with a 1.45m version of > ij.jar, the compiler tells me it doesn't know FileSaver nor opener, nor > the .serialize() function. Is there a trick to that? > > best Heinrich > > > Am 05.08.2011 20:28, schrieb Rasband, Wayne (NIH/NIMH) [E]: >> On Aug 5, 2011, at 8:47 AM, Heinrich Grabmayr wrote: >> >>> Hi, >>> >>> I wouldlike to transfer one or more of the Images opened in IJ to >>> another JVM. The way I think is best suited here is to use the system >>> clipboard. >>> As the class that is to be copied into the clipboard needs to implement >>> Serializable, I wanted to be clever and defined a new class that holds >>> an array of ImagePlus and implements Serializable: >> The ImageJ 1.45m daily build adds methods for serializing (as a TIFF-encoded array of bytes) and deserializing ImagePlus objects. Here is a JavaScript example: >> >> imp = IJ.getImage(); >> bytes = new FileSaver(imp).serialize(); >> imp2 = new Opener().deserialize(bytes); >> imp2.show(); >> >> -wayne >> >> >>> public class imparraytranse implements Serializable >>> { >>> // >>> ImagePlus[] theImpArray; >>> public imparraytranse(ImagePlus[] totransfer){ >>> theImpArray = totransfer; >>> } >>> public imparraytranse(int length){ >>> theImpArray = new ImagePlus[length]; >>> } >>> public void setImps(ImagePlus[] totransfer){ >>> for (int i=0;i<theImpArray.length;i++){ >>> theImpArray[i] = totransfer[i].createImagePlus(); // >>> somehow, duplicate() doesn't work >>> theImpArray[i].setImage(totransfer[i].getImage()); >>> } >>> } >>> public ImagePlus[] getTheThing(){ >>> return theImpArray; >>> } >>> } >>> >>> >>> this, I used in my transferable: >>> >>> class impATransferable implements Transferable { >>> >>> public impATransferable(imparraytranse transimpArray) { >>> ImagePlus[] dummy = transimpArray.getTheThing(); >>> theimpArray = new imparraytranse(dummy.length); >>> theimpArray.setImps(dummy); >>> } >>> >>> public DataFlavor[] getTransferDataFlavors() { >>> return supportedFlavors; >>> } >>> >>> public boolean isDataFlavorSupported(DataFlavor flavor) { >>> return flavor.equals(imparFlavor); >>> } >>> >>> public Object getTransferData(DataFlavor flavor) throws >>> UnsupportedFlavorException { >>> if (flavor.equals(imparFlavor)) { >>> return theimpArray; >>> } >>> else { >>> throw new UnsupportedFlavorException(flavor); >>> } >>> } >>> >>> private imparraytranse theimpArray; >>> protected static DataFlavor imparFlavor = new >>> DataFlavor(imparraytranse.class, "impArrayFlavor"); >>> protected static DataFlavor[] supportedFlavors = {imparFlavor}; >>> } >>> >>> >>> >>> in my program, I copy an ImagePlus Array into the clipboard >>> >>> Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); >>> imparraytranse totrans = new imparraytranse(imps.length); >>> totrans.setImps(imps); >>> impATransferable selection = new impATransferable(totrans); >>> clipboard.setContents(selection, null); >>> >>> which seems ok. I can check what is in the clipboard: >>> >>> DataFlavor[] dfs = clipboard.getAvailableDataFlavors(); >>> >>> and get something out which looks fine. >>> >>> but when I want to retrieve the clipboard content: >>> >>> imparraytranse imptrans = (imparraytranse) clipboard.getData(flavor); >>> >>> I get an exception "java.io.NotSerializableException: ij.ImagePlus" >>> >>> >>> The whole thing works, though, when I do the very same thing with an >>> array of strings instead of ImagePluses. >>> So was my idea with going via the extra class implementing serializable >>> bad? How else could I do this? i wouldlike to keep the metadata - that >>> is why I do not use an array of simple java images. >>> >>> Best >>> Heinrich > . > |
Free forum by Nabble | Edit this page |