Skip to main content

Mosaic image has 'weird' colors when overlaying two images on top of each other

Please note these forums are being decommissioned and use the new and improved forums at
1 reply [Last post]
Joined: 2009-08-17

This is a follow up tp a previous post I had, but I am trying to do things a little different.

I have two images that should overlay. The top image is transparent in the middle portion of the image. I want the bottom image to show through in the places where the top image is transparent (ie in the middle).

I pass a sourceAlphas parameter into the mosaic function but instead of just hard coding it to 0 or 1 (transparent or opaque) I actually select the alpha band from each image and use that.

But only the top image is showing up. The portions on that image that were transparent are just black and I cannot see the bottom image in those areas.

I have tried not passing in the sourceAlphas vector and the transparency works (ie I can see the bottom image in places where the top image is transparent. However if I do this I get weird colors where the two images overlap. In that case the image I see is the top image but some of the pixels are not quite right and the image is not as crisp.

I am hoping to show the top image (in places where it is not transparent) and have that image unmodified (ie should be crisp and none of the pixels should have been modified), but in places where that top image is transparent I want the bottom image to show through.

Any one else have similar problems with mosiac?

Vector sourceAlphas = new Vector();

BufferedImage image1 = .......

<p>// need to get this image to rgba<br /><br />IndexColorModel icm = (IndexColorModel) image1.getColorModel();<br /><br />byte[ ][ ] data = new byte[4][icm.getMapSize()];</p>

<p>icm.getReds(data[0]);<br /><br />icm.getGreens(data[1]);<br /><br />icm.getBlues(data[2]);<br /><br />icm.getAlphas(data[3]);<br /><br />LookupTableJAI lut = new LookupTableJAI(data);<br /><br />RenderedOp rgbaImage1 = JAI.create(&quot;lookup&quot;, image1, lut);</p><p>// Get alpha bits from this image</p>sourceAplhas.add(JAI.create(&quot;bandSelect&quot;, rgbaImage1, new int[] {3}));

<p>BufferedImage image2 = .......</p>

<p>// need to get this image to rgba<br /><br />icm = (IndexColorModel) image2.getColorModel();<br /><br />data = new byte[4][icm.getMapSize()];<br /><br />icm.getReds(data[0]);<br /><br />icm.getGreens(data[1]);<br /><br />icm.getBlues(data[2]);<br /><br />icm.getAlphas(data[3]);<br /><br />lut = new LookupTableJAI(data);</p><p>RenderedOp rgbaImage2 = JAI.create(&quot;lookup&quot;, image2, lut)</p><pre>
// Get aplha bits from this image
sourceAplhas.add(JAI.create(&quot;bandSelect&quot;, rgbaImage2, new int[] {3}));

ParameterBlockJAI params = new ParameterBlockJAI(&quot;mosaic&quot;);



params.setParameter(&quot;mosaicType&quot;, MosaicDescriptor.MOSAIC_TYPE_OVERLAY);
params.setParameter(&quot;sourceAlphas&quot;, sourceAlphas); // pass in source alphas

RenderedOp mosaic = JAI.create("mosaic", params);// Then show the image, since both are in position x/y 0/0 then one should be on top of the other

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2009-08-17

An easier question. What is the proper way to use the mosaic descriptor to mosaic images together that have transparent pixels. I want the mosaic to obey the transparency of each pixel. Ie if the pixel is opaque that pixel should show of it is transparent a pixel under that pixel should show.