Posted by
Volker Baecker on
URL: http://imagej.273.s1.nabble.com/Plugin-assigning-roi-measurements-to-a-variable-tp3698886p3698890.html
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
try something like this:
image.setRoi(x, y, sub_sample_size, sub_sample_size);
ResultsTable measurements = new ResultsTable();
Analyzer analyzer = new Analyzer(image,
Measurements.STD_DEV, measurements);
analyzer.run(image.getProcessor());
double stdDev = measurements.getValue(ResultsTable.STD_DEV, 0);
System.out.println(stdDev);
The 4 you get is just the constant STD_DEV that is used to specify which
measurements you want, not the result of a measurement.
Volker
> ip.setRoi(x, y, sub_sample_size, sub_sample_size);
> Analyzer ana = new Analyzer();
> int measurements = Analyzer.getMeasurements();
> measurements = (ana.STD_DEV);
> IJ.write(Integer.toString(measurements));
>
> This just returns the value 4.
>
> Many thanks for any help,
>
> David Platten
> Clinical Scientist
> Northampton General Hospital
> Billing Road
> Northampton NN1 5BD
> tel +44 (0)1604 54 4369
>
>
> //-----------------------------------------------------------
> macro "Signal to noise map" {
> // Calculates the signal to noise of sub-samples
> // over an image.
> // Displays the results as a new image.
> // SNR taken as mean pixel value in ROI divided
> // by standard deviation in the region.
> // David Platten, July 2007
>
> // Ask the user for the size of the sub-samples.
> Dialog.create("Signal to noise image");
> Dialog.addMessage("Click OK to analyze, or cancel to exit (!).");
> Dialog.addNumber("Sub-sample size:", 50);
> Dialog.show();
> sub_sample_size = Dialog.getNumber();
>
> // Find the dimensions of the image and then
> // determine the number of sub-samples that
> // will go into it.
> width = getWidth;
> height = getHeight;
> i_max = floor(width/sub_sample_size) + 1;
> j_max = floor(height/sub_sample_size) + 1;
>
> // Create an array to hold the results
> results = newArray(i_max * j_max);
>
> // Loop through the image, stepping through in
> // increments equal to the sub-sample size.
> i = 0;
> j = 0;
> max_snr = 0; // Used to scale the results image
>
> for(x=0; x<width; x+=sub_sample_size) {
> j = 0;
> for(y=0; y<height; y+=sub_sample_size) {
> // Specify the width, height and position of the ROI, then
> // measure the standard deviation and mean within it.
> // SNR is calculated as mean / standard deviation and
> // written into the appropriate element of the results array.
> run("Specify...", "width="+sub_sample_size+"
> height="+sub_sample_size+" x="+x+" y="+y);
> run("Set Measurements...", "mean standard decimal=5");
> run("Measure");
>
> mean = getResult("Mean", nResults-1);
> stdev = getResult("StdDev", nResults-1);
>
> results[i + (j*i_max)] = mean / stdev;
>
> // Check to see if this is a new maximum snr. This is
> // used to scale the results at the end.
> if(results[i + (j*i_max)] > max_snr) max_snr = results[i + (j*i_max)];
>
> j++;
> }
> i ++;
> }
>
> // Create new image to display the results.
> // At the moment this is an 8-bit image, 256 shades of grey.
> image_title = "SNR, " + sub_sample_size + " pixel sub-samples";
> newImage(image_title, "8-bit Black", i_max, j_max, 1);
>
> // Step through the results array, scaling the values using
> // the known maximum figure and then allocating the value to
> // the appropriate pixel.
> for(i=0;i<i_max; i++) {
> for(j=0;j<j_max; j++) {
> temp = round(results[i + (j*i_max)] / max_snr * 256);
> setPixel(i, j, temp);
> }
> }
>
> // Resize the results image to have the same dimensions
> // as the original and then enhance the contrast (an
> // auto window and level).
> run("Size...", "width="+width+" height="+height+" constrain");
> run("Enhance Contrast", "saturated=0.5");
> }
> //-----------------------------------------------------------
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla -
http://enigmail.mozdev.orgiD8DBQFGlJtTxZKX7A/4oMERAp9IAJ9na74BMeUR4y8rX54vHOPlVMMgoQCePzUU
JIymQSFCGAmt2J7z0NhW+WQ=
=Y3TZ
-----END PGP SIGNATURE-----
--
passerelle antivirus du campus CNRS de Montpellier
--