Basic ROI questions...

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

Basic ROI questions...

Weller Andrew Francis
Dear all,

I apologise for the basic questions, but something I've yet to get
accustomed to is ROI management in ImageJ.

In essence, I have an image with a particle of interest in. I segment
the foreground/background using the 'Mixture Modeling' plugin
(http://rsb.info.nih.gov/ij/plugins/mixture-modeling.html).

How do I eliminate smaller ROIs? (Or select the largest one, presuming
it's the particle I am after?)
How do I delete the background from my original image?
How do I select my particle with a bounding box and save as a new
(smaller) image?
Can I save the ROI as well for future reference?

I would then like to do some morphological analysis on the ROI.

I hope someone can point me in the right direction?

Many thanks, Andy
Reply | Threaded
Open this post in threaded view
|

Re: Basic ROI questions...

Wayne Rasband
> I apologise for the basic questions, but something I've yet to get
> accustomed to is ROI management in ImageJ.
>
> In essence, I have an image with a particle of interest in. I segment
> the foreground/background using the 'Mixture Modeling' plugin
> (http://rsb.info.nih.gov/ij/plugins/mixture-modeling.html).
>
> How do I eliminate smaller ROIs? (Or select the largest one,
> presuming it's the particle I am after?)

The particle analyzer will eliminate smaller objects if you set a
minimum size in the dialog and choose "Masks" from the drop down menu.
You would need a macro something like this to find the largest object:

     max = 0;
     for (i=0; i<nResults; i++) {
         area = getResult("Area", i);
         if (area>max) {
             max = area;
             index = i;
         }
    }
    doWand(getResult("XStart",index), getResult("YStart",index));

This macro assumes that that "Record Starts" was checked in the
particle analyze dialog and areas are in pixels.

> How do I delete the background from my original image?

AND the original image with the "Masks" image generated by the particle
analyzer.

> How do I select my particle with a bounding box and save as a new
> (smaller) image?

Create a rectangular ROI and then use the Image>Duplicate command.

> Can I save the ROI as well for future reference?

Use File>Save As>Selection to save the ROI.

> I would then like to do some morphological analysis on the ROI.
>
> I hope someone can point me in the right direction?
>
> Many thanks, Andy
>
Reply | Threaded
Open this post in threaded view
|

Re: ROI questions...

Weller Andrew Francis
Dear all,

I have a basic macro that reads images in a batch and segments them; I
want to add analysis later.

I'm currently a little lost as to how to work with both the ROI
(morphology, texture) and how to delete the background from my original
image.

I currently have a function threshold() that returns the doWand of my
thresholded image. As Wayne says I need to AND the original image with
the "Masks" image generated by the particle analyzer to delete the
background. For this I have:

image = open(fileName); // sets original image
mask = threshold(); // returns thresholded image
threshImg = image & mask; // deletes background
open(threshImg); // open image

This is not working though, perhaps there is an obvious reason, but it
ain't so obvious to me at present!?

I am slowly getting more 'in' to ImageJ and the more I play, the more I
like, but some 'simple' things aren't so simple to me.

Cheers, Andy

On Mon, 2006-06-12 at 15:59 -0400, Wayne Rasband wrote:

> > I apologise for the basic questions, but something I've yet to get
> > accustomed to is ROI management in ImageJ.
> >
> > In essence, I have an image with a particle of interest in. I segment
> > the foreground/background using the 'Mixture Modeling' plugin
> > (http://rsb.info.nih.gov/ij/plugins/mixture-modeling.html).
> >
> > How do I eliminate smaller ROIs? (Or select the largest one,
> > presuming it's the particle I am after?)
>
> The particle analyzer will eliminate smaller objects if you set a
> minimum size in the dialog and choose "Masks" from the drop down menu.
> You would need a macro something like this to find the largest object:
>
>      max = 0;
>      for (i=0; i<nResults; i++) {
>          area = getResult("Area", i);
>          if (area>max) {
>              max = area;
>              index = i;
>          }
>     }
>     doWand(getResult("XStart",index), getResult("YStart",index));
>
> This macro assumes that that "Record Starts" was checked in the
> particle analyze dialog and areas are in pixels.
>
> > How do I delete the background from my original image?
>
> AND the original image with the "Masks" image generated by the particle
> analyzer.
>
> > How do I select my particle with a bounding box and save as a new
> > (smaller) image?
>
> Create a rectangular ROI and then use the Image>Duplicate command.
>
> > Can I save the ROI as well for future reference?
>
> Use File>Save As>Selection to save the ROI.
>
> > I would then like to do some morphological analysis on the ROI.
> >
> > I hope someone can point me in the right direction?
> >
> > Many thanks, Andy
> >
Reply | Threaded
Open this post in threaded view
|

Re: ROI questions...

Weller Andrew Francis
In essence, at each 'processing' point in my macro I want to store (not
necessarily save) the result (ROI, image, etc) which can be called when
ANDing, etc later in my macro. So for example, if I:

doWand(getResult("XStart",index), getResult("YStart",index));

I want to store that ROI as a variable which can be called later in my
macro for subsequent processing/saving. I've searched the archives for
an answer to no avail...

Any clues?

Many thanks, Andy

On Fri, 2006-06-23 at 13:45 +0200, Andy Weller wrote:

> Dear all,
>
> I have a basic macro that reads images in a batch and segments them; I
> want to add analysis later.
>
> I'm currently a little lost as to how to work with both the ROI
> (morphology, texture) and how to delete the background from my original
> image.
>
> I currently have a function threshold() that returns the doWand of my
> thresholded image. As Wayne says I need to AND the original image with
> the "Masks" image generated by the particle analyzer to delete the
> background. For this I have:
>
> image = open(fileName); // sets original image
> mask = threshold(); // returns thresholded image
> threshImg = image & mask; // deletes background
> open(threshImg); // open image
>
> This is not working though, perhaps there is an obvious reason, but it
> ain't so obvious to me at present!?
>
> I am slowly getting more 'in' to ImageJ and the more I play, the more I
> like, but some 'simple' things aren't so simple to me.
>
> Cheers, Andy
>
> On Mon, 2006-06-12 at 15:59 -0400, Wayne Rasband wrote:
> > > I apologise for the basic questions, but something I've yet to get
> > > accustomed to is ROI management in ImageJ.
> > >
> > > In essence, I have an image with a particle of interest in. I segment
> > > the foreground/background using the 'Mixture Modeling' plugin
> > > (http://rsb.info.nih.gov/ij/plugins/mixture-modeling.html).
> > >
> > > How do I eliminate smaller ROIs? (Or select the largest one,
> > > presuming it's the particle I am after?)
> >
> > The particle analyzer will eliminate smaller objects if you set a
> > minimum size in the dialog and choose "Masks" from the drop down menu.
> > You would need a macro something like this to find the largest object:
> >
> >      max = 0;
> >      for (i=0; i<nResults; i++) {
> >          area = getResult("Area", i);
> >          if (area>max) {
> >              max = area;
> >              index = i;
> >          }
> >     }
> >     doWand(getResult("XStart",index), getResult("YStart",index));
> >
> > This macro assumes that that "Record Starts" was checked in the
> > particle analyze dialog and areas are in pixels.
> >
> > > How do I delete the background from my original image?
> >
> > AND the original image with the "Masks" image generated by the particle
> > analyzer.
> >
> > > How do I select my particle with a bounding box and save as a new
> > > (smaller) image?
> >
> > Create a rectangular ROI and then use the Image>Duplicate command.
> >
> > > Can I save the ROI as well for future reference?
> >
> > Use File>Save As>Selection to save the ROI.
> >
> > > I would then like to do some morphological analysis on the ROI.
> > >
> > > I hope someone can point me in the right direction?
> > >
> > > Many thanks, Andy
Reply | Threaded
Open this post in threaded view
|

Re: ROI questions...

Wayne Rasband
> In essence, at each 'processing' point in my macro I want to store
> (not necessarily save) the result (ROI, image, etc) which can be
> called when ANDing, etc later in my macro. So for example, if I:
>
> doWand(getResult("XStart",index), getResult("YStart",index));
>
> I want to store that ROI as a variable which can be called later
> in my macro for subsequent processing/saving. I've searched
> the archives for an answer to no avail...

Save the ROIs in the ROI Manager. Here are some example macros that do
this:

       http://rsb.info.nih.gov/ij/macros/RoiManagerMacros.txt
       http://rsb.info.nih.gov/ij/macros/ROI_Manager_Stack_Demo.txt
       http://rsb.info.nih.gov/ij/macros/RoiManagerAddParticles.txt

The ROI Manager macro functions are described at:

     
http://rsb.info.nih.gov/ij/developer/macro/functions.html#roiManager

-wayne
Reply | Threaded
Open this post in threaded view
|

Re: ROI questions...

Wayne Rasband
In reply to this post by Weller Andrew Francis
Here is an example macro that does an AND-mode paste of the "Masks"
output of the particle analyzer to erase the background of the original
image.

     run("Blobs (25K)");
     id = getImageID();
     setAutoThreshold();
     run("Analyze Particles...", "size=400 circularity=0.00 show=Masks
exclude");
     run("Copy");
     selectImage(id);
     setPasteMode("AND");
     run("Paste");
     resetThreshold();

-wayne


On Jun 23, 2006, at 7:45 AM, Andy Weller wrote:

> Dear all,
>
> I have a basic macro that reads images in a batch and segments them; I
> want to add analysis later.
>
> I'm currently a little lost as to how to work with both the ROI
> (morphology, texture) and how to delete the background from my original
> image.
>
> I currently have a function threshold() that returns the doWand of my
> thresholded image. As Wayne says I need to AND the original image with
> the "Masks" image generated by the particle analyzer to delete the
> background. For this I have:
>
> image = open(fileName); // sets original image
> mask = threshold(); // returns thresholded image
> threshImg = image & mask; // deletes background
> open(threshImg); // open image
>
> This is not working though, perhaps there is an obvious reason, but it
> ain't so obvious to me at present!?
>
> I am slowly getting more 'in' to ImageJ and the more I play, the more I
> like, but some 'simple' things aren't so simple to me.
>
> Cheers, Andy
>
> On Mon, 2006-06-12 at 15:59 -0400, Wayne Rasband wrote:
>>> I apologise for the basic questions, but something I've yet to get
>>> accustomed to is ROI management in ImageJ.
>>>
>>> In essence, I have an image with a particle of interest in. I segment
>>> the foreground/background using the 'Mixture Modeling' plugin
>>> (http://rsb.info.nih.gov/ij/plugins/mixture-modeling.html).
>>>
>>> How do I eliminate smaller ROIs? (Or select the largest one,
>>> presuming it's the particle I am after?)
>>
>> The particle analyzer will eliminate smaller objects if you set a
>> minimum size in the dialog and choose "Masks" from the drop down menu.
>> You would need a macro something like this to find the largest object:
>>
>>      max = 0;
>>      for (i=0; i<nResults; i++) {
>>          area = getResult("Area", i);
>>          if (area>max) {
>>              max = area;
>>              index = i;
>>          }
>>     }
>>     doWand(getResult("XStart",index), getResult("YStart",index));
>>
>> This macro assumes that that "Record Starts" was checked in the
>> particle analyze dialog and areas are in pixels.
>>
>>> How do I delete the background from my original image?
>>
>> AND the original image with the "Masks" image generated by the
>> particle
>> analyzer.
>>
>>> How do I select my particle with a bounding box and save as a new
>>> (smaller) image?
>>
>> Create a rectangular ROI and then use the Image>Duplicate command.
>>
>>> Can I save the ROI as well for future reference?
>>
>> Use File>Save As>Selection to save the ROI.
>>
>>> I would then like to do some morphological analysis on the ROI.
>>>
>>> I hope someone can point me in the right direction?
>>>
>>> Many thanks, Andy
>>>
>
Reply | Threaded
Open this post in threaded view
|

Re: ROI questions...

Weller Andrew Francis
In reply to this post by Wayne Rasband
Sorry, I can't get my head round this... Basically, my macro has:

run("Crop"); // A cropped image
threshold(); // This is threshold with my function

What I would like to do is this:

Fit a bounding box to crop this newly threshold image:

getSelectionBounds(x, y, width, height);
makeRectangle(x, y, width, height);
run("Crop");
roiManager("Add"); // The ROI found from the threshold is added to the
manager

AND the new run("Crop") image with the roiManager("Add") ROI to delete
the background. I guess using:

imageCalculator("AND create", CropImage, ROI);

I would like to save both the newly cropped-to-ROI and deleted
background image AND the ROI. This will allow me to open these 2 in the
future to do some analyses on them - morphological, textural, etc.

I hope this makes sense and that someone can help me out?!

Thanks, Andy

On Fri, 2006-06-23 at 10:16 -0400, Wayne Rasband wrote:

> > In essence, at each 'processing' point in my macro I want to store
> > (not necessarily save) the result (ROI, image, etc) which can be
> > called when ANDing, etc later in my macro. So for example, if I:
> >
> > doWand(getResult("XStart",index), getResult("YStart",index));
> >
> > I want to store that ROI as a variable which can be called later
> > in my macro for subsequent processing/saving. I've searched
> > the archives for an answer to no avail...
>
> Save the ROIs in the ROI Manager. Here are some example macros that do
> this:
>
>        http://rsb.info.nih.gov/ij/macros/RoiManagerMacros.txt
>        http://rsb.info.nih.gov/ij/macros/ROI_Manager_Stack_Demo.txt
>        http://rsb.info.nih.gov/ij/macros/RoiManagerAddParticles.txt
>
> The ROI Manager macro functions are described at:
>
>      
> http://rsb.info.nih.gov/ij/developer/macro/functions.html#roiManager
>
> -wayne
Reply | Threaded
Open this post in threaded view
|

Re: ROI questions...

Martin du Saire
If I understand your problem, you want to be able to select ROIs and
process them individually and still have access the the final image
or intermediate images?  If so one option would be to explicitly save
the image.  If you don't close it, you can access it using
selectWindow() or selectImage(), otherwise, re-open the image with open():


open("C:\\Image_directory\\image1.tif");
makeRectangle(x, y, width, height);
run("Duplicate...", "title=roi_1");
saveAs("Tiff", "C:\\Image_directory\\roi_1.tif");
run("Duplicate...", "title=roi_1_background.tif");
saveAs("Tiff", "C:\\Image_directory\\roi_1_background.tif");
selectWindow("roi_1.tif");

<< Do whatever you want to with this copy of the ROI  >>

saveAs("Tiff", "C:\\Image_directory\\processed_roi_1.tif");

selectWindow("roi_1_background.tif");

<<  Do whatever with this second copy of the ROI  >>

saveAs("Tiff", "C:\\Image_directory\\processed_roi_1_background.tif");

If you don't want to go through the hassle of reading and writing
images to disk, just duplicate and rename the images you want to
"keep" for later use.

Of course, I may have completely misunderstood what you are trying to
do...Hope this helps.

M

At 12:00 PM 6/23/2006, you wrote:

>Sorry, I can't get my head round this... Basically, my macro has:
>
>run("Crop"); // A cropped image
>threshold(); // This is threshold with my function
>
>What I would like to do is this:
>
>Fit a bounding box to crop this newly threshold image:
>
>getSelectionBounds(x, y, width, height);
>makeRectangle(x, y, width, height);
>run("Crop");
>roiManager("Add"); // The ROI found from the threshold is added to the
>manager
>
>AND the new run("Crop") image with the roiManager("Add") ROI to delete
>the background. I guess using:
>
>imageCalculator("AND create", CropImage, ROI);
>
>I would like to save both the newly cropped-to-ROI and deleted
>background image AND the ROI. This will allow me to open these 2 in the
>future to do some analyses on them - morphological, textural, etc.
>
>I hope this makes sense and that someone can help me out?!
>
>Thanks, Andy
>
>On Fri, 2006-06-23 at 10:16 -0400, Wayne Rasband wrote:
> > > In essence, at each 'processing' point in my macro I want to store
> > > (not necessarily save) the result (ROI, image, etc) which can be
> > > called when ANDing, etc later in my macro. So for example, if I:
> > >
> > > doWand(getResult("XStart",index), getResult("YStart",index));
> > >
> > > I want to store that ROI as a variable which can be called later
> > > in my macro for subsequent processing/saving. I've searched
> > > the archives for an answer to no avail...
> >
> > Save the ROIs in the ROI Manager. Here are some example macros that do
> > this:
> >
> >        http://rsb.info.nih.gov/ij/macros/RoiManagerMacros.txt
> >        http://rsb.info.nih.gov/ij/macros/ROI_Manager_Stack_Demo.txt
> >        http://rsb.info.nih.gov/ij/macros/RoiManagerAddParticles.txt
> >
> > The ROI Manager macro functions are described at:
> >
> >
> > http://rsb.info.nih.gov/ij/developer/macro/functions.html#roiManager
> >
> > -wayne
Reply | Threaded
Open this post in threaded view
|

Re: ROI questions...

Weller Andrew Francis
In reply to this post by Wayne Rasband
Thanks all for your help! Yes I had been using the macro recorder, but
it didn't really reproduce what I wanted. Currently I have:

        threshold(); // my function
        roiManager("Add");
        //run("Create Mask"); // Maybe?!?
        roiManager("select", 0); // select the first ROI
        selectImage(id);
        setPasteMode("AND");
        run("Paste");
        id1 = getImageID();
        save(dir2+"NEW_"+fileName+".tif");
        roiManager("deselect"); // clear the ROImanager ready for loop N

but this is now giving me a more-or-less blotchy background with my red
particle on it!? What I really need is:

a) my roi stored for future reference (I think this is easy to do/save)
b) a new image stored with a black or white background AND my particle
right there, not a red blob...

Maybe this is a silly error that's easy to rectify.

Cheers, Andy

On Fri, 2006-06-23 at 12:45 -0400, Wayne Rasband wrote:

> Here is an example macro that does an AND-mode paste of the "Masks"
> output of the particle analyzer to erase the background of the original
> image.
>
>      run("Blobs (25K)");
>      id = getImageID();
>      setAutoThreshold();
>      run("Analyze Particles...", "size=400 circularity=0.00 show=Masks
> exclude");
>      run("Copy");
>      selectImage(id);
>      setPasteMode("AND");
>      run("Paste");
>      resetThreshold();
>
> -wayne
>
>
> On Jun 23, 2006, at 7:45 AM, Andy Weller wrote:
>
> > Dear all,
> >
> > I have a basic macro that reads images in a batch and segments them; I
> > want to add analysis later.
> >
> > I'm currently a little lost as to how to work with both the ROI
> > (morphology, texture) and how to delete the background from my original
> > image.
> >
> > I currently have a function threshold() that returns the doWand of my
> > thresholded image. As Wayne says I need to AND the original image with
> > the "Masks" image generated by the particle analyzer to delete the
> > background. For this I have:
> >
> > image = open(fileName); // sets original image
> > mask = threshold(); // returns thresholded image
> > threshImg = image & mask; // deletes background
> > open(threshImg); // open image
> >
> > This is not working though, perhaps there is an obvious reason, but it
> > ain't so obvious to me at present!?
> >
> > I am slowly getting more 'in' to ImageJ and the more I play, the more I
> > like, but some 'simple' things aren't so simple to me.
> >
> > Cheers, Andy
> >
> > On Mon, 2006-06-12 at 15:59 -0400, Wayne Rasband wrote:
> >>> I apologise for the basic questions, but something I've yet to get
> >>> accustomed to is ROI management in ImageJ.
> >>>
> >>> In essence, I have an image with a particle of interest in. I segment
> >>> the foreground/background using the 'Mixture Modeling' plugin
> >>> (http://rsb.info.nih.gov/ij/plugins/mixture-modeling.html).
> >>>
> >>> How do I eliminate smaller ROIs? (Or select the largest one,
> >>> presuming it's the particle I am after?)
> >>
> >> The particle analyzer will eliminate smaller objects if you set a
> >> minimum size in the dialog and choose "Masks" from the drop down menu.
> >> You would need a macro something like this to find the largest object:
> >>
> >>      max = 0;
> >>      for (i=0; i<nResults; i++) {
> >>          area = getResult("Area", i);
> >>          if (area>max) {
> >>              max = area;
> >>              index = i;
> >>          }
> >>     }
> >>     doWand(getResult("XStart",index), getResult("YStart",index));
> >>
> >> This macro assumes that that "Record Starts" was checked in the
> >> particle analyze dialog and areas are in pixels.
> >>
> >>> How do I delete the background from my original image?
> >>
> >> AND the original image with the "Masks" image generated by the
> >> particle
> >> analyzer.
> >>
> >>> How do I select my particle with a bounding box and save as a new
> >>> (smaller) image?
> >>
> >> Create a rectangular ROI and then use the Image>Duplicate command.
> >>
> >>> Can I save the ROI as well for future reference?
> >>
> >> Use File>Save As>Selection to save the ROI.
> >>
> >>> I would then like to do some morphological analysis on the ROI.
> >>>
> >>> I hope someone can point me in the right direction?
> >>>
> >>> Many thanks, Andy
Reply | Threaded
Open this post in threaded view
|

setAutoThreshold()

Weller Andrew Francis
Wayne kindly supplied me the following macro (see below) for
segmentation. I would like to change setAutoThreshold() to the manual
setThreshold(). This is because I miss a little material and want to
lower the lower bounds.

I have therefore changed the setAutoThreshold() part to the following:

   getThreshold(lo, up);
   lo = lo-30;
      if (lo<0) {
         lo = 0;
         }
   setThreshold(lo, up, "over/under");
   run("Threshold", "thresholded remaining");

but this is not giving me what I expected. When I save the images, all I
get now is just black.

Any ideas how to correct this so I can manually enter a threshold value?

Thanks, Andy

On Tue, 2006-06-27 at 09:45 -0400, Wayne Rasband wrote:

> Here is a macro that erases the background to black and creates a
> selection corresponding to the foraminifera. It uses the new
> Edit>Selection>Create Selection command, which was added in ImageJ
> 1.37j (attached). This command converts a mask to a selection.
>
>    setBatchMode(true);
>    img = getImageID;
>    setAutoThreshold();
>    run("Analyze Particles...", "size=0.50-Infinity circularity=0.00-1.00
> show=Masks clear");
>    mask = getImageID;
>    run("Copy");
>    setPasteMode("AND");
>    selectImage(img);
>    run("Paste");
>    resetThreshold();
>    selectImage(mask);
>    run("Create Selection"); // requires 1.37j
>    selectImage(img);
>    run("Restore Selection");
>
> -wayne
Reply | Threaded
Open this post in threaded view
|

Re: setAutoThreshold()

Weller Andrew Francis
OK, before getThreshold(lo, up) I ran setAutoThreshold() to get the
initial values. But this is still returning just the thresholded image!

Any pointers how to return my segmented image?

Thanks, Andy

On Wed, 2006-06-28 at 14:23 +0200, Andy Weller wrote:

> Wayne kindly supplied me the following macro (see below) for
> segmentation. I would like to change setAutoThreshold() to the manual
> setThreshold(). This is because I miss a little material and want to
> lower the lower bounds.
>
> I have therefore changed the setAutoThreshold() part to the following:
>
>    getThreshold(lo, up);
>    lo = lo-30;
>       if (lo<0) {
>          lo = 0;
>          }
>    setThreshold(lo, up, "over/under");
>    run("Threshold", "thresholded remaining");
>
> but this is not giving me what I expected. When I save the images, all I
> get now is just black.
>
> Any ideas how to correct this so I can manually enter a threshold value?
>
> Thanks, Andy
>
> On Tue, 2006-06-27 at 09:45 -0400, Wayne Rasband wrote:
> > Here is a macro that erases the background to black and creates a
> > selection corresponding to the foraminifera. It uses the new
> > Edit>Selection>Create Selection command, which was added in ImageJ
> > 1.37j (attached). This command converts a mask to a selection.
> >
> >    setBatchMode(true);
> >    img = getImageID;
> >    setAutoThreshold();
> >    run("Analyze Particles...", "size=0.50-Infinity circularity=0.00-1.00
> > show=Masks clear");
> >    mask = getImageID;
> >    run("Copy");
> >    setPasteMode("AND");
> >    selectImage(img);
> >    run("Paste");
> >    resetThreshold();
> >    selectImage(mask);
> >    run("Create Selection"); // requires 1.37j
> >    selectImage(img);
> >    run("Restore Selection");
> >
> > -wayne