Hi,
i have several regions of interest as PolygonRoi in an ImagePlus object that i want to extract to extra ImagePlus objects. My attempts with ImagePlus plus = new ImagePlus(..) ; plus.setRoi(polyRoi); // plus.copy(true); ImagePlus iplus= ImagePlus.getClipboard(); iplus.setTitle(polyRoi.getName()); iplus.show(); or just with "iplus.paste()" resulted in the insertion of the content of the bounding Rectangle of my PolygonRoi. when I use manually the GUI with copying the current ROI selection and using "File>> New >> Internal Clipboard" i have only the desired content of the Polygon Roi. How can i get this result with java code? best regards Thomas |
Hi Thomas,
You have to use the mask of the non-rectangular ROI to do a proper fill/draw/paste etc. call getMask() or getMaskPixels() on your ImageProcessor that has a ROI, and then use them as boolean variables to set the pixels of your new image. Otherwise, follow the trail of java code in ImageJ's source code: $~/fiji/ImageJA$ grep -rn "Internal Clipboard" * IJ_Props.txt:28:new03="Internal Clipboard",ij.plugin.Clipboard("show") Now we search for the "show" argument: $~/fiji/ImageJA$ grep -n -A 2 "\"show\"" ij/plugin/Clipboard.java 35: else if (arg.equals("show")) 36- showInternalClipboard(); 37- } Now we search for the showInternalClipboard method: $~/fiji/ImageJA$ grep -n -A 20 "showInternalClipboard() {" ij/plugin/Clipboard.java 148: void showInternalClipboard() { 149- ImagePlus clipboard = ImagePlus.getClipboard(); 150- if (clipboard!=null) { 151- ImageProcessor ip = clipboard.getProcessor(); 152- ImagePlus imp2 = new ImagePlus("Clipboard", ip.duplicate()); 153- Roi roi = clipboard.getRoi(); 154- imp2.killRoi(); 155- if (roi!=null && roi.isArea() && roi.getType()!=Roi.RECTANGLE) { 156- roi = (Roi)roi.clone(); 157- roi.setLocation(0, 0); 158- imp2.setRoi(roi); 159- IJ.run(imp2, "Clear Outside", null); 160- imp2.killRoi(); 161- } 162- WindowManager.checkForDuplicateName = true; 163- imp2.show(); 164- } else 165- IJ.error("The internal clipboard is empty."); 166- } Above is the answer to your question. Hope that helps, Albert > Hi, > > i have several regions of interest as PolygonRoi in an ImagePlus > object that i want to extract to extra ImagePlus objects. > > My attempts with > > ImagePlus plus = new ImagePlus(..) ; > plus.setRoi(polyRoi); // > > plus.copy(true); > > ImagePlus iplus= ImagePlus.getClipboard(); > iplus.setTitle(polyRoi.getName()); > iplus.show(); > > or just with "iplus.paste()" resulted in the insertion of the content > of the bounding Rectangle of my PolygonRoi. > > when I use manually the GUI with copying the current ROI selection and > using "File>> New >> Internal Clipboard" > i have only the desired content of the Polygon Roi. > > How can i get this result with java code? > > best regards > > Thomas -- Albert Cardona http://www.mcdb.ucla.edu/Research/Hartenstein/acardona |
Free forum by Nabble | Edit this page |