Before or after ImageProcessor.setRoi calculations

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

Before or after ImageProcessor.setRoi calculations

CARL Philippe (LBP)
Dear all,
Under the following link (code as well copied below):
        http://punias.free.fr/ImageJ/My_Plugin.java
I perform Measurements.AREA and Measurements.MEAN calculations before and
after applying a ImageProcessor.setRoi method on both a rectangular and
round PolygonRoi.
And as the obtained results are similar for the rectangular roi, they quite
differ for the round one.
Is this a bug or am I doing something wrong within my calculations?
I thank you very much for your lightings on this.
My best regards,
Philippe

import ij.IJ;
import ij.ImagePlus;
import ij.measure.Measurements;
import ij.plugin.frame.RoiManager;
import ij.plugin.PlugIn;
import ij.gui.PolygonRoi;
import ij.gui.Roi;
import ij.process.ImageProcessor;
import ij.process.ImageStatistics;

public class My_Plugin implements PlugIn {

        ImageStatistics stats;
        Roi roi;
        float[] rectangleX = {25.30f, 126.93f, 126.93f, 25.30f};
        float[] rectangleY = {29.43f,  29.43f,  65.28f, 65.28f};
        float[] roundX = {128.00f, 126.93f, 125.86f, 124.80f,
123.75f, 122.72f, 121.70f, 120.72f, 119.76f, 118.84f, 117.95f, 117.10f,
116.29f, 115.53f, 114.82f, 114.17f, 113.56f, 113.01f, 112.53f, 112.10f,
111.74f, 111.44f, 111.20f, 111.03f, 110.93f, 110.90f, 110.93f, 111.03f,
111.20f, 111.44f, 111.74f, 112.10f, 112.53f, 113.01f, 113.56f, 114.17f,
114.82f, 115.53f, 116.29f, 117.10f, 117.95f, 118.84f, 119.76f, 120.72f,
121.70f, 122.72f, 123.75f, 124.80f, 125.86f, 126.93f, 128.00f, 129.07f,
130.14f, 131.20f, 132.25f, 133.28f, 134.30f, 135.28f, 136.24f, 137.16f,
138.05f, 138.90f, 139.71f, 140.47f, 141.18f, 141.83f, 142.44f, 142.99f,
143.47f, 143.90f, 144.26f, 144.56f, 144.80f, 144.97f, 145.07f, 145.10f,
145.07f, 144.97f, 144.80f, 144.56f, 144.26f, 143.90f, 143.47f, 142.99f,
142.44f, 141.83f, 141.18f, 140.47f, 139.71f, 138.90f, 138.05f, 137.16f,
136.24f, 135.28f, 134.30f, 133.28f, 132.25f, 131.20f, 130.14f, 129.07f};
        float[] roundY = {144.10f, 144.07f, 143.97f, 143.80f,
143.56f, 143.26f, 142.90f, 142.47f, 141.99f, 141.44f, 140.83f, 140.18f,
139.47f, 138.71f, 137.90f, 137.05f, 136.16f, 135.24f, 134.28f, 133.30f,
132.28f, 131.25f, 130.20f, 129.14f, 128.07f, 127.00f, 125.93f, 124.86f,
123.80f, 122.75f, 121.72f, 120.70f, 119.72f, 118.76f, 117.84f, 116.95f,
116.10f, 115.29f, 114.53f, 113.82f, 113.17f, 112.56f, 112.01f, 111.53f,
111.10f, 110.74f, 110.44f, 110.20f, 110.03f, 109.93f, 109.90f, 109.93f,
110.03f, 110.20f, 110.44f, 110.74f, 111.10f, 111.53f, 112.01f, 112.56f,
113.17f, 113.82f, 114.53f, 115.29f, 116.10f, 116.95f, 117.84f, 118.76f,
119.72f, 120.70f, 121.72f, 122.75f, 123.80f, 124.86f, 125.93f, 127.00f,
128.07f, 129.14f, 130.20f, 131.25f, 132.28f, 133.30f, 134.28f, 135.24f,
136.16f, 137.05f, 137.90f, 138.71f, 139.47f, 140.18f, 140.83f, 141.44f,
141.99f, 142.47f, 142.90f, 143.26f, 143.56f, 143.80f, 143.97f, 144.07f};

        public void run(String arg) {
                RoiManager rm = RoiManager.getInstance();
                if (rm==null) rm = new RoiManager();
                ImagePlus imp =
IJ.openImage("http://wsr.imagej.net/images/blobs.gif");
                roi = new PolygonRoi(rectangleX, rectangleY,
rectangleX.length, Roi.POLYGON);
                roi.setName("rectangular");
                rm.addRoi(roi);
                roi = new PolygonRoi(roundX, roundY,  roundX.length,
Roi.POLYGON);
                roi.setName("round");
                rm.addRoi(roi);
                imp.show();
                ImageProcessor ip = imp.getProcessor();
                rm.select(imp, 0);
                stats = ImageStatistics.getStatistics(ip , Measurements.AREA
+ Measurements.MEAN, null);
                IJ.log("rectangular roi before ImageProcessor.setRoi - area
= " + stats.area + " mean = " + stats.mean);
                ip.setRoi(imp.getRoi());
                stats = ImageStatistics.getStatistics(ip , Measurements.AREA
+ Measurements.MEAN, null);
                IJ.log("rectangular roi after    ImageProcessor.setRoi -
area = " + stats.area + " mean = " + stats.mean);
                rm.select(imp, 1);
                stats = ImageStatistics.getStatistics(ip , Measurements.AREA
+ Measurements.MEAN, null);
                IJ.log("round          roi before ImageProcessor.setRoi -
area = " + stats.area + " mean = " + stats.mean);
                ip.setRoi(imp.getRoi());
                stats = ImageStatistics.getStatistics(ip , Measurements.AREA
+ Measurements.MEAN, null);
                IJ.log("round          roi after    ImageProcessor.setRoi -
area = " + stats.area + "   mean = " + stats.mean);
        }
}

Philippe CARL
Laboratoire de Bioimagerie et Pathologies
UMR 7021 CNRS - Université de Strasbourg
Faculté de Pharmacie
74 route du Rhin
67401 ILLKIRCH
Tel : +33(0)3 68 85 41 84

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