Combine and measure all ROIs in each slice of a stack

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

Combine and measure all ROIs in each slice of a stack

ksexton-2
Hello,I have been looking at this forum for a few days to find solution for
this and haven't been able to get anything to work for me, though I may have
missed a pertinent post somewhere.
/AIM/
I am processing CT images in order to get the body outline, measure the area
within this, get the mean pixel (HU) value within the ROI and get the
dimensions of the bounding rectangle of the ROI for every slice. This has
been successful so far and I am able to get the results I want. However, I
have run into an issue with a recent image.
/ISSUE/
Towards the inferior of the CT image, the legs come in and a ROI is drawn
for each leg on the slice. These are then measured separately which is not
what I want. I would like to count the number of ROIs in a slice, combine
these and get the area, mean pixel value and bounding rectangle dimensions.
/WHAT I HAVE TRIED .../
I have tried to associate the ROIs with each slice in the hopes that I could
then combine all the ROIs corresponding to a single slice and then move to
the next slice and so on. However, when I count the ROIs in a loop over the
slices, I get just the total number of ROIs for the whole image stack. I can
combine slices manually using ROIManager of course, but I would like my
macro to identify when there is >1 ROI per slice, combine the ROIs and
measure.
Any help would be appreciated.



--
Sent from: http://imagej.1557.x6.nabble.com/

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

Re: Combine and measure all ROIs in each slice of a stack

Michael Schmid
Hi,

assuming that your ROIs in the ROI Manager are not renamed, the first
four letters of the ROI names should give you the slice number.

So you could write a macro; roughly like the following:
Create an empty array.
Loop through the ROIs (up to the current number of ROIs in the ROI
Manager, say nRois).
For each index in the list of ROIs:
   select the ROI, retrieve the name with Roi.getName() and get the
slice number from the name (see the substring and parseInt commands).
   If you have a new slice, combine the rois from the array
     roiManager("select", theArray);
     roiManager("combine");
     Then add them to the ROI Manager and empty the array.
   In any case, add the current loop index to the array.

After the loop, also combine the rois from the array and add them.

Finally, delete the first nRois from the ROI Manager.

If you don't need it the rois, just measure, you can measure after
roiManager("combine") and omit adding to the ROI Manager (also, no need
to delete anything).


To extend arrays, you need setOption("ExpandableArrays", true); at the
beginning of the macro. Otherwise, you would have to declare a large
array (e.g. of size nRois) and have a variable for how many array
positions are actually used.

Michael
________________________________________________________________
On 24/05/2018 11:34, ksexton wrote:

> Hello,I have been looking at this forum for a few days to find solution for
> this and haven't been able to get anything to work for me, though I may have
> missed a pertinent post somewhere.
> /AIM/
> I am processing CT images in order to get the body outline, measure the area
> within this, get the mean pixel (HU) value within the ROI and get the
> dimensions of the bounding rectangle of the ROI for every slice. This has
> been successful so far and I am able to get the results I want. However, I
> have run into an issue with a recent image.
> /ISSUE/
> Towards the inferior of the CT image, the legs come in and a ROI is drawn
> for each leg on the slice. These are then measured separately which is not
> what I want. I would like to count the number of ROIs in a slice, combine
> these and get the area, mean pixel value and bounding rectangle dimensions.
> /WHAT I HAVE TRIED .../
> I have tried to associate the ROIs with each slice in the hopes that I could
> then combine all the ROIs corresponding to a single slice and then move to
> the next slice and so on. However, when I count the ROIs in a loop over the
> slices, I get just the total number of ROIs for the whole image stack. I can
> combine slices manually using ROIManager of course, but I would like my
> macro to identify when there is >1 ROI per slice, combine the ROIs and
> measure.
> Any help would be appreciated.
>
>
>
> --
> Sent from: http://imagej.1557.x6.nabble.com/
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

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