Login  Register

how to define a ROI with selection and thresholding

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

how to define a ROI with selection and thresholding

pang
Dear ImageJ colleagues,

I would like to use makeRectangle to identify a specific area I would like to work on, and then set a threshold using the OTSU method.  Next I want to make a selection with thresholded pixels within  the Rectangle.

makeRectangle(512, 512, 512, 512);
setAutoThreshold("Otsu dark");
run("Create Selection");
roiManager("Add");

I found that ImageJ created selection on the whole image with the thresholded value determined by the Rectangele. I really want to create selection only within the rectangle. How could I do that?


Thanks!

Zhengyu

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

Re: how to define a ROI with selection and thresholding

Gabriel Landini
On Thursday 21 Mar 2013 15:23:19 you wrote:

> I would like to use makeRectangle to identify a specific area I would like
> to work on, and then set a threshold using the OTSU method.  Next I want to
> make a selection with thresholded pixels within  the Rectangle.
>
> makeRectangle(512, 512, 512, 512);
> setAutoThreshold("Otsu dark");
> run("Create Selection");
> roiManager("Add");
>
> I found that ImageJ created selection on the whole image with the
> thresholded value determined by the Rectangele. I really want to create
> selection only within the rectangle. How could I do that?

A macro: duplicate the selection, threshold it, paste it back on the original:

run("Bridge (174K)");
makeRectangle(123, 118, 193, 176);
run("Duplicate...", "title=bridge-1.gif");
setAutoThreshold("Otsu");
setOption("BlackBackground", true);
run("Convert to Mask");
run("Copy");
selectWindow("bridge.gif");
run("Paste");

Cheers
Gabriel

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

Re: how to define a ROI with selection and thresholding

jchanson
In reply to this post by pang
Zhengyu -
        If you save both your region the selection from Otsu thresholding to the ROI manager, you can use it's "AND" function to select only objects inside the original ROI.  Here's a script that use the ROI manager to do the AND and then cleans up the temporary ROIs when it's done.

Jeff Hanson
Senior Imaging Analyst
//<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>//
makeRectangle(100, 100, 128, 128);
nROIs = roiManager("count");
roiManager("Add");
//run("Threshold...");
setAutoThreshold("Otsu dark");
run("Create Selection");
roiManager("Add");

// AND the ROIs
roiList = newArray(2);
roiList[0] = nROIs; roiList[1] = nROIs+1;
roiManager("select",roiList);
roiManager("AND");

// Delete the temporary ROIs
roiManager("select",roiList);
roiManager("delete");
//<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>//

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Pang, Zhengyu (GE Global Research)
Sent: Thursday, March 21, 2013 11:23 AM
To: [hidden email]
Subject: how to define a ROI with selection and thresholding

Dear ImageJ colleagues,

I would like to use makeRectangle to identify a specific area I would like to work on, and then set a threshold using the OTSU method.  Next I want to make a selection with thresholded pixels within  the Rectangle.

makeRectangle(512, 512, 512, 512);
setAutoThreshold("Otsu dark");
run("Create Selection");
roiManager("Add");

I found that ImageJ created selection on the whole image with the thresholded value determined by the Rectangele. I really want to create selection only within the rectangle. How could I do that?


Thanks!

Zhengyu

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

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