Is there a way to convert an 8bit grayscale image to RGB?
I've read many examples that converts RGB to grayscale. But I still didn't manage to do it the other way round.
Hope I could get some help here.
Printable View
Is there a way to convert an 8bit grayscale image to RGB?
I've read many examples that converts RGB to grayscale. But I still didn't manage to do it the other way round.
Hope I could get some help here.
Oh, thanks for replying.
I thought it's possible cause my teacher said it can be done :confused:
Anyway, actually I just want to convert my grayscale level of 255 to red value. Still can't be done?
Sure, you're talking "pseudo colours" here. You can convert a gray level of 255 (pure white) to a triple (r,g,b) == (255, 0, 0) (pure red). But my previous remark still stands: a mapping f(r, g, b) to a one dimensional number in the range [0, 255] is a surjection and there is no way to go the other way.
kind regards,
Jos
Oh, now I get ya! :)
But, how do I convert them? I think I need some examples :confused:
Also, do I need to include anything at the header?
Thank You Jos.
You've been a great help!
You're welcome of course; another small tip: use a gray level larger than a value M and transform that to a colour (r, g, b) == (gray, 0, 0). Otherwise you only see a few red spots in your processed image. Experiment with the value of M for best results.
kind regards,
Jos
And I thought I got this prob solved but actually, no. The color didn't change at all :(
So, I'm stuck now :eek:
edit:
hmm, correct me if im wrong but this line:
"c= new Color(255, 0, 0); // red, completely opague"
will not display anything right?
so, ill have to do this?
ip.putPixel(_ ,_ , _);
oh wait, but how do I make use of the line above because previously, my values are in this form (a,b). Now since its (a,b,c). How do I go about it? =x
Yep, creating a new Color object doesn't change any image (and therefor any display) at all. Read the API documentation for the BufferedImage class. You create two of them, a gray scale image and an ARGB image (alpha, red, green, blue). You have to read the pixel values from your gray scale image, use my suggestion of a previous reply of mine and write a pixel in the ARGB image. When that's done you can draw the image or save it to disk (that's what the ImageIO class is for) or do anything you want with it.
kind regards,
Jos
is this the correct way to create the ARGB image?
From here on, how do I make use of the ARGB :confused:Code:BufferedImage bimage = new BufferedImage(X, Y, BufferedImage.TYPE_INT_RGB);
bimage = new BufferedImage(X, Y, BufferedImage.TYPE_INT_ARGB);
Oh, cause I thought I might use RGB instead og ARGB. I've read some but I'm not sure if what I'm reading is the correct one that might help me in this
The Sun Java Tutorials are always fine. Also, the Sun Java API Documentation is a must read. Bookmark those two links and read them before you attempt to program anything at all.
kind regards,
Jos
hello,
i was just searching for some ideas regarding grayscale to rgb images and manage to create this function, that creates an grayscale image (100px height) from an int (0-255) array :
dont know if thats what u looking for, but anyway..
regardsCode:public static BufferedImage grayLineToBufferedImage(int[] grayLine) {
BufferedImage image = new BufferedImage(grayLine.length, 100,
BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < grayLine.length; x++) {
for (int y = 0; y < image.getHeight(); y++) {
Color color = new Color(grayLine[x], grayLine[x], grayLine[x]);
image.setRGB(x, y, color.getRGB());
}
}
return image;
}
Sholzan
Rather obviously, it wasn't. Please don't post to old dead threads.Quote:
dont know if thats what u looking for
Closing.
db