Skip to main content

[JAI] Composite again

8 replies [Last post]
Anonymous

Hi,

I'm using the JAI 'composite' operation on images which do not have the same
dimensions. I wondered how does JAI handles this, and then I found the
following thread in the mailing list archives :

http://archives.java.sun.com/cgi-bin/wa?A2=ind9910&L=jai-interest&D=0&I=...
=474

It is said that JAI's default behaviour is to consider only the intersection
between images. It is also said that if you want to composite a small image
onto a larger one, you should first perform the composite operation, and
then overlay the result onto the largest of the two input images. This is OK
when the largest of the two images completely contains the bounds of the
smaller one. But now I need to do the same with two images that only have a
small overlapped area.
Does anyone know a efficient way to do this ?

Thanks a lot !
Stephane W.

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Aastha Bhardwaj

Hi Stéphane,

To get what you need, you should create a TiledImage with the dimensions
you would get with the two images overlapping, i.e. dimensions big
enough that both images would fit into the TiledImage. You can then set
the first image on the TiledImage, using the TiledImage.set() method,
you can then set the second image on the TiledImage, again using
TiledImage.set(). Finally you can use the JAI "composite" operation on
the two original images, and then set the resultant image on the
TiledImage. This should give you the expected result.

Aastha

---------------------
Aastha Bhardwaj
Java Advanced Imaging
Sun Microsystems

>
> I'm using the JAI 'composite' operation on images which do not have the same
> dimensions. I wondered how does JAI handles this, and then I found the
> following thread in the mailing list archives :
>
> http://archives.java.sun.com/cgi-bin/wa?A2=ind9910&L=jai-interest&D=0&I=...
> =474
>
> It is said that JAI's default behaviour is to consider only the intersection
> between images. It is also said that if you want to composite a small image
> onto a larger one, you should first perform the composite operation, and
> then overlay the result onto the largest of the two input images. This is OK
> when the largest of the two images completely contains the bounds of the
> smaller one. But now I need to do the same with two images that only have a
> small overlapped area.
> Does anyone know a efficient way to do this ?
>
> Thanks a lot !
> Stephane W.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

Stéphane Wasserhardt

Thanks a lot Aastha !

I changed your idea a bit because I must composite multiple overlapping
images. So there's the complete process :
I create an empty TiledImage (called "nextImage"), which size is the
bounding box of the union of all images to be combined. Then I use "set" to
put the first image.
I do the same with another TiledImage which will be used as alpha layer
(called "nextAlpha") : this time, I first use the "constant" operator, to
fill my image with zeros. Then I also use "set" to put the alpha layer of
the first image on it.
Now I can composite "nextImage" and its alpha layer "nextAlpha" with the
second image (and its alpha layer).
After that, I use the "bandselect" operator to re-build "nextImage" and
"nextAlpha" from the result.
Finally, I can re-iterate "composite" and "bandselect" operations with the
next images, until I get the final "nextImage" !

I detailled the process because I think this is a basic feature used in many
imagery tools (Gimp, PhotoShop, etc ..) and many ppl may need to implement
it.
If someone need the source code ... Just let me know !

Stephane

-----Message d'origine-----
De : Aastha Bhardwaj [mailto:Aastha.Bhardwaj@Sun.COM]
Envoyé : jeudi 26 mai 2005 00:33
À : interest@jai.dev.java.net
Objet : Re: [JAI] Composite again

Hi Stéphane,

To get what you need, you should create a TiledImage with the dimensions
you would get with the two images overlapping, i.e. dimensions big
enough that both images would fit into the TiledImage. You can then set
the first image on the TiledImage, using the TiledImage.set() method,
you can then set the second image on the TiledImage, again using
TiledImage.set(). Finally you can use the JAI "composite" operation on
the two original images, and then set the resultant image on the
TiledImage. This should give you the expected result.

Aastha

---------------------
Aastha Bhardwaj
Java Advanced Imaging
Sun Microsystems

>
> I'm using the JAI 'composite' operation on images which do not have the
same
> dimensions. I wondered how does JAI handles this, and then I found the
> following thread in the mailing list archives :
>
>
http://archives.java.sun.com/cgi-bin/wa?A2=ind9910&L=jai-interest&D=0&I=...
> =474
>
> It is said that JAI's default behaviour is to consider only the
intersection
> between images. It is also said that if you want to composite a small
image
> onto a larger one, you should first perform the composite operation, and
> then overlay the result onto the largest of the two input images. This is
OK
> when the largest of the two images completely contains the bounds of the
> smaller one. But now I need to do the same with two images that only have
a
> small overlapped area.
> Does anyone know a efficient way to do this ?
>
> Thanks a lot !
> Stephane W.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

Brian Burkhalter

Is this process something which could be accomplished using the "Mosaic"
operation?

http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/ja...

Brian

On Tue, 31 May 2005, Stéphane Wasserhardt wrote:

> Thanks a lot Aastha !
>
> I changed your idea a bit because I must composite multiple overlapping
> images. So there's the complete process :
> I create an empty TiledImage (called "nextImage"), which size is the
> bounding box of the union of all images to be combined. Then I use "set" to
> put the first image.
> I do the same with another TiledImage which will be used as alpha layer
> (called "nextAlpha") : this time, I first use the "constant" operator, to
> fill my image with zeros. Then I also use "set" to put the alpha layer of
> the first image on it.
> Now I can composite "nextImage" and its alpha layer "nextAlpha" with the
> second image (and its alpha layer).
> After that, I use the "bandselect" operator to re-build "nextImage" and
> "nextAlpha" from the result.
> Finally, I can re-iterate "composite" and "bandselect" operations with the
> next images, until I get the final "nextImage" !
>
> I detailled the process because I think this is a basic feature used in many
> imagery tools (Gimp, PhotoShop, etc ..) and many ppl may need to implement
> it.
> If someone need the source code ... Just let me know !
>
> Stephane
>
> -----Message d'origine-----
> De : Aastha Bhardwaj [mailto:Aastha.Bhardwaj@Sun.COM]
> Envoyé : jeudi 26 mai 2005 00:33
> À : interest@jai.dev.java.net
> Objet : Re: [JAI] Composite again
>
>
> Hi Stéphane,
>
> To get what you need, you should create a TiledImage with the dimensions
> you would get with the two images overlapping, i.e. dimensions big
> enough that both images would fit into the TiledImage. You can then set
> the first image on the TiledImage, using the TiledImage.set() method,
> you can then set the second image on the TiledImage, again using
> TiledImage.set(). Finally you can use the JAI "composite" operation on
> the two original images, and then set the resultant image on the
> TiledImage. This should give you the expected result.
>
> Aastha
>
> ---------------------
> Aastha Bhardwaj
> Java Advanced Imaging
> Sun Microsystems
>
> >
> > I'm using the JAI 'composite' operation on images which do not have the
> same
> > dimensions. I wondered how does JAI handles this, and then I found the
> > following thread in the mailing list archives :
> >
> >
> http://archives.java.sun.com/cgi-bin/wa?A2=ind9910&L=jai-interest&D=0&I=...
> > =474
> >
> > It is said that JAI's default behaviour is to consider only the
> intersection
> > between images. It is also said that if you want to composite a small
> image
> > onto a larger one, you should first perform the composite operation, and
> > then overlay the result onto the largest of the two input images. This is
> OK
> > when the largest of the two images completely contains the bounds of the
> > smaller one. But now I need to do the same with two images that only have
> a
> > small overlapped area.
> > Does anyone know a efficient way to do this ?
> >
> > Thanks a lot !
> > Stephane W.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> > For additional commands, e-mail: interest-help@jai.dev.java.net
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>

----------------
Brian Burkhalter
Advanced Development, Graphics and Media
Software Chief Technology Office
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

Stéphane Wasserhardt

Errrr ... ***slapping himself*** ... you're right ... I should have taken a
look at it, but I thought the Mosaic operation didn't take alpha layers into
account.

Thank you very much ! I think I'll get some better performance now :D

BTW, there was a mistake in my previous post : I forgot to tell that you
must overlay the result of the "composite" operation over the result of the
previous iteration. But nobody matters anyway, as everybody (except me 1
minute ago) knew that there is a "mosaic" operator ...

Stephane

-----Message d'origine-----
De : Brian Burkhalter [mailto:Brian.Burkhalter@Sun.COM]
Envoyé : mercredi 1 juin 2005 03:01
À : Java Advanced Imaging discussion list;
stephane.wasserhardt@magellium.fr
Objet : RE: [JAI] Composite again

Is this process something which could be accomplished using the "Mosaic"
operation?

http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/ja...
media/jai/operator/MosaicDescriptor.html

Brian

On Tue, 31 May 2005, Stéphane Wasserhardt wrote:

> Thanks a lot Aastha !
>
> I changed your idea a bit because I must composite multiple overlapping
> images. So there's the complete process :
> I create an empty TiledImage (called "nextImage"), which size is the
> bounding box of the union of all images to be combined. Then I use "set"
to
> put the first image.
> I do the same with another TiledImage which will be used as alpha layer
> (called "nextAlpha") : this time, I first use the "constant" operator, to
> fill my image with zeros. Then I also use "set" to put the alpha layer of
> the first image on it.
> Now I can composite "nextImage" and its alpha layer "nextAlpha" with the
> second image (and its alpha layer).
> After that, I use the "bandselect" operator to re-build "nextImage" and
> "nextAlpha" from the result.
> Finally, I can re-iterate "composite" and "bandselect" operations with the
> next images, until I get the final "nextImage" !
>
> I detailled the process because I think this is a basic feature used in
many
> imagery tools (Gimp, PhotoShop, etc ..) and many ppl may need to implement
> it.
> If someone need the source code ... Just let me know !
>
> Stephane
>
> -----Message d'origine-----
> De : Aastha Bhardwaj [mailto:Aastha.Bhardwaj@Sun.COM]
> Envoyé : jeudi 26 mai 2005 00:33
> À : interest@jai.dev.java.net
> Objet : Re: [JAI] Composite again
>
>
> Hi Stéphane,
>
> To get what you need, you should create a TiledImage with the dimensions
> you would get with the two images overlapping, i.e. dimensions big
> enough that both images would fit into the TiledImage. You can then set
> the first image on the TiledImage, using the TiledImage.set() method,
> you can then set the second image on the TiledImage, again using
> TiledImage.set(). Finally you can use the JAI "composite" operation on
> the two original images, and then set the resultant image on the
> TiledImage. This should give you the expected result.
>
> Aastha
>
> ---------------------
> Aastha Bhardwaj
> Java Advanced Imaging
> Sun Microsystems
>
> >
> > I'm using the JAI 'composite' operation on images which do not have the
> same
> > dimensions. I wondered how does JAI handles this, and then I found the
> > following thread in the mailing list archives :
> >
> >
>
http://archives.java.sun.com/cgi-bin/wa?A2=ind9910&L=jai-interest&D=0&I=...
> > =474
> >
> > It is said that JAI's default behaviour is to consider only the
> intersection
> > between images. It is also said that if you want to composite a small
> image
> > onto a larger one, you should first perform the composite operation, and
> > then overlay the result onto the largest of the two input images. This
is
> OK
> > when the largest of the two images completely contains the bounds of the
> > smaller one. But now I need to do the same with two images that only
have
> a
> > small overlapped area.
> > Does anyone know a efficient way to do this ?
> >
> > Thanks a lot !
> > Stephane W.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> > For additional commands, e-mail: interest-help@jai.dev.java.net
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>

----------------
Brian Burkhalter
Advanced Development, Graphics and Media
Software Chief Technology Office
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

Stéphane Wasserhardt

I successfully changed my code to use the Mosaic operator, and it works
well... at first sight. It seems that there's an odd behaviour :
Even if all images in the sourceAlpha parameter of the mosaic are constant
byte images with value 255, the result of the mosaic seems to be the
averaging of all source images. What I need in this case is to only get the
first image, because its alpha is "opaque" (value 255), and therefore it
should hide the other images.
I tried to change Transparency.OPAQUE to Transparency.TRANSLUCENT and to
Transparency.BITMASK in the RenderingHints, but it didn't change anything
...

If you need more info, here is how my app works :

The user can open images, and for each of them, give an opacity value in the
range 0-100. I use a class "StackImage" which wraps the openned images
(RenderedImage) and contains the opacity value (so I have two methods :
stackImage.getImage() and stackImage.getOpacity(), plus another usefull
method : stackImage.getBounds() ).
The program then draws the "mosaic" of all images, with the following code :

public static RenderedOp mosaic(StackImage[] stack) {
ImageLayout layout = new ImageLayout();
layout.setColorModel(
new ComponentColorModel(
ColorSpace.getInstance(ColorSpace.CS_sRGB),
new int[] {8, 8, 8},
false, false,
Transparency.OPAQUE,
DataBuffer.TYPE_BYTE
)
);
RenderingHints hints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout);

java.awt.Rectangle aExt;
RenderedOp[] alphaLayers = new RenderedOp[stack.length];
ParameterBlock pb = new ParameterBlock();
for (int i = 0; i < stack.length; i++) {
pb.addSource(stack[i].getImage());
aExt = stack[i].getBounds();
alphaLayers[i] = createConstant(
new Byte[] {opacityToAlpha(stack[i].getOpacity())},
aExt.x, aExt.y,
aExt.width, aExt.height
);
}
pb.add(MosaicDescriptor.MOSAIC_TYPE_BLEND);
pb.add(alphaLayers);

return JAI.create("mosaic", pb, hints); //$NON-NLS-1$
}

I use there two methods :
First, "createConstant", which uses the "constant" operator with the
following rendering hints :
RenderingHints hints;
ImageLayout layout = new ImageLayout();
layout.setMinX(x);
layout.setMinY(y);
layout.setTileGridXOffset(0);
layout.setTileGridYOffset(0);

layout.setTileWidth(ProcessConfiguration.getInstance().getTileWidth());

layout.setTileHeight(ProcessConfiguration.getInstance().getTileWidth());
layout.setColorModel(cm);
layout.setSampleModel(cm.createCompatibleSampleModel(width, height));
hints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout);

And "opacityToAlpha", which normalizes 0-100 opacity to 0-255 alpha with the
following code :
public static Byte opacityToAlpha(int opacity) {
int value = (opacity*255)/100;
return new Byte((byte)value);
}

The problem is that even if opacity is 100 (ie the alpha images are constant
images with pixel values set to 255) I still see all the images ! I just
want to see the first image in that case !

Thanks in advance :)

Stephane

-----Message d'origine-----
De : Stéphane Wasserhardt [mailto:stephane.wasserhardt@magellium.fr]
Envoyé : mercredi 1 juin 2005 08:39
À : interest@jai.dev.java.net
Objet : RE: [JAI] Composite again

Errrr ... ***slapping himself*** ... you're right ... I should have taken a
look at it, but I thought the Mosaic operation didn't take alpha layers into
account.

Thank you very much ! I think I'll get some better performance now :D

BTW, there was a mistake in my previous post : I forgot to tell that you
must overlay the result of the "composite" operation over the result of the
previous iteration. But nobody matters anyway, as everybody (except me 1
minute ago) knew that there is a "mosaic" operator ...

Stephane

-----Message d'origine-----
De : Brian Burkhalter [mailto:Brian.Burkhalter@Sun.COM]
Envoyé : mercredi 1 juin 2005 03:01
À : Java Advanced Imaging discussion list;
stephane.wasserhardt@magellium.fr
Objet : RE: [JAI] Composite again

Is this process something which could be accomplished using the "Mosaic"
operation?

http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/ja...
media/jai/operator/MosaicDescriptor.html

Brian

On Tue, 31 May 2005, Stéphane Wasserhardt wrote:

> Thanks a lot Aastha !
>
> I changed your idea a bit because I must composite multiple overlapping
> images. So there's the complete process :
> I create an empty TiledImage (called "nextImage"), which size is the
> bounding box of the union of all images to be combined. Then I use "set"
to
> put the first image.
> I do the same with another TiledImage which will be used as alpha layer
> (called "nextAlpha") : this time, I first use the "constant" operator, to
> fill my image with zeros. Then I also use "set" to put the alpha layer of
> the first image on it.
> Now I can composite "nextImage" and its alpha layer "nextAlpha" with the
> second image (and its alpha layer).
> After that, I use the "bandselect" operator to re-build "nextImage" and
> "nextAlpha" from the result.
> Finally, I can re-iterate "composite" and "bandselect" operations with the
> next images, until I get the final "nextImage" !
>
> I detailled the process because I think this is a basic feature used in
many
> imagery tools (Gimp, PhotoShop, etc ..) and many ppl may need to implement
> it.
> If someone need the source code ... Just let me know !
>
> Stephane
>
> -----Message d'origine-----
> De : Aastha Bhardwaj [mailto:Aastha.Bhardwaj@Sun.COM]
> Envoyé : jeudi 26 mai 2005 00:33
> À : interest@jai.dev.java.net
> Objet : Re: [JAI] Composite again
>
>
> Hi Stéphane,
>
> To get what you need, you should create a TiledImage with the dimensions
> you would get with the two images overlapping, i.e. dimensions big
> enough that both images would fit into the TiledImage. You can then set
> the first image on the TiledImage, using the TiledImage.set() method,
> you can then set the second image on the TiledImage, again using
> TiledImage.set(). Finally you can use the JAI "composite" operation on
> the two original images, and then set the resultant image on the
> TiledImage. This should give you the expected result.
>
> Aastha
>
> ---------------------
> Aastha Bhardwaj
> Java Advanced Imaging
> Sun Microsystems
>
> >
> > I'm using the JAI 'composite' operation on images which do not have the
> same
> > dimensions. I wondered how does JAI handles this, and then I found the
> > following thread in the mailing list archives :
> >
> >
>
http://archives.java.sun.com/cgi-bin/wa?A2=ind9910&L=jai-interest&D=0&I=...
> > =474
> >
> > It is said that JAI's default behaviour is to consider only the
> intersection
> > between images. It is also said that if you want to composite a small
> image
> > onto a larger one, you should first perform the composite operation, and
> > then overlay the result onto the largest of the two input images. This
is
> OK
> > when the largest of the two images completely contains the bounds of the
> > smaller one. But now I need to do the same with two images that only
have
> a
> > small overlapped area.
> > Does anyone know a efficient way to do this ?
> >
> > Thanks a lot !
> > Stephane W.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> > For additional commands, e-mail: interest-help@jai.dev.java.net
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>

----------------
Brian Burkhalter
Advanced Development, Graphics and Media
Software Chief Technology Office
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

Brian Burkhalter

Stephane,

Did you try setting the 'mosaicType' parameter to MOSAIC_TYPE_OVERLAY?

Brian

On Wed, 1 Jun 2005, Stéphane Wasserhardt wrote:

> I successfully changed my code to use the Mosaic operator, and it works
> well... at first sight. It seems that there's an odd behaviour :
> Even if all images in the sourceAlpha parameter of the mosaic are constant
> byte images with value 255, the result of the mosaic seems to be the
> averaging of all source images. What I need in this case is to only get the
> first image, because its alpha is "opaque" (value 255), and therefore it
> should hide the other images.
> I tried to change Transparency.OPAQUE to Transparency.TRANSLUCENT and to
> Transparency.BITMASK in the RenderingHints, but it didn't change anything
> ...
>
> If you need more info, here is how my app works :
>
> The user can open images, and for each of them, give an opacity value in the
> range 0-100. I use a class "StackImage" which wraps the openned images
> (RenderedImage) and contains the opacity value (so I have two methods :
> stackImage.getImage() and stackImage.getOpacity(), plus another usefull
> method : stackImage.getBounds() ).
> The program then draws the "mosaic" of all images, with the following code :
>
> public static RenderedOp mosaic(StackImage[] stack) {
> ImageLayout layout = new ImageLayout();
> layout.setColorModel(
> new ComponentColorModel(
> ColorSpace.getInstance(ColorSpace.CS_sRGB),
> new int[] {8, 8, 8},
> false, false,
> Transparency.OPAQUE,
> DataBuffer.TYPE_BYTE
> )
> );
> RenderingHints hints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout);
>
> java.awt.Rectangle aExt;
> RenderedOp[] alphaLayers = new RenderedOp[stack.length];
> ParameterBlock pb = new ParameterBlock();
> for (int i = 0; i < stack.length; i++) {
> pb.addSource(stack[i].getImage());
> aExt = stack[i].getBounds();
> alphaLayers[i] = createConstant(
> new Byte[] {opacityToAlpha(stack[i].getOpacity())},
> aExt.x, aExt.y,
> aExt.width, aExt.height
> );
> }
> pb.add(MosaicDescriptor.MOSAIC_TYPE_BLEND);
> pb.add(alphaLayers);
>
> return JAI.create("mosaic", pb, hints); //$NON-NLS-1$
> }
>
> I use there two methods :
> First, "createConstant", which uses the "constant" operator with the
> following rendering hints :
> RenderingHints hints;
> ImageLayout layout = new ImageLayout();
> layout.setMinX(x);
> layout.setMinY(y);
> layout.setTileGridXOffset(0);
> layout.setTileGridYOffset(0);
>
> layout.setTileWidth(ProcessConfiguration.getInstance().getTileWidth());
>
> layout.setTileHeight(ProcessConfiguration.getInstance().getTileWidth());
> layout.setColorModel(cm);
> layout.setSampleModel(cm.createCompatibleSampleModel(width, height));
> hints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout);
>
> And "opacityToAlpha", which normalizes 0-100 opacity to 0-255 alpha with the
> following code :
> public static Byte opacityToAlpha(int opacity) {
> int value = (opacity*255)/100;
> return new Byte((byte)value);
> }
>
> The problem is that even if opacity is 100 (ie the alpha images are constant
> images with pixel values set to 255) I still see all the images ! I just
> want to see the first image in that case !
>
> Thanks in advance :)
>
> Stephane
>
> -----Message d'origine-----
> De : Stéphane Wasserhardt [mailto:stephane.wasserhardt@magellium.fr]
> Envoyé : mercredi 1 juin 2005 08:39
> À : interest@jai.dev.java.net
> Objet : RE: [JAI] Composite again
>
>
> Errrr ... ***slapping himself*** ... you're right ... I should have taken a
> look at it, but I thought the Mosaic operation didn't take alpha layers into
> account.
>
> Thank you very much ! I think I'll get some better performance now :D
>
> BTW, there was a mistake in my previous post : I forgot to tell that you
> must overlay the result of the "composite" operation over the result of the
> previous iteration. But nobody matters anyway, as everybody (except me 1
> minute ago) knew that there is a "mosaic" operator ...
>
> Stephane
>
> -----Message d'origine-----
> De : Brian Burkhalter [mailto:Brian.Burkhalter@Sun.COM]
> Envoyé : mercredi 1 juin 2005 03:01
> À : Java Advanced Imaging discussion list;
> stephane.wasserhardt@magellium.fr
> Objet : RE: [JAI] Composite again
>
>
> Is this process something which could be accomplished using the "Mosaic"
> operation?
>
> http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/ja...
> media/jai/operator/MosaicDescriptor.html
>
> Brian
>
> On Tue, 31 May 2005, Stéphane Wasserhardt wrote:
>
> > Thanks a lot Aastha !
> >
> > I changed your idea a bit because I must composite multiple overlapping
> > images. So there's the complete process :
> > I create an empty TiledImage (called "nextImage"), which size is the
> > bounding box of the union of all images to be combined. Then I use "set"
> to
> > put the first image.
> > I do the same with another TiledImage which will be used as alpha layer
> > (called "nextAlpha") : this time, I first use the "constant" operator, to
> > fill my image with zeros. Then I also use "set" to put the alpha layer of
> > the first image on it.
> > Now I can composite "nextImage" and its alpha layer "nextAlpha" with the
> > second image (and its alpha layer).
> > After that, I use the "bandselect" operator to re-build "nextImage" and
> > "nextAlpha" from the result.
> > Finally, I can re-iterate "composite" and "bandselect" operations with the
> > next images, until I get the final "nextImage" !
> >
> > I detailled the process because I think this is a basic feature used in
> many
> > imagery tools (Gimp, PhotoShop, etc ..) and many ppl may need to implement
> > it.
> > If someone need the source code ... Just let me know !
> >
> > Stephane
> >
> > -----Message d'origine-----
> > De : Aastha Bhardwaj [mailto:Aastha.Bhardwaj@Sun.COM]
> > Envoyé : jeudi 26 mai 2005 00:33
> > À : interest@jai.dev.java.net
> > Objet : Re: [JAI] Composite again
> >
> >
> > Hi Stéphane,
> >
> > To get what you need, you should create a TiledImage with the dimensions
> > you would get with the two images overlapping, i.e. dimensions big
> > enough that both images would fit into the TiledImage. You can then set
> > the first image on the TiledImage, using the TiledImage.set() method,
> > you can then set the second image on the TiledImage, again using
> > TiledImage.set(). Finally you can use the JAI "composite" operation on
> > the two original images, and then set the resultant image on the
> > TiledImage. This should give you the expected result.
> >
> > Aastha
> >
> > ---------------------
> > Aastha Bhardwaj
> > Java Advanced Imaging
> > Sun Microsystems
> >
> > >
> > > I'm using the JAI 'composite' operation on images which do not have the
> > same
> > > dimensions. I wondered how does JAI handles this, and then I found the
> > > following thread in the mailing list archives :
> > >
> > >
> >
> http://archives.java.sun.com/cgi-bin/wa?A2=ind9910&L=jai-interest&D=0&I=...
> > > =474
> > >
> > > It is said that JAI's default behaviour is to consider only the
> > intersection
> > > between images. It is also said that if you want to composite a small
> > image
> > > onto a larger one, you should first perform the composite operation, and
> > > then overlay the result onto the largest of the two input images. This
> is
> > OK
> > > when the largest of the two images completely contains the bounds of the
> > > smaller one. But now I need to do the same with two images that only
> have
> > a
> > > small overlapped area.
> > > Does anyone know a efficient way to do this ?
> > >
> > > Thanks a lot !
> > > Stephane W.
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> > > For additional commands, e-mail: interest-help@jai.dev.java.net
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> > For additional commands, e-mail: interest-help@jai.dev.java.net
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> > For additional commands, e-mail: interest-help@jai.dev.java.net
> >
> >
>
> ----------------
> Brian Burkhalter
> Advanced Development, Graphics and Media
> Software Chief Technology Office
> Sun Microsystems, Inc.
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> This email message is for the sole use of the intended recipient(s)
> and may contain confidential and privileged information. Any
> unauthorized review, use, disclosure or distribution is prohibited.
> If you are not the intended recipient, please contact the sender by
> reply email and destroy all copies of the original message.
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>

----------------
Brian Burkhalter
Advanced Development, Graphics and Media
Software Chief Technology Office
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

Stéphane Wasserhardt

Brian,

The MOSAIC_TYPE_OVERLAY doesn't take the sourceAlpha array into account, and
I need it !
I think a good solution for my problem is to try applying alpha values on
the images before doing a mosaic of type "overlay". That's what I'll try now
...
If it doesn't work, I found another solution which might work : the awt
"AlphaComposite" class. But it isn't a JAI class, and I fear that it could
slow down my process, as it probably won't take advantage of JAI tiling ...
In this case I'll have some work to do in order to optimize it..

Stephane

-----Message d'origine-----
De : Brian Burkhalter [mailto:Brian.Burkhalter@Sun.COM]
Envoyé : mercredi 1 juin 2005 21:03
À : interest@jai.dev.java.net
Objet : RE: [JAI] Mosaic now

Stephane,

Did you try setting the 'mosaicType' parameter to MOSAIC_TYPE_OVERLAY?

Brian

On Wed, 1 Jun 2005, Stéphane Wasserhardt wrote:

> I successfully changed my code to use the Mosaic operator, and it works
> well... at first sight. It seems that there's an odd behaviour :
> Even if all images in the sourceAlpha parameter of the mosaic are constant
> byte images with value 255, the result of the mosaic seems to be the
> averaging of all source images. What I need in this case is to only get
the
> first image, because its alpha is "opaque" (value 255), and therefore it
> should hide the other images.
> I tried to change Transparency.OPAQUE to Transparency.TRANSLUCENT and to
> Transparency.BITMASK in the RenderingHints, but it didn't change anything
> ...
>
> If you need more info, here is how my app works :
>
> The user can open images, and for each of them, give an opacity value in
the
> range 0-100. I use a class "StackImage" which wraps the openned images
> (RenderedImage) and contains the opacity value (so I have two methods :
> stackImage.getImage() and stackImage.getOpacity(), plus another usefull
> method : stackImage.getBounds() ).
> The program then draws the "mosaic" of all images, with the following code
:
>
> public static RenderedOp mosaic(StackImage[] stack) {
> ImageLayout layout = new ImageLayout();
> layout.setColorModel(
> new ComponentColorModel(
> ColorSpace.getInstance(ColorSpace.CS_sRGB),
> new int[] {8, 8, 8},
> false, false,
> Transparency.OPAQUE,
> DataBuffer.TYPE_BYTE
> )
> );
> RenderingHints hints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout);
>
> java.awt.Rectangle aExt;
> RenderedOp[] alphaLayers = new RenderedOp[stack.length];
> ParameterBlock pb = new ParameterBlock();
> for (int i = 0; i < stack.length; i++) {
> pb.addSource(stack[i].getImage());
> aExt = stack[i].getBounds();
> alphaLayers[i] = createConstant(
> new Byte[] {opacityToAlpha(stack[i].getOpacity())},
> aExt.x, aExt.y,
> aExt.width, aExt.height
> );
> }
> pb.add(MosaicDescriptor.MOSAIC_TYPE_BLEND);
> pb.add(alphaLayers);
>
> return JAI.create("mosaic", pb, hints); //$NON-NLS-1$
> }
>
> I use there two methods :
> First, "createConstant", which uses the "constant" operator with the
> following rendering hints :
> RenderingHints hints;
> ImageLayout layout = new ImageLayout();
> layout.setMinX(x);
> layout.setMinY(y);
> layout.setTileGridXOffset(0);
> layout.setTileGridYOffset(0);
>
> layout.setTileWidth(ProcessConfiguration.getInstance().getTileWidth());
>
> layout.setTileHeight(ProcessConfiguration.getInstance().getTileWidth());
> layout.setColorModel(cm);
> layout.setSampleModel(cm.createCompatibleSampleModel(width, height));
> hints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout);
>
> And "opacityToAlpha", which normalizes 0-100 opacity to 0-255 alpha with
the
> following code :
> public static Byte opacityToAlpha(int opacity) {
> int value = (opacity*255)/100;
> return new Byte((byte)value);
> }
>
> The problem is that even if opacity is 100 (ie the alpha images are
constant
> images with pixel values set to 255) I still see all the images ! I just
> want to see the first image in that case !
>
> Thanks in advance :)
>
> Stephane
>
> -----Message d'origine-----
> De : Stéphane Wasserhardt [mailto:stephane.wasserhardt@magellium.fr]
> Envoyé : mercredi 1 juin 2005 08:39
> À : interest@jai.dev.java.net
> Objet : RE: [JAI] Composite again
>
>
> Errrr ... ***slapping himself*** ... you're right ... I should have taken
a
> look at it, but I thought the Mosaic operation didn't take alpha layers
into
> account.
>
> Thank you very much ! I think I'll get some better performance now :D
>
> BTW, there was a mistake in my previous post : I forgot to tell that you
> must overlay the result of the "composite" operation over the result of
the
> previous iteration. But nobody matters anyway, as everybody (except me 1
> minute ago) knew that there is a "mosaic" operator ...
>
> Stephane
>
> -----Message d'origine-----
> De : Brian Burkhalter [mailto:Brian.Burkhalter@Sun.COM]
> Envoyé : mercredi 1 juin 2005 03:01
> À : Java Advanced Imaging discussion list;
> stephane.wasserhardt@magellium.fr
> Objet : RE: [JAI] Composite again
>
>
> Is this process something which could be accomplished using the "Mosaic"
> operation?
>
>
http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/ja...
> media/jai/operator/MosaicDescriptor.html
>
> Brian
>
> On Tue, 31 May 2005, Stéphane Wasserhardt wrote:
>
> > Thanks a lot Aastha !
> >
> > I changed your idea a bit because I must composite multiple overlapping
> > images. So there's the complete process :
> > I create an empty TiledImage (called "nextImage"), which size is the
> > bounding box of the union of all images to be combined. Then I use "set"
> to
> > put the first image.
> > I do the same with another TiledImage which will be used as alpha layer
> > (called "nextAlpha") : this time, I first use the "constant" operator,
to
> > fill my image with zeros. Then I also use "set" to put the alpha layer
of
> > the first image on it.
> > Now I can composite "nextImage" and its alpha layer "nextAlpha" with the
> > second image (and its alpha layer).
> > After that, I use the "bandselect" operator to re-build "nextImage" and
> > "nextAlpha" from the result.
> > Finally, I can re-iterate "composite" and "bandselect" operations with
the
> > next images, until I get the final "nextImage" !
> >
> > I detailled the process because I think this is a basic feature used in
> many
> > imagery tools (Gimp, PhotoShop, etc ..) and many ppl may need to
implement
> > it.
> > If someone need the source code ... Just let me know !
> >
> > Stephane
> >
> > -----Message d'origine-----
> > De : Aastha Bhardwaj [mailto:Aastha.Bhardwaj@Sun.COM]
> > Envoyé : jeudi 26 mai 2005 00:33
> > À : interest@jai.dev.java.net
> > Objet : Re: [JAI] Composite again
> >
> >
> > Hi Stéphane,
> >
> > To get what you need, you should create a TiledImage with the dimensions
> > you would get with the two images overlapping, i.e. dimensions big
> > enough that both images would fit into the TiledImage. You can then set
> > the first image on the TiledImage, using the TiledImage.set() method,
> > you can then set the second image on the TiledImage, again using
> > TiledImage.set(). Finally you can use the JAI "composite" operation on
> > the two original images, and then set the resultant image on the
> > TiledImage. This should give you the expected result.
> >
> > Aastha
> >
> > ---------------------
> > Aastha Bhardwaj
> > Java Advanced Imaging
> > Sun Microsystems
> >
> > >
> > > I'm using the JAI 'composite' operation on images which do not have
the
> > same
> > > dimensions. I wondered how does JAI handles this, and then I found the
> > > following thread in the mailing list archives :
> > >
> > >
> >
>
http://archives.java.sun.com/cgi-bin/wa?A2=ind9910&L=jai-interest&D=0&I=...
> > > =474
> > >
> > > It is said that JAI's default behaviour is to consider only the
> > intersection
> > > between images. It is also said that if you want to composite a small
> > image
> > > onto a larger one, you should first perform the composite operation,
and
> > > then overlay the result onto the largest of the two input images. This
> is
> > OK
> > > when the largest of the two images completely contains the bounds of
the
> > > smaller one. But now I need to do the same with two images that only
> have
> > a
> > > small overlapped area.
> > > Does anyone know a efficient way to do this ?
> > >
> > > Thanks a lot !
> > > Stephane W.
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> > > For additional commands, e-mail: interest-help@jai.dev.java.net
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> > For additional commands, e-mail: interest-help@jai.dev.java.net
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> > For additional commands, e-mail: interest-help@jai.dev.java.net
> >
> >
>
> ----------------
> Brian Burkhalter
> Advanced Development, Graphics and Media
> Software Chief Technology Office
> Sun Microsystems, Inc.
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> This email message is for the sole use of the intended recipient(s)
> and may contain confidential and privileged information. Any
> unauthorized review, use, disclosure or distribution is prohibited.
> If you are not the intended recipient, please contact the sender by
> reply email and destroy all copies of the original message.
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>

----------------
Brian Burkhalter
Advanced Development, Graphics and Media
Software Chief Technology Office
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

Brian Burkhalter

When sourceAlpha is used with MOSAIC_TYPE_OVERLAY then the pixel at a given
point is equal to the corresponding pixel of the first source in the array
which has a non-zero alpha value at that position.

Brian

On Thu, 2 Jun 2005, Stéphane Wasserhardt wrote:

> The MOSAIC_TYPE_OVERLAY doesn't take the sourceAlpha array into account, and
> I need it !

----------------
Brian Burkhalter
Advanced Development, Graphics and Media
Software Chief Technology Office
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net