Results 1 to 16 of 16
Thread: Grayscale to RGB
- 01-27-2011, 07:31 AM #1
Member
- Join Date
- Jan 2011
- Posts
- 11
- Rep Power
- 0
- 01-27-2011, 07:33 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,377
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-27-2011, 04:08 PM #3
Member
- Join Date
- Jan 2011
- Posts
- 11
- Rep Power
- 0
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?
- 01-27-2011, 04:16 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,377
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-27-2011, 05:48 PM #5
Member
- Join Date
- Jan 2011
- Posts
- 11
- Rep Power
- 0
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?
- 01-27-2011, 05:54 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,377
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-27-2011, 06:12 PM #7
Member
- Join Date
- Jan 2011
- Posts
- 11
- Rep Power
- 0
Thank You Jos.
You've been a great help!
- 01-27-2011, 07:25 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,377
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-28-2011, 06:03 PM #9
Member
- Join Date
- Jan 2011
- Posts
- 11
- Rep Power
- 0
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? =xLast edited by unexpert; 01-28-2011 at 06:15 PM.
- 01-28-2011, 07:03 PM #10
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,377
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-29-2011, 06:02 AM #11
Member
- Join Date
- Jan 2011
- Posts
- 11
- Rep Power
- 0
is this the correct way to create the ARGB image?
From here on, how do I make use of the ARGB :confused:Java Code:BufferedImage bimage = new BufferedImage(X, Y, BufferedImage.TYPE_INT_RGB); bimage = new BufferedImage(X, Y, BufferedImage.TYPE_INT_ARGB);
- 01-29-2011, 07:41 AM #12
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,377
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-29-2011, 08:22 AM #13
Member
- Join Date
- Jan 2011
- Posts
- 11
- Rep Power
- 0
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
Last edited by unexpert; 01-29-2011 at 08:25 AM.
- 01-29-2011, 10:15 AM #14
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,377
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 08-09-2011, 10:46 PM #15
Member
- Join Date
- Aug 2011
- Posts
- 1
- Rep Power
- 0
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..
regardsJava Code: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
- 08-10-2011, 07:07 AM #16


LinkBack URL
About LinkBacks


Bookmarks