NaN on Results window

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

NaN on Results window

Miguel Tapia R.
Hello everyone,

I would like to exchange "0" values I obtained from a 32-bit image to "NaN" in the Results window. I wrote the following macro:


newImage("Untitled", "8-bit black", 400, 400, 1);

run("32-bit");

nBins = 256;
histMin = 0;
histMax = 256;

        run("Clear Results");
        row=0;
   
getHistogram(values, counts, nBins, histMin, histMax);

        for (j=0; j<nBins; j++) {
      setResult("Bin", row, values[j]);
      setResult("Numbers", row, counts[j]);
      count = counts[j];
        if (count==0) count=NaN;
        updateResults();
        row++;

   name = getTitle;
   name = name + ".csv";

}

in the Results window, bin 0 has all the values (in this case 160000) and the rest of bins shows "0" and i would ask if it is possible to change 0 to NaN to be displayed.

Thanks in advance,


Miguel

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

Re: NaN on Results window

Michael Schmid
Hi Miguel,

first, make sure that you put the curly braces into the right place.
ImageJ is not python; it's the braces, not the indent that determine the
program flow.

Second, it does not help to set a variable like 'count', 'name' if you
do nothing with it.
I guess that you want something like the following:

newImage("Untitled", "8-bit black", 400, 400, 1);

run("32-bit");

nBins = 256;
histMin = 0;
histMax = 256;

run("Clear Results");
getHistogram(values, counts, nBins, histMin, histMax);

for (j=0; j<nBins; j++) {
   if (counts[j] == 0)
     counts[j] = NaN;
   setResult("Bin", j, values[j]);
   setResult("Numbers", j, counts[j]);
}
updateResults();
name = getTitle();
name = name + ".csv";
IJ.renameResults(name);


Michael
________________________________________________________________

On 2016-11-16 20:58, Miguel Tapia R. wrote:

> Hello everyone,
>
> I would like to exchange "0" values I obtained from a 32-bit image to
> "NaN" in the Results window. I wrote the following macro:
>
>
> newImage("Untitled", "8-bit black", 400, 400, 1);
>
> run("32-bit");
>
> nBins = 256; histMin = 0; histMax = 256;
>
> run("Clear Results"); row=0;
>
> getHistogram(values, counts, nBins, histMin, histMax);
>
> for (j=0; j<nBins; j++) { setResult("Bin", row, values[j]);
> setResult("Numbers", row, counts[j]); count = counts[j]; if
> (count==0) count=NaN; updateResults(); row++;
>
> name = getTitle; name = name + ".csv";
>
> }
>
> in the Results window, bin 0 has all the values (in this case 160000)
> and the rest of bins shows "0" and i would ask if it is possible to
> change 0 to NaN to be displayed.
>
> Thanks in advance,
>
>
> Miguel

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

Re: NaN on Results window

Miguel Tapia R.
In reply to this post by Miguel Tapia R.
hi Michael,

Yes, that was what I need, thank you very much for your explanation and help!,


Miguel

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