473,231 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

How do I add colorize a black & white image?

Let's say I have an image which is monochrome with areas of white, black and
shades of gray. Now I want to turn all the white parts into some RGB color
but it also needs to be darkened by the gray areas for the same color.

Like say it's an image of a sphere, it is white in the part it is under the
light but then as you get away from the light source it becomes darker and
darker gray. Now I want to take this image and apply just one RGB color to
it, so it becomes say a red sohere, blue one, whatever. So that parts that
were whitest and purest red, and then the red gets darker where the grays are
darker.

It's easy to do this manually in something like photoshop, but I need to
make a a windows app that does this programmatically depending on what RGB
choice user makes.

Any ideas how?
Oct 26 '06 #1
4 5148
If you want to do any kind of image processing in .NET and you don't
want to wait a year for an operation to complete, you need to be
working in "unsafe" code. First take some time and look into the
"LockBits" method (I think it's in user32.dll). Using this method you
can move pixel by pixel through your image and set it's RGB values.

A good place to start when researching anything visual in Windows is
www.bobpowell.net, in your case I would focus on his GDI+ FAQ
(http://www.bobpowell.net/faqmain.htm). There you can read about
LockBits and how to use it as well as find some sample code. If you're
still having trouble after that post some of the code you're using.
Good luck!

MrNobody wrote:
Let's say I have an image which is monochrome with areas of white, black and
shades of gray. Now I want to turn all the white parts into some RGB color
but it also needs to be darkened by the gray areas for the same color.

Like say it's an image of a sphere, it is white in the part it is under the
light but then as you get away from the light source it becomes darker and
darker gray. Now I want to take this image and apply just one RGB color to
it, so it becomes say a red sohere, blue one, whatever. So that parts that
were whitest and purest red, and then the red gets darker where the grays are
darker.

It's easy to do this manually in something like photoshop, but I need to
make a a windows app that does this programmatically depending on what RGB
choice user makes.

Any ideas how?
Oct 26 '06 #2
Thanks justin that is a very helpful link.

Would you happen to know where I can go to form some basic color type
questions?

Like what exactly would I have to do to give each pixel a red color but
darkened/lightened depending on how gray it is? Wouldn't I have to change the
RGB value given depending on the shade of gray the pixel is, so the end
result is not just pure saturated color?
Oct 26 '06 #3

MrNobody wrote:
Thanks justin that is a very helpful link.

Would you happen to know where I can go to form some basic color type
questions?

Like what exactly would I have to do to give each pixel a red color but
darkened/lightened depending on how gray it is? Wouldn't I have to change the
RGB value given depending on the shade of gray the pixel is, so the end
result is not just pure saturated color?
Exactly right.

If your destination hue was red, green, or blue, it would be easy: just
keep the R, G, or B value for the color you want, and set the other two
to zero. But it probably won't be red, green, or blue that you want.
You'll have to start with an HSV color value, adjusting the color
percentage that you want, and convert back to RGB.

You can learn a lot about color on wikipedia.
http://en.wikipedia.org/wiki/HSV_color_space

There are commandline utilities, and commercial libraries, that do the
work for you. Try out graphicsmagick: http://www.graphicsmagick.org

As an example, with graphicsmagic, converting from grayscale to
shades-of-blue would be
gm convert input.png -colorize 255/255/0 output.png

Oct 26 '06 #4
If all you are trying to do is apply a red, blue, or green hue that
matches how much grey is in the image that is not too difficult. First
you need to determine what format your gray image is in. This is
because different image formats have different sizes. The BitmapData
class will have the necessary information here. Once you have a
numerical value for how much gray there is you can set the correct
color to that amount. To do that you do the following.

- create an empty Bitmap the same size as your gray one.
- iterate through your gray image using your BitmapData object and get
gray value.
- create a pixel in your empty Bitmap with the same amount of whatever
color you want to set as a hue. The byte you add the value to for the
color is reached with your BitmapData object, but how you find the
right byte depends on the image format you use.
- when you're done save your new Bitmap.

Now, this will only work to add one hue to the image, so you'll go from
a gray image to a red image, or a blue image, etc. Hope that helps,
good luck.

MrNobody wrote:
Thanks justin that is a very helpful link.

Would you happen to know where I can go to form some basic color type
questions?

Like what exactly would I have to do to give each pixel a red color but
darkened/lightened depending on how gray it is? Wouldn't I have to change the
RGB value given depending on the shade of gray the pixel is, so the end
result is not just pure saturated color?
Oct 27 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Michael Allen | last post by:
Hi all you Java 2D gurus out there. I wonder if you might be able to help me. I've been dipping my toe into the world of Gaussian blurring and with the help of a few articles and some bashing my...
3
by: Stijn Goris | last post by:
Hi all, I want to make a coloured picture black and white when a user moves its mouse pointer over it. I just don't want to store a coloured an black and white (grayscaled) version on the...
7
by: marfi95 | last post by:
I'm trying to implement some code in vb.net to allow the user to adjust the brightness or contrast on an image (through the use of a slider) that is already black & white in the bitmap. I have...
1
by: Sandy | last post by:
Dear Pythonic People, I recently discovered SciTE (1.68) as a programming editor, and I find it just beautiful. Small, fast, elegant and beautiful. I particularly like syntax highlighting...
1
by: retheeshnewage | last post by:
I have a doubt in php.I wrote a php program to convert colour Images to balck & white.It is working fine with JPEG files and PNG files.When it comes to GIF files I am not getting the colour...
0
by: benfly08 | last post by:
Hi, guys. I have a program to draw bar/pie chart based on the data i hard coded in it. However, my image comes with "BLACK" background color. I don't know how to fix this. The code snippet is...
3
by: hambone2123 | last post by:
hi, im using windows vista and i tried burning a movie to dvd and when i play the dvd in my dvd player its in black and white and the screen jumps up and down what should i do
3
by: Muddasir | last post by:
hi all i need to upload an image and if that image is coloured i need to convert it to black and white image ... till now i only uploaded images ... simple.. have no idea how to do this...
2
by: studentofknowledge | last post by:
For some unknown reason ie is placing images I have in a div in a weird way. One image is overlapping another but this problem is not occuring in mozilla. I have looked at my code over and over again...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.