imp_rgb = IJ.getImage() # IJ.openImage("http://imagej.nih.gov/ij/images/flybrain.zip") # Define a threshold for the red channel: any values at or above # in the green channel will be placed into a new image threshold = 119 # Example 1: with ImageCalculator from ij.process import ImageProcessor from ij.plugin import ChannelSplitter, ImageCalculator # Split color channels red, green, blue = ChannelSplitter().split(imp_rgb) # 3 ImagePlus # Set threshold for each slice for index in xrange(1, red.getNSlices() + 1): bp = red.getStack().getProcessor(index) #bp.setThreshold(threshold, 255, ImageProcessor.BLACK_AND_WHITE_LUT) bp.threshold(threshold) # mask is 0, background is 255 # Apply threshold: convert each slice to a mask (only 0 or 255 pixel values) #IJ.run(red, "Convert to Mask", "method=Default background=Dark black") red.show() green_under_red_mask = ImageCalculator().run("and create stack", red, green) green_under_red_mask.show() """ # Example 2: with ImgLib2 LoopBuilder from net.imglib2.img.display.imagej import ImageJFunctions as IL from net.imglib2.converter import Converters from net.imglib2.img.array import ArrayImgs