Skip to main content

Add a 'transparency' band to a single banded image

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
1 reply [Last post]
newmanw10
Offline
Joined: 2009-08-17

I have two sets of single banded images. Each set has many images. The hasAlpha on the images is false. I am creating two mosaics one for the first set of images and one for the second set of images.

When I mosaic the images together from each set they do not always span the entire mosaic. Because of this I create a blank single band image as a background and lay the images on the backgroud. For example and 'X' is an image from the set and a '0' rpresents the blank background I created.

First set mosaic:

X 0 X 0

0 X 0 X

X 0 X 0

Second Set mosaic:

0 X 0 X

X 0 X 0

0 X 0 X

I want to create a third mosaic that is a combintation of the two mosaics I created above. I know that I could use all the images from set 1 AND set 2 to create one mosaic but I cannot go that route as that breaks the current design. So i am stuck with creating the two mosaics, then trying to use those to create a third.

i.e. I would like the image to be complete (in this example) it would look like this:

X X X X

X X X X

X X X X

The problem is that the '0' (or blank) portion of the two mosaic images I created is not transparent, so when I mosaic them only the top image is visible.

What I am wondering is if I can add a 'transparent' second band to each of the images in each set. Then as my background instead of a blank single band image I could create an image with two bands, one with data, and one with the transparency band set to transparent. I.E. a transparent background.

Set 1 (X is a single image from the set in which I have added a second band) and '-' is a transparent background ( 2 bands, but second band is completly transparent.

X - X -

- X - X

X - X -

And the same for set two. Then since the '-' is tranparent I should get the desired result. I could then strip off the second band from the final mosaic to end up with my new one band image.

Problem is I have no idea if this is even possible. I guess the easy question to ask is: can I somehow add another band to an image that represents transparency. If I can do that I think I can handle the rest.

Thanks.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rgd
Offline
Joined: 2005-08-23

This is puzzling because you shouldn't have to do anything special to
get what you want (if I understand it correctly). No mucking about with
transparency layers necessary. You're using the Mosaic operator, right?

First, the background of a mosaic is set to 0 by default, if there are
no source images. So you shouldn't need the background 0 image.

Second, if the mosaic type is OVERLAY (which is the default), then it
should pick the first non-0 input for each pixel. So the parts of the
image that are 0 should automatically be transparent.

See the MosaicDescriptor javadocs for more details.

HTH...

-Bob

On 1/19/12 6:24 PM, forums@java.net wrote:
> I have two sets of single banded images. Each set has many images. The
> hasAlpha on the images is false. I am creating a two mosaics one for the
> first set of images and one for the second set of images.
>
> When I mosaic the images together from each set they do not always span the
> entire mosaic. Because of this I create a blank single band image as a
> background and lay the images on the backgroud. For example and 'X' is an
> image from the set and a '0' rpresents the blank background I created.
>
> First set mosaic:
>
> X 0 X 0
>
> 0 X 0 X
>
> X 0 X 0
>
> Second Set mosaic:
>
> 0 X 0 X
>
> X 0 X 0
>
> 0 X 0 X
>
> I want to create a third mosaic that is a combintation of the two sets.
> I know that I could use all the images from set 1 AND set 2 to create one
> mosaic but I cannot go that route as that breaks the current design.
>
> i.e. I would like the image to be complete (in this example) it would look
> like this:
>
> X X X X
>
> X X X X
>
> X X X X
>
> The problem is that the '0' (or blank) portion of the two images I
> created is
> not transparent, so when I mosaic on the top image is visisble and has
> blank
> spots.
>
> What I am wondering is if I can add a 'transparent' second band to each of
> the images in each set. Then as my background instead of a blank single
> band image I could create an image with two bands, one with data, and one
> with the transparency band set to transparent. I.E. a transparent
> background.
>
> Set 1 (X is a single image from the set in which I have added a second
> band)
> and '-' is a transparent background ( 2 bands, but second band is completly
> transparent.
>
> X - X -
>
> - X - X
>
> X - X -
>
> And the same for set two. Then since the '-' is tranparent I should get
> the
> desired result. I could then strip off the second band from the final
> mosaic to end up with my one band image.
>
>
>
> Problem is I have no idea if this is even possible. I guess the easy
> question to ask is: can I somehow add another band to an image that
> represents transparency. If I can do that I think I can handle the rest.
>
> Thanks.
>
>
>
>