Created
March 5, 2014 15:56
-
-
Save kmader/9369975 to your computer and use it in GitHub Desktop.
ImageJ plugin which calculates the average value in each slice
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
import ij.*; | |
import ij.process.*; | |
import ij.gui.*; | |
import java.awt.*; | |
import ij.plugin.*; | |
import ij.plugin.frame.*; | |
public class AverageSliceValue implements PlugIn { | |
public void run(String arg) { | |
ImagePlus imp = IJ.getImage(); | |
ImageStack is = imp.getStack(); | |
int n_slices = is.getSize(); | |
for(int sliceIndex=1;sliceIndex<=n_slices;sliceIndex++) { | |
double sumVal=0; | |
long countPixel=0; | |
ImageProcessor curSlice=is.getProcessor(sliceIndex); | |
float[][] sliceArray=curSlice.getFloatArray(); | |
for(int x=0;x<sliceArray.length;x++) { | |
for(int y=0;y<sliceArray[x].length;y++) { | |
sumVal+=sliceArray[x][y]; | |
countPixel+=1; | |
} | |
} | |
IJ.log("Slice:"+sliceIndex+", Mean:"+sumVal/countPixel); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment