Login  Register

Problem with StackStatistics function (Histogram)

Posted by damien.schnebelen on Jul 03, 2015; 12:39am
URL: http://imagej.273.s1.nabble.com/Problem-with-StackStatistics-function-Histogram-tp5013403.html

Hi everybody,
I've loaded stacks in Fiji and I used the StackStatistics function applied on these stacks. One output of this function is the histogram.
Nonetheless, severals tests make me wondering that the range of value for the x-axis is [0, max] instead of [0,255] where max is defined by the maximum pixel value (max = 100 for example for a stack filled with pixels valued  0 or 100).
The main problem is that in this range of values, the histogram function gives us 256 values too and not 'max+1'!
Do you know how one can face this issue ? Is there an option in the StatckStatistics function which allows us to set the range automatically?
Thank you by advance.

You will find below one of the test I have done.

Script:
Im_green = ImagePlus("Green", green) #Stack Loaded
green = Im_green.getStack()        

for i in range(1, Im_green.getNSlices()+1):    #Initialize all slices with pixels whose value is 0
        ip = green.getProcessor(i)
        rect = Roi(0, 0, Im_crop.width,Im_crop.height)
        ip.setRoi(rect)
        ip.setValue(0)
        ip.fill()

        #Im_green.show()
        stats_before = StackStatistics(Im_green)   #Calculating the histogram of the stack
        hist_before = stats_before.histogram   #Store the histogram

        p = 1
        ip = green.getProcessor(p)
        rect = Roi(0, 0, Im_crop.width,Im_crop.height) # Fill the first slice with pixels whose value is 100
        ip.setRoi(rect)
        ip.setValue(100)
        ip.fill()
       
        stats_after = StackStatistics(Im_green) #Calculate the histogram of the stack after this shift
        hist_after = stats_after.histogram
       
       
        print " Green Hist Values Before " + " : \n" + str(hist_before) + "\n"   #Compare the results
        print " Green Hist Values After " + " : \n" + str(hist_after) + "\n"

Results
Green Hist Values Before  :
array('i', [530063160, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1661640])

Here you can see that the max value is 1661640, which fit with the area of one slice. But this values correspond to a pixel value of 100 and not 255...