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, 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, 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... |
> On Jul 2, 2015, at 8:39 PM, damien.schnebelen <[hidden email]> wrote:
> > 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). There is a StackStatistics constructor that allows you to specify the number of bins and the x-axis (pixel value) histogram range. The following JavaScript example generates a histogram of the T1 Head sample stack that uses 200 bins and a x-axis range of 0-400. The StackStatistics constructor with only an ImagePlus argument defaults to 256 bins and an x-axis range of min-max for 16-bit stacks and 0-255 for 8-bit stacks, where ‘min’ and ‘max’ are the minimum and maximum stack pixel values. -wayne imp = IJ.openImage("http://imagej.nih.gov/ij/images/t1-head.zip"); bins = 200; xmin = 0; xmax = 400; binSize = xmax/bins; stats = new StackStatistics(imp, bins, xmin, xmax); plot = new Plot("Histogram", "Pixel Value", "Count"); n = stats.histogram.length; x = new Array(n); y = new Array(n); for (i=0; i<n; i++) { x[i] = i*binSize; y[i] = stats.histogram[i]; } plot.setLimits(0, n*binSize, 0, 20000); plot.add("line", x, y); plot.show(); > > 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, 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, 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]) > > Green Hist Values After : > array('i', [528401520, 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, 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, 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... > > > -- > View this message in context: http://imagej.1557.x6.nabble.com/Problem-with-StackStatistics-function-Histogram-tp5013403.html > Sent from the ImageJ mailing list archive at Nabble.com. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Thank you very much, it works perfectly ! =)
|
Free forum by Nabble | Edit this page |