Skip to main content

Urgent!!!!!How to composit three grayscale images to a new RGB image

8 replies [Last post]
leizhuhong
Offline
Joined: 2006-08-10

hi ,all!

i am a newbie here.

i want to make three different channel grayscale (8 bit)images(same size) to be a new RGB(24bit)image.

i need the help,and if you can tell me in detail ,i will be grateful. thanx!

have a try,but failed
the code is below,i need helpppppppppppppp

public class RGBPanel extends JPanel{
// public Image []image=new Image[3];

BufferedImage []img=new BufferedImage[3];
Image RGBimg=null;
int imageWidth;
int imageHeight;

public RGBPanel() {
init();
}

public void paintComponent(Graphics g)
{
super.paintComponent(g);
for(int i=0;i<3;i++)
if(img==null)
return;

g.drawImage(RGBimg,0,0,this);

}
public void init() {
try{
img[0]=ImageIO.read(new File ("E:\\sample\\band1.bmp"));
img[1]=ImageIO.read(new File ("E:\\sample\\band3.bmp"));
img[2]=ImageIO.read(new File ("E:\\sample\\band5.bmp"));

imageHeight=img[0].getHeight(null);
imageWidth=img[0].getWidth(null);

BufferedImage image=new BufferedImage(imageWidth,imageHeight,BufferedImage.TYPE_INT_ARGB);

for(int i=0;i>16);
int g=0Xff&(pixel[1]>>8);
int b=0Xff&(pixel[2]);
int despixel;
despixel=(255<<24)|(r<<16)|(g<<8)|b;
image.setRGB(i,j,despixel);
}
RGBimg=(Image)image;

}
catch(IOException e){
e.printStackTrace();
}
}
}

Reply viewing options

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

> Oh,omg!
> I really feel shame and sorry .
>
I must admit that messages with subjects Urgent and lots of !!! turn me
off ;-)

Anyway check jaistuff.dev.java.net , there are examples that could help.

Rafael

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

leizhuhong
Offline
Joined: 2006-08-10

Thank u very much for offering the URL of s BandMergeDescriptor,which makes me know there is a function to handle this problem.However,as you know ,i am really a newbie in JAVA and JAI field,which makes me feel puzzled about [b]BandMergeDescriptor[/b],can you give me much more hint.i will be appreiciate about your mercy.Really really than you !!

Message was edited by: leizhuhong

robert engels

Why don't you ask your professor for help. If you don't know Java or
JAI what are you doing on a developer's forum....

On Aug 22, 2006, at 8:21 PM, jai-imageio@javadesktop.org wrote:

> Thank u very much for offering the URL of s
> BandMergeDescriptor,which makes me know there is a function to
> handle this problem.However,as you know ,i am really a newbie in
> JAVA and JAI field,which makes me feel puzzled aobue [b]
> BandMergeDescriptor[/b],can you give me much more hint.i will be
> appreiciate about your mercy.Really really than you !!
> [Message sent by forum member 'leizhuhong' (leizhuhong)]
>
> http://forums.java.net/jive/thread.jspa?messageID=145901
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-
> imageio.dev.java.net
>

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

leizhuhong
Offline
Joined: 2006-08-10

Oh,omg!
I really feel shame and sorry .
i just believe there are most JAI Users here,and this forum can help me to solve the trouble.Thank you

robert engels

There is no reason to feel shame or sorry.

The JAI users forum is just probably a better place to start in order
to get assistance.

On Aug 22, 2006, at 8:49 PM, jai-imageio@javadesktop.org wrote:

> Oh,omg!
> I really feel shame and sorry .
> i just believe there are most JAI Users here,and this forum can
> help me to solve the trouble.Thank you
> [Message sent by forum member 'leizhuhong' (leizhuhong)]
>
> http://forums.java.net/jive/thread.jspa?messageID=145938
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-
> imageio.dev.java.net
>

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

leizhuhong
Offline
Joined: 2006-08-10

Thanx Brian Burkhalter and Rober engels.

I follow your advices and make a small test.

Successful!

below is my code ,however it is just a test

import java.awt.image.RenderedImage;
import java.io.IOException;

import javax.media.jai.JAI;
import javax.media.jai.RenderedOp;
import javax.media.jai.operator.BandMergeDescriptor;

import com.sun.media.jai.codec.FileSeekableStream;

/*
* Created on 2006-8-23
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/

/**
* @author hgxida
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class BandMerge {

/**
*
*/
public BandMerge() {
// super();
// TODO Auto-generated constructor stub
FileSeekableStream stream1=null;
FileSeekableStream stream2=null;
FileSeekableStream stream3=null;

try{
stream1=new FileSeekableStream("e:\\sample\\band1.bmp");
stream2=new FileSeekableStream("e:\\sample\\band3.bmp");
stream3=new FileSeekableStream("e:\\sample\\band4.bmp");

}
catch(IOException e){e.printStackTrace();System.exit(0);

}

RenderedImage SourceImage1=JAI.create("Stream",stream3);
RenderedImage SourceImage2=JAI.create("Stream",stream2);
RenderedImage SourceImage3=JAI.create("Stream",stream1);

RenderedOp desImg;
desImg=BandMergeDescriptor.create(SourceImage1,SourceImage2,null);

desImg=BandMergeDescriptor.create(desImg,SourceImage3,null);

try{
JAI.create("filestore",desImg,"e:\\desimg.bmp","bmp",null);

}catch(Exception e){
System.out.println("Wrong!");
System.exit(-1);
}

}

public static void main(String[] args) {
new BandMerge();
}
}

Brian Burkhalter

If you use the JAI.create(ParameterBlock,RenderingHints) approach you can do
this in a single step

RenderedOp dest = JAI.create("BandMerge", pb, null);

Brian

On Tue, 22 Aug 2006, jai-imageio@javadesktop.org wrote:

> Thanx Brian Burkhalter and Rober engels.
>
> I follow your advices and make a small test.
>
> Successful!
>
> below is my code ,however it is just a test
>
> import java.awt.image.RenderedImage;
> import java.io.IOException;
>
> import javax.media.jai.JAI;
> import javax.media.jai.RenderedOp;
> import javax.media.jai.operator.BandMergeDescriptor;
>
> import com.sun.media.jai.codec.FileSeekableStream;
>
> /*
> * Created on 2006-8-23
> *
> * TODO To change the template for this generated file go to
> * Window - Preferences - Java - Code Style - Code Templates
> */
>
> /**
> * @author hgxida
> *
> * TODO To change the template for this generated type comment go to
> * Window - Preferences - Java - Code Style - Code Templates
> */
> public class BandMerge {
>
> /**
> *
> */
> public BandMerge() {
> // super();
> // TODO Auto-generated constructor stub
> FileSeekableStream stream1=null;
> FileSeekableStream stream2=null;
> FileSeekableStream stream3=null;
>
> try{
> stream1=new FileSeekableStream("e:\\sample\\band1.bmp");
> stream2=new FileSeekableStream("e:\\sample\\band3.bmp");
> stream3=new FileSeekableStream("e:\\sample\\band4.bmp");
>
> }
> catch(IOException e){e.printStackTrace();System.exit(0);
>
> }
>
> RenderedImage SourceImage1=JAI.create("Stream",stream3);
> RenderedImage SourceImage2=JAI.create("Stream",stream2);
> RenderedImage SourceImage3=JAI.create("Stream",stream1);
>
>
> RenderedOp desImg;
> desImg=BandMergeDescriptor.create(SourceImage1,SourceImage2,null);
>
> desImg=BandMergeDescriptor.create(desImg,SourceImage3,null);
>
> try{
> JAI.create("filestore",desImg,"e:\\desimg.bmp","bmp",null);
>
> }catch(Exception e){
> System.out.println("Wrong!");
> System.exit(-1);
> }
>
> }
>
> public static void main(String[] args) {
> new BandMerge();
> }
> }
> [Message sent by forum member 'leizhuhong' (leizhuhong)]
>
> http://forums.java.net/jive/thread.jspa?messageID=145956
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-imageio.dev.java.net
>
>

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
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-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net

Brian Burkhalter

http://download.java.net/media/jai/javadoc/1.1.3-beta/javax/media/jai/op...

On Tue, 22 Aug 2006, jai-imageio@javadesktop.org wrote:

> hi ,all!
>
> i am a newbie here.
>
> i want to make three different channel grayscale (8 bit)images(same size) to be a new RGB(24bit)image.
>
> i need the help,and if you can tell me in detail ,i will be grateful. thanx!
>
>
> have a try,but failed
> the code is below,i need helpppppppppppppp
>
>
> public class RGBPanel extends JPanel{
> // public Image []image=new Image[3];
>
> BufferedImage []img=new BufferedImage[3];
> Image RGBimg=null;
> int imageWidth;
> int imageHeight;
>
> public RGBPanel() {
> init();
> }
>
>
>
> public void paintComponent(Graphics g)
> {
> super.paintComponent(g);
> for(int i=0;i<3;i++)
> if(img==null)
> return;
>
>
> g.drawImage(RGBimg,0,0,this);
>
> }
> public void init() {
> try{
> img[0]=ImageIO.read(new File ("E:\\sample\\band1.bmp"));
> img[1]=ImageIO.read(new File ("E:\\sample\\band3.bmp"));
> img[2]=ImageIO.read(new File ("E:\\sample\\band5.bmp"));
>
>
>
> imageHeight=img[0].getHeight(null);
> imageWidth=img[0].getWidth(null);
>
>
>
> BufferedImage image=new BufferedImage(imageWidth,imageHeight,BufferedImage.TYPE_INT_ARGB);
>
> for(int i=0;i > for(int j=0;j > { int []pixel=new int[3];
> for(int k=0;k<3;k++)
> pixel[k]=img[k].getRGB(i,j);
>
> int r=0Xff&(pixel[0]>>16);
> int g=0Xff&(pixel[1]>>8);
> int b=0Xff&(pixel[2]);
> int despixel;
> despixel=(255<<24)|(r<<16)|(g<<8)|b;
> image.setRGB(i,j,despixel);
> }
> RGBimg=(Image)image;
>
> }
> catch(IOException e){
> e.printStackTrace();
> }
> }
> }
> [Message sent by forum member 'leizhuhong' (leizhuhong)]
>
> http://forums.java.net/jive/thread.jspa?messageID=145869
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-imageio.dev.java.net
>
>

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
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-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net