Combined surface area of all ROI in an image

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

Combined surface area of all ROI in an image

mmettlen
Easy - yet so difficult: How can I measure the combined total surface area of all ROI in an image? In the attached example : surface area of ROIs 125+126+127+128 = ?
I'm wondering if this can be done automatically? My timeseries has 250 images and the number of ROIs is variable from frame to frame => I'd like to get one number/slice.
Reply | Threaded
Open this post in threaded view
|

Re: Combined surface area of all ROI in an image

Burger Wilhelm
In a Java plugin, you could use Roi's point iterator to count the included pixels, as described here:
https://imagej.nih.gov/ij/developer/api/ij/gui/Roi.html
This should work for composite ROIs too.

--Wilhelm


-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of mmettlen
Sent: Montag, 15. Mai 2017 15:38
To: [hidden email]
Subject: Combined surface area of all ROI in an image

Easy - yet so difficult: How can I measure the combined total surface area of all ROI in an image? In the attached example : surface area of ROIs
125+126+127+128 = ?
I'm wondering if this can be done automatically? My timeseries has 250 images and the number of ROIs is variable from frame to frame => I'd like to get one number/slice.
<http://imagej.1557.x6.nabble.com/file/n5018716/example.jpg>



--
View this message in context: http://imagej.1557.x6.nabble.com/Combined-surface-area-of-all-ROI-in-an-image-tp5018716.html
Sent from the ImageJ mailing list archive at Nabble.com.

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

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

Re: Combined surface area of all ROI in an image

Krs5
If you have all the ROIs in the ROI manager you could use something like below in the macro language. This assumes an 8-bit image.

----------------------------------code snippet-------------------------------------------
run("Colors...", "foreground=white background=black selection=red");
run("Set Measurements...", "area display redirect=None decimal=3");
roiManager("Deselect");
roiManager("Fill");
setAutoThreshold("Default dark");
setThreshold(255, 255);
getDimensions(width, height, channels, slices, frames);
for(i=1;i<=frames;i++){
        setSlice(i);
        run("Analyze Particles...", "size=25-Infinity pixel summarize");
}
------------------------------------------------------------------------------------


The results should be a summary table with the total area + area fraction for each frame.

Hope it works

Kees

Dr Ir K.R. Straatman
Senior Experimental Officer
Advanced Imaging Facility
Centre for Core Biotechnology Services
University of Leicester
http://www2.le.ac.uk/colleges/medbiopsych/facilities-and-services/cbs/lite/aif

ImageJ workshops 1 and 2 June: http://www2.le.ac.uk/colleges/medbiopsych/facilities-and-services/cbs/AIF/workshops/imagej-workshops-June-2017

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Burger Wilhelm
Sent: 16 May 2017 08:49
To: [hidden email]
Subject: Re: Combined surface area of all ROI in an image

In a Java plugin, you could use Roi's point iterator to count the included pixels, as described here:
https://imagej.nih.gov/ij/developer/api/ij/gui/Roi.html
This should work for composite ROIs too.

--Wilhelm


-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of mmettlen
Sent: Montag, 15. Mai 2017 15:38
To: [hidden email]
Subject: Combined surface area of all ROI in an image

Easy - yet so difficult: How can I measure the combined total surface area of all ROI in an image? In the attached example : surface area of ROIs
125+126+127+128 = ?
I'm wondering if this can be done automatically? My timeseries has 250 images and the number of ROIs is variable from frame to frame => I'd like to get one number/slice.
<http://imagej.1557.x6.nabble.com/file/n5018716/example.jpg>



--
View this message in context: http://imagej.1557.x6.nabble.com/Combined-surface-area-of-all-ROI-in-an-image-tp5018716.html
Sent from the ImageJ mailing list archive at Nabble.com.

--
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
Reply | Threaded
Open this post in threaded view
|

Re: Combined surface area of all ROI in an image

mmettlen
In reply to this post by mmettlen
Thanks for your replies! I've worked on it too and wrote a little macro that does what Kees suggested. In a nutshell, the macro takes a stack of images and the corresponding ROI manager that contains all the ROIs. It than makes a new 8-bit black stack with the same dimension as the original stack, copies the ROIs into it, flattens them, and uses them to quantify the total area of all ROIs/slice:

if (isOpen("Results")) {selectWindow("Results"); run ("Close");}
dir = getDirectory("image"); //the original stack has to be open with its corresponding ROI manager
title = getTitle();
getDimensions(width, height, channels, slices, frames);
FolderName = split(title,".");
DirName = FolderName[0];
File.makeDirectory(dir+File.separator+DirName);
while (nImages>0) {
          selectImage(nImages);
        close();}
run("Set Measurements...", "area limit display redirect=None decimal=2");
newImage("Untitled", "8-bit black", width, height, frames);
roiManager("Set Fill Color", "white"); //copies all ROIs into a given slice - pulled from ROI manager
roiManager("Show All"); //copies all ROIs into a given slice - pulled from ROI manager
for (i=1; i<=nSlices; i++)
{run("Set Slice...", "slice="+i);
setBatchMode(true);
run("Flatten", "slice"); //'burn's white ROIs into black image
run("8-bit");
saveAs("tif", dir+DirName+File.separator+"Mask_"+i+".tif"); close();}; //the saved images will be used below to automatically generate a stack
while (nImages>0) {
          selectImage(nImages);
        close();}
setBatchMode(false);
run("Image Sequence...", "open="+dir+DirName+File.separator+"Mask_1.tif sort");
setThreshold(100, 255); //stack is thresholded and used to measure surface area of all ROIs
for (i=1; i<=nSlices; i++)
{run("Set Slice...", "slice="+i);
run("Measure");}
selectWindow("Results");
saveAs("txt", dir+File.separator+"Results_"+DirName+".txt");
run("Close");
while (nImages>0) {
          selectImage(nImages);
        close();}
if (isOpen("Log")) {selectWindow("Log"); run ("Close");}
Reply | Threaded
Open this post in threaded view
|

Re: Combined surface area of all ROI in an image

Burger Wilhelm
Just to elaborate on the idea to use the Roi iterator, below is a small ImageJ plugin that calculates the cumulative roi area in a stack. No masks, no files required. Perhaps you want to give it a try...

--Wilhelm

// -----------------------------------------------------------------------------
import java.awt.Point;

import ij.IJ;
import ij.ImagePlus;
import ij.gui.Overlay;
import ij.gui.Roi;
import ij.plugin.filter.PlugInFilter;
import ij.process.ImageProcessor;

public class Stack_Roi_Sum_Area implements PlugInFilter {
        ImagePlus im = null;

        public int setup(String arg, ImagePlus im) {
                this.im = im;
                return DOES_ALL + STACK_REQUIRED + NO_CHANGES;
        }

        public void run(ImageProcessor ip) {
                int area = 0;
                Overlay oly = im.getOverlay();
                if (oly != null) {
                        for (int i = 0; i < oly.size(); i++) {
                                Roi roi = oly.get(i);
                                if (roi != null) {
                                        for(Point p : roi) {
                                                area++;
                                        }
                                }
                        }
                }
                IJ.log("Cumulative roi area = " + area);
        }
}
// -----------------------------------------------------------------------------

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of mmettlen
Sent: Dienstag, 16. Mai 2017 15:49
To: [hidden email]
Subject: Re: Combined surface area of all ROI in an image

Thanks for your replies! I've worked on it too and wrote a little macro that does what Kees suggested. In a nutshell, the macro takes a stack of images and the corresponding ROI manager that contains all the ROIs. It than makes a new 8-bit black stack with the same dimension as the original stack, copies the ROIs into it, flattens them, and uses them to quantify the total area of all ROIs/slice:

.....

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