Created
November 4, 2014 17:48
-
-
Save iarganda/c7fc0a88b8d2737c9d3d 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
import ij.IJ; | |
import ij.ImagePlus; | |
import ij.ImageStack; | |
import ij.process.FloatProcessor; | |
// assume probability image as the currently selected one | |
probs = IJ.getImage(); | |
// read image dimensions | |
width = probs.getWidth(); | |
height = probs.getHeight(); | |
nSlices = probs.getNSlices(); | |
nClasses = probs.getNChannels(); | |
// create stack to store segmentation | |
segmentation = new ImageStack( width, height ); | |
// for each slice | |
for( s = 1; s <= nSlices; s++ ) | |
{ | |
probs.setSlice( s ); | |
probStack = probs.getImageStack(); | |
segSlice = new FloatProcessor( width, height ); | |
for( x=0; x<width; x++ ) | |
for( y=0; y<height; y++ ) | |
{ | |
max = 0f; | |
cIndex = 0; | |
// select class with higher probability | |
for( c=0; c<nClasses; c++ ) | |
if( probStack.getVoxel( x, y, c ) > max ) | |
{ | |
max = probStack.getVoxel( x, y, c ); | |
cIndex = c; | |
} | |
segSlice.setf( x, y, (float) cIndex ); | |
} | |
segmentation.addSlice( "", segSlice ); | |
} | |
// create and display segmentation image | |
result = new ImagePlus( "Thresholded probabilities", segmentation ); | |
result.show(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment