In ImageJ, you can do the following to apply a mask to an RGB image:
import ij.ImagePlus;
import ij.plugin.ImageCalculator;
[...]
ImageCalculator ic = new ImageCalculator();
ImagePlus imp3 = ic.run("AND create", imp1, imp2);
with imp1
and imp2
being instances of the ImagePlus
class, imp1
being the original image (e.g. RGB) and imp2
being the binary mask image.
To get this code, I was running Process > Image Calculator... while running the macro recorder (Plugins > Macros > Record...) in Java mode.