# 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 from net.imglib2.util import Intervals from net.imglib2.loops import LoopBuilder img = IL.wrap(imp_rgb) # an ARGBType Img red = Converters.argbChannel(img, 1) # a view of the ARGB red channel