convert grayscale images to color

S

sea

I have binary images in grayscale (shades of black and white) -- is
there some way I can convert this to a specific color? Thank you very
much for any help with this!
 
T

Troy Kinsella

sea said:
I have binary images in grayscale (shades of black and white) -- is
there some way I can convert this to a specific color? Thank you very
much for any help with this!

As in a monochromatic image?
 
A

Andrew Thompson

Troy said:
As in a monochromatic image?

As I understand the OP, they want to
convert from shades of gray (I think that is
what 'shades of black and white' translates to)
to shades of another color, as if you were
looking at it through 'rose colored glasses' or
such.

[ And as I understand the question..
Yes, I would guess Java can do it,
it does not seem to be very complicated. ]
 
N

nos

Andrew Thompson said:
Troy said:
As in a monochromatic image?

As I understand the OP, they want to
convert from shades of gray (I think that is
what 'shades of black and white' translates to)
to shades of another color, as if you were
looking at it through 'rose colored glasses' or
such.

[ And as I understand the question..
Yes, I would guess Java can do it,
it does not seem to be very complicated. ]

--
Andrew Thompson
* http://www.PhySci.org/ Open-source software suite
* http://www.PhySci.org/codes/ Web & IT Help
* http://www.1point1C.org/ Science & Technology

Gray (grey, what's the diff?) is probably represented
in 8 bits. Color is a triplet of 3 8-bit values. So to
convert from shades of Gray to say shades of Red:

red values = gray values
green values = 0
blue values = 0
 
S

sea

Thank you very much for the info that Java can do this -- but how? I
searched all over and could not find anything helpful -- anyone knows
any examples on the web about this? Thanks a bunch!


Andrew Thompson said:
Troy said:
As in a monochromatic image?

As I understand the OP, they want to
convert from shades of gray (I think that is
what 'shades of black and white' translates to)
to shades of another color, as if you were
looking at it through 'rose colored glasses' or
such.

[ And as I understand the question..
Yes, I would guess Java can do it,
it does not seem to be very complicated. ]
 
A

Andrew Thompson

sea said:
"Andrew Thompson" ... .... ....
Thank you very much for the info that Java can do this -- but how? I
searched all over and could not find anything helpful -- anyone knows
any examples on the web about this? Thanks a bunch!

[please do not top post, sea]

I have never done it, but if you can
get and set the values of the red green
and blue components of an image, you
get them from the grayscale image, do
a simple mathematical calculation and
set the RGB components accordingly.

So, q. 1. Do you know how to get at
the actual image data?
 
G

Guest

I have binary images in grayscale (shades of black and white) -- is there
some way I can convert this to a specific color? Thank you very much for
any help with this!

Use an ImageFilter!

Aloha,
La'ie Techie
 
B

Boudewijn Dijkstra

sea said:
I have binary images in grayscale (shades of black and white) -- is
there some way I can convert this to a specific color? Thank you very
much for any help with this!

I am assuming you want to convert the file "testgrey.jpg" to the file
"testcolor.jpg". Before we start:
import java.awt.*;
import java.awt.image.*;
import java.io.*;

First, get an ImageFilter, as La'ie Techie suggested. You probably want
something like this:

public class MixerFilter extends RGBImageFilter
{
float ratioR, ratioG, ratioB;

public BlendingFilter(Color color)
{
ratioR = color.getRed() / 255f;
ratioG = color.getGreen() / 255f;
ratioB = color.getBlue() / 255f;
}

public int filterRGB(int x, int y, int rgb)
{
int
b = rgb & 0xff,
g = (rgb >>= 8) & 0xff,
r = (rgb >>= 8) & 0xff;
r = (int) Math.round(r * ratioR);
g = (int) Math.round(g * ratioG);
b = (int) Math.round(b * ratioB);
if (r < 0) r = 0; else if (r > 255) r = 255;
if (g < 0) g = 0; else if (g > 255) g = 255;
if (b < 0) b = 0; else if (b > 255) b = 255;
return (rgb & 0xff000000) + ((((r << 8) + g) << 8) + b);
}
}

Create an instance of this filter by supplying your 'specific color' to the
constructor. Name it "myFilter".

Then, create an instance of the source Image:
Image imSrc = Toolkit.getDefaultToolkit().createImage("testgrey.jpg");

Now, filter the Image:
Image imDst = Toolkit.getDefaultToolkit().createImage(new
FilteredImageSource(imSrc.getSource(), myFilter));

Normally, a RenderedImage is returned. Writing an Image can then be very
straightforward:
ImageIO.write((RenderedImage)imDst, "JPG", new File("testcolor.jpg"));

Now you have your filtered image! Enjoy!

Once you get the hang of it, you can create weird filters and then watch the
result on some images!
 
Joined
Dec 13, 2007
Messages
1
Reaction score
0
Gray (grey, what's the diff?) is probably represented
in 8 bits. Color is a triplet of 3 8-bit values. So to
convert from shades of Gray to say shades of Red:

red values = gray values
green values = 0
blue values = 0

Well, every shade of grey represents a different color than another shade.
The question is not really how to do that but rather is it actually possible? I'd say "Yes, It is possible"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top