Java Code Examples for ij.process.ColorProcessor#set()

The following examples show how to use ij.process.ColorProcessor#set() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ValueToNoise.java    From render with GNU General Public License v2.0 6 votes vote down vote up
private static void processColor(final ColorProcessor ip,
                                 final int value,
                                 final int min,
                                 final int max) {
    final int scale = max - min + 1;
    final Random rnd = new Random();
    final int n = ip.getWidth() * ip.getHeight();
    for (int i = 0; i < n; ++i) {
        final int v = ip.get(i) & 0x00ffffff;
        if (v == value) {
            final int r = rnd.nextInt(scale) + min;
            final int g = rnd.nextInt(scale) + min;
            final int b = rnd.nextInt(scale) + min;

            ip.set(i, (((((0xff << 8) | r) << 8) | g) << 8) | b);
        }
    }
}
 
Example 2
Source File: ValueToNoise.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
final static private void processColor(final ColorProcessor ip, final int value, final int min, final int max) {
	final int scale = max - min + 1;
	final Random rnd = new Random();
	final int n = ip.getWidth() * ip.getHeight();
	for (int i =0; i < n; ++i) {
		final int v = ip.get(i);
		if (v == value)
		{
			final int r = rnd.nextInt(scale) + min;
			final int g = rnd.nextInt(scale) + min;
			final int b = rnd.nextInt(scale) + min;

			ip.set(i, (((((0xff << 8) | r) << 8) | g) << 8) | b);
		}
	}
}
 
Example 3
Source File: ColorImages.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Assumes reference image contains a ByteProcessor.
 */
private final static ImageProcessor binaryOverlayGray8(ImageProcessor refImage, 
		ImageProcessor mask, Color color) 
{
	int width = refImage.getWidth(); 
	int height = refImage.getHeight(); 
	ColorProcessor result = new ColorProcessor(width, height);
	
	int value;
	int rgbValue = color.getRGB();
	
	// Iterate on image pixels, and choose result value depending on mask
	for (int y = 0; y < height; y++) {
		for (int x = 0; x < width; x++) {
			if(mask.get(x, y) == 0) {
				// choose value from reference image
				value = refImage.get(x, y);
				// convert grayscale to equivalent color
				value = (value & 0x00FF) << 16 | (value & 0x00FF) << 8 | (value & 0x00FF);
				result.set(x, y, value);

			} else {
				// set value to chosen color
				result.set(x, y, rgbValue);
			}
		}
	}
	
	return result;
}
 
Example 4
Source File: ColorImages.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Assumes reference image contains a ColorProcessor.
 */
private final static ImageProcessor binaryOverlayRGB(ImageProcessor refImage, 
		ImageProcessor mask, Color color)
{
	int width = refImage.getWidth(); 
	int height = refImage.getHeight(); 
	ColorProcessor result = new ColorProcessor(width, height);
	
	int value;
	int rgbValue = color.getRGB();
	
	// Iterate on image pixels, and choose result value depending on mask
	for (int y = 0; y < height; y++) {
		for (int x = 0; x < width; x++) {
			if(mask.get(x, y) == 0) {
				// choose RGB value directly from reference image
				value = refImage.get(x, y);
				result.set(x, y, value);

			} else {
				// set value to chosen color
				result.set(x, y, rgbValue);
			}
		}
	}
	
	return result;
}
 
Example 5
Source File: LabelImages.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new Color image from a label planar image, a LUT, and a 
 * color for background.
 * 
 * @param image an ImageProcessor with label values and 0 for background
 * @param lut the array of color components for each label 
 * @param bgColor the background color
 * @return a new instance of ColorProcessor
 */
public static final ColorProcessor labelToRgb(ImageProcessor image, byte[][] lut, Color bgColor) 
{
	int width = image.getWidth();
	int height = image.getHeight();
	
	int bgColorCode = bgColor.getRGB();
	
	ColorProcessor result = new ColorProcessor(width, height);
	for (int y = 0; y < height; y++) 
	{
		for (int x = 0; x < width; x++) 
		{
			int index = (int) image.getf(x, y);
			if (index == 0) 
			{
				result.set(x, y, bgColorCode);
			} 
			else 
			{
				byte[] rgb = lut[index - 1];
				int color = (int) ((rgb[0] & 0xFF) << 16
						| (rgb[1] & 0xFF) << 8 | (rgb[2] & 0xFF));
				result.set(x, y, color);
			}
		}
	}
	
	return result;
}
 
Example 6
Source File: ColorImages.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Creates a new color ImageStack from the red, green and blue ImageStack
 * instances. Each channel must contains instances of ByteProcessor.
 * 
 * @param red
 *            the image for the red channel (must contain ByteProcessor instances)
 * @param green
 *            the image for the green channel (must contain ByteProcessor instances)
 * @param blue
 *            the image for the blue channel (must contain ByteProcessor instances)
 * @return the color image corresponding to the concatenation of the three
 *         channels
 * @throws IllegalArgumentException
 *             if one of the ImageStack does not contain instances of ByteProcessor
 */
public static final ImageStack mergeChannels(ImageStack red, 
		ImageStack green, ImageStack blue)
{
	// check validity of input
	if (!(red.getProcessor(1) instanceof ByteProcessor))
		throw new IllegalArgumentException("Input channels must be instances of ByteProcessor");
	if (!(green.getProcessor(1) instanceof ByteProcessor))
		throw new IllegalArgumentException("Input channels must be instances of ByteProcessor");
	if (!(blue.getProcessor(1) instanceof ByteProcessor))
		throw new IllegalArgumentException("Input channels must be instances of ByteProcessor");
	
	int width = red.getWidth();
	int height = red.getHeight();
	int depth = red.getSize();
	ImageStack result = ImageStack.create(width, height, depth, 24);
	
	for (int z = 1; z <= depth; z++)
	{
		// extract current slices
		ByteProcessor redSlice = (ByteProcessor) red.getProcessor(z);
		ByteProcessor greenSlice = (ByteProcessor) green.getProcessor(z);
		ByteProcessor blueSlice = (ByteProcessor) blue.getProcessor(z);
		ColorProcessor rgbSlice =  (ColorProcessor) result.getProcessor(z);

		for (int y = 0; y < height; y++)
		{
			for (int x = 0; x < width; x++)
			{
				int r = redSlice.get(x, y);
				int g = greenSlice.get(x, y);
				int b = blueSlice.get(x, y);
				int rgbCode = (r << 16) | (g << 8) | b;
				rgbSlice.set(x, y, rgbCode);
			}
		}
		
		result.setProcessor(rgbSlice, z);
	}
	
	return result;	
}
 
Example 7
Source File: ReconstructionTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Test
public void testReconstructByDilation_RGB_C4() 
{
	// size of images
	int width = 10;
	int height = 10;
	
	// Choose contrasted colors
	int redCode 	= 0xFF0000;
	int greenCode 	= 0x00FF00;
	int blueCode 	= 0x0000FF;
	int yellowCode 	= 0xFFFF00;

	// create black images with four 3x3 squares containing one of the
	// contrasted colors
	ColorProcessor mask = new ColorProcessor(width, height);
	for (int y = 0; y < 3; y++)
	{
		for (int x = 0; x < 3; x++)
		{
			mask.set(x + 1, y + 1, redCode);
			mask.set(x + 5, y + 1, greenCode);
			mask.set(x + 1, y + 5, blueCode);
			mask.set(x + 5, y + 5, yellowCode);
		}
	}

	// create a marker image with two white squares
	ColorProcessor marker = new ColorProcessor(width, height);
	marker.set(6, 2, 0xFFFFFF);
	marker.set(2, 6, 0xFFFFFF);
	
	// Apply reconstruction
	ImageProcessor result = Reconstruction.reconstructByDilation(marker, mask, 4);
	
	// result should contain only the two colored squares specified by the
	// marker image
	assertEquals(0, result.get(2, 2) & 0x00FFFFFF);
	assertEquals(0, result.get(6, 6) & 0x00FFFFFF);
	assertEquals(greenCode, result.get(6, 2) & 0x00FFFFFF);
	assertEquals(blueCode, result.get(2, 6) & 0x00FFFFFF);
}