Created
March 5, 2014 15:46
-
-
Save kmader/9369798 to your computer and use it in GitHub Desktop.
Calculate the average value in each slice
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image = WindowManager.getCurrentImage() | |
stack = image.getStack() # get the stack within the ImagePlus | |
n_slices = stack.getSize() # get the number of slices | |
# iterate over every slice | |
for sliceIndex in range(1,n_slices+1): | |
curSlice=stack.getProcessor(sliceIndex) | |
sumVal=0;countPixel=0 | |
# iterate over every pixel in the slice | |
for cPixel in curSlice.toFloatArrays()[0]: | |
sumVal+=cPixel | |
countPixel+=1 | |
IJ.log("Slice:"+str(sliceIndex)+", Mean:"+str(sumVal/countPixel)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment