Created
February 3, 2014 07:09
-
-
Save hirokai/8779868 to your computer and use it in GitHub Desktop.
This file contains 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
# Example of Fiji script for taking statistics of every stack in a stack file. | |
# Statistics of 3 ROIs are taken for every stack. | |
from ij import IJ | |
from ij.process import ImageStatistics as IS | |
# import os | |
options = IS.MEAN | IS.MEDIAN | IS.MIN_MAX | IS.AREA | |
def get_statistics(imp): | |
# Return statistics for the given ImagePlus | |
global options | |
ip = imp.getProcessor() | |
stats = IS.getStatistics(ip, options, imp.getCalibration()) | |
return stats.mean, stats.median, stats.min, stats.max, stats.area | |
filename = "image.tif" | |
rois = [[56, 55, 13, 13], | |
[51, 82, 15, 7], | |
[92, 58, 7, 13]] | |
def get_framestat(imp, i): | |
imp.setSlice(i) | |
mean, median, min, max,area = get_statistics(imp) | |
return mean,median,min,max,area | |
# print "Processing", filename | |
imp = IJ.openImage(filename) | |
if imp is None: | |
print "Could not open image from file:", filename | |
else: | |
n = imp.getNFrames() | |
for i in range(1,n+1): | |
imp.setRoi(*rois[0]) | |
mean, median, min, max, area = get_framestat(imp,i) | |
imp.setRoi(*rois[1]) | |
mean2, median2, min2, max2, area2 = get_framestat(imp,i) | |
imp.setRoi(*rois[2]) | |
mean3, median3, min3, max3, area3 = get_framestat(imp,i) | |
print mean, "\t", mean2, "\t", mean3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment