Re: Getting the number of pixels which values are below a certain threshold

Posted by Stephan Bender on
URL: http://imagej.273.s1.nabble.com/Getting-the-number-of-pixels-which-values-are-below-a-certain-threshold-tp3688975p3688977.html

Hi Michael,

thanks for the advice. However, I still do not get it because of the
loop you describe.

This is how I would start with the macro:

    name = getArgument;
    if (name=="") exit ("No argument!");
    setBatchMode(true);
    open(name);
     // here goes the loop
     print(getTitle+": "+result);

Can you please help me with the loop?

Thank you!

Best regards,

Stephan

Am 02.03.2010 11:05, schrieb Michael Schmid:

> Hi Stephan,
>
> this should be easy:
>   getStatistics(area, mean, min, max, std, histogram);
> In a 'for' loop, sum up all values in the histogram array from index 0 to
>   floor(lengthOf(histogram)*(threshold-min)/(max-min))
> where threshold is -500 in your case.
> Write the result to a file:
>  f = File.open(path);
>  print(f, result);
> in your shell script or batch file, you can read the value from the file.
>
>
> Michael
> ________________________________________________________________
>
> On 1 Mar 2010, at 18:18, Stephan Bender wrote:
>
>> Hello,
>>
>> I'm quite new to ImageJ, I hope someone can help me with this task:
>>
>> I need get the number of pixels which values are below a certain
>> threshold. The image format is DICOM (16 bit), and I need the result
>> on a Unix command line, so I guess I'll have to use a macro function.
>> A common image has appr. 60% of the pixel values from -2048 to -500,
>> I need to know the exact number of pixels below -500.
>>
>> Thank you very much for your help!
>>
>> Best regards,
>>
>> Stephan