Dear List,
I need to retrieve the pixels of several ROIs in the same image and to visualize these ROIs. To do that, inside a loop, I draw several rectangles corresponding to each ROI (using the rectangular selection tool for example) and I use the following lines to store the corresponding ROI and to visualize each of them on the image which is a live stream : roi[i]=img.getRoi(); IJ.run("Add Selection...", ""); My question is how to change (to translate) the ROIs *and* their corresponding overlay ? Thanks for help. Best regards, Philippe -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
On Nov 18, 2013, at 4:15 PM, Philippe GENDRE wrote:
> Dear List, > > I need to retrieve the pixels of several ROIs in the same image and to > visualize these ROIs. > > To do that, inside a loop, I draw several rectangles corresponding to each > ROI (using the rectangular selection tool for example) and I use the > following lines to store the corresponding ROI and to visualize each of > them on the image which is a live stream : > > roi[i]=img.getRoi(); > IJ.run("Add Selection...", ""); > > My question is how to change (to translate) the ROIs *and* their > corresponding overlay ? You can use the Overlay.translate(x,y) method to translate the overlay. An overlay is essentially an array of ROIs so there is no need to maintain a second array. Here is JavaScript code that creates an overlay consisting of three rectangles, translates the overlay and then activates, one at a time, each of the three rectangles. -wayne imp = IJ.createImage("Untitled", "8-bit black", 500, 500, 1); overlay = new Overlay(); overlay.add(new Roi(50, 50, 120, 120)); overlay.add(new Roi(200, 150, 120, 120)); overlay.add(new Roi(300, 300, 140, 120)); imp.setOverlay(overlay); imp.show(); IJ.wait(2000); overlay.translate(50, 50); imp.draw(); IJ.wait(1000); rois = overlay.toArray(); for (i=0; i<rois.length; i++) { imp.setRoi(rois[i]); IJ.wait(1000); } -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Thanks a lot Wayne. Your answer is very useful for me.
Just one question more on this topic : do I have to create as overlay as rois if I want to move each overlay/roi with a specific value ? Best regards, Philippe 2013/11/19 Rasband, Wayne (NIH/NIMH) [E] <[hidden email]> > On Nov 18, 2013, at 4:15 PM, Philippe GENDRE wrote: > > > Dear List, > > > > I need to retrieve the pixels of several ROIs in the same image and to > > visualize these ROIs. > > > > To do that, inside a loop, I draw several rectangles corresponding to > each > > ROI (using the rectangular selection tool for example) and I use the > > following lines to store the corresponding ROI and to visualize each of > > them on the image which is a live stream : > > > > roi[i]=img.getRoi(); > > IJ.run("Add Selection...", ""); > > > > My question is how to change (to translate) the ROIs *and* their > > corresponding overlay ? > > You can use the Overlay.translate(x,y) method to translate the overlay. An > overlay is essentially an array of ROIs so there is no need to maintain a > second array. Here is JavaScript code that creates an overlay consisting of > three rectangles, translates the overlay and then activates, one at a time, > each of the three rectangles. > > -wayne > > imp = IJ.createImage("Untitled", "8-bit black", 500, 500, 1); > overlay = new Overlay(); > overlay.add(new Roi(50, 50, 120, 120)); > overlay.add(new Roi(200, 150, 120, 120)); > overlay.add(new Roi(300, 300, 140, 120)); > imp.setOverlay(overlay); > imp.show(); > IJ.wait(2000); > overlay.translate(50, 50); > imp.draw(); > IJ.wait(1000); > rois = overlay.toArray(); > for (i=0; i<rois.length; i++) { > imp.setRoi(rois[i]); > IJ.wait(1000); > } > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Philippe,
an overlay is a list (a java Vector) of Rois. You can step through all of these rois and manipulate them individually. Roughly like this (I have not tried it, beware of typos and mistakes) Roi[] myRois = myOverlay.toArray(); //convert vector to array for (int i=0; i myRois.length; i++) { Roi roi = myRois [i]; roi.setLocation (newXforThisRoi, newYforThisRoi); } Don't forget imp.updateAndDraw() to show the modified image. If you have an Overlay all the rectangles are shown at the same time. If you want to show the rectangles one after another and keep them editable, don't use an overlay but imp.setRoi for each roi. Is this what you were asking for? Michael ________________________________________________________________ On Nov 19, 2013, at 12:48, Philippe GENDRE wrote: > Thanks a lot Wayne. Your answer is very useful for me. > > Just one question more on this topic : do I have to create as overlay as > rois if I want to move each overlay/roi with a specific value ? > > Best regards, > > Philippe > > > 2013/11/19 Rasband, Wayne (NIH/NIMH) [E] <[hidden email]> > >> On Nov 18, 2013, at 4:15 PM, Philippe GENDRE wrote: >> >>> Dear List, >>> >>> I need to retrieve the pixels of several ROIs in the same image and to >>> visualize these ROIs. >>> >>> To do that, inside a loop, I draw several rectangles corresponding to >> each >>> ROI (using the rectangular selection tool for example) and I use the >>> following lines to store the corresponding ROI and to visualize each of >>> them on the image which is a live stream : >>> >>> roi[i]=img.getRoi(); >>> IJ.run("Add Selection...", ""); >>> >>> My question is how to change (to translate) the ROIs *and* their >>> corresponding overlay ? >> >> You can use the Overlay.translate(x,y) method to translate the overlay. An >> overlay is essentially an array of ROIs so there is no need to maintain a >> second array. Here is JavaScript code that creates an overlay consisting of >> three rectangles, translates the overlay and then activates, one at a time, >> each of the three rectangles. >> >> -wayne >> >> imp = IJ.createImage("Untitled", "8-bit black", 500, 500, 1); >> overlay = new Overlay(); >> overlay.add(new Roi(50, 50, 120, 120)); >> overlay.add(new Roi(200, 150, 120, 120)); >> overlay.add(new Roi(300, 300, 140, 120)); >> imp.setOverlay(overlay); >> imp.show(); >> IJ.wait(2000); >> overlay.translate(50, 50); >> imp.draw(); >> IJ.wait(1000); >> rois = overlay.toArray(); >> for (i=0; i<rois.length; i++) { >> imp.setRoi(rois[i]); >> IJ.wait(1000); >> } >> >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >> > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Michael,
Sorry for the lack of precision of my words. In other words : I want to show all the rectangles (the oulines of my Rois) allways on the image and to be able to move all of them independently (updating the outlines and the Rois). Best regards, Philippe 2013/11/19 Michael Schmid <[hidden email]> > Hi Philippe, > > an overlay is a list (a java Vector) of Rois. You can step through all of > these rois and manipulate them individually. Roughly like this (I have not > tried it, beware of typos and mistakes) > > Roi[] myRois = myOverlay.toArray(); //convert vector to array > for (int i=0; i myRois.length; i++) { > Roi roi = myRois [i]; > roi.setLocation (newXforThisRoi, newYforThisRoi); > } > > Don't forget imp.updateAndDraw() to show the modified image. > > If you have an Overlay all the rectangles are shown at the same time. > If you want to show the rectangles one after another and keep them > editable, don't use an overlay but imp.setRoi for each roi. > > Is this what you were asking for? > > Michael > ________________________________________________________________ > > > On Nov 19, 2013, at 12:48, Philippe GENDRE wrote: > > > Thanks a lot Wayne. Your answer is very useful for me. > > > > Just one question more on this topic : do I have to create as overlay as > > rois if I want to move each overlay/roi with a specific value ? > > > > Best regards, > > > > Philippe > > > > > > 2013/11/19 Rasband, Wayne (NIH/NIMH) [E] <[hidden email]> > > > >> On Nov 18, 2013, at 4:15 PM, Philippe GENDRE wrote: > >> > >>> Dear List, > >>> > >>> I need to retrieve the pixels of several ROIs in the same image and to > >>> visualize these ROIs. > >>> > >>> To do that, inside a loop, I draw several rectangles corresponding to > >> each > >>> ROI (using the rectangular selection tool for example) and I use the > >>> following lines to store the corresponding ROI and to visualize each of > >>> them on the image which is a live stream : > >>> > >>> roi[i]=img.getRoi(); > >>> IJ.run("Add Selection...", ""); > >>> > >>> My question is how to change (to translate) the ROIs *and* their > >>> corresponding overlay ? > >> > >> You can use the Overlay.translate(x,y) method to translate the overlay. > An > >> overlay is essentially an array of ROIs so there is no need to maintain > a > >> second array. Here is JavaScript code that creates an overlay > consisting of > >> three rectangles, translates the overlay and then activates, one at a > time, > >> each of the three rectangles. > >> > >> -wayne > >> > >> imp = IJ.createImage("Untitled", "8-bit black", 500, 500, 1); > >> overlay = new Overlay(); > >> overlay.add(new Roi(50, 50, 120, 120)); > >> overlay.add(new Roi(200, 150, 120, 120)); > >> overlay.add(new Roi(300, 300, 140, 120)); > >> imp.setOverlay(overlay); > >> imp.show(); > >> IJ.wait(2000); > >> overlay.translate(50, 50); > >> imp.draw(); > >> IJ.wait(1000); > >> rois = overlay.toArray(); > >> for (i=0; i<rois.length; i++) { > >> imp.setRoi(rois[i]); > >> IJ.wait(1000); > >> } > >> > >> -- > >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html > >> > > > > -- > > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |