473,805 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 programmaticall y depending on what RGB
choice user makes.

Any ideas how?
Oct 26 '06 #1
4 5221
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 programmaticall y 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
5884
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 head against the screen, I've managed to get it to work... sort of. Right now, though, when I make multiple passes with my bluring ConvolveOp objects, I get progressively more and more black border around the image I am blurring. You can see...
3
8390
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 server. Someone done this before? kind regards Stijn
7
10852
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 tried to use the colormatrix and even down to the pixel using GetPixel and SetPixel in system.drawing, but I'm really not up on using gdi+ and haven't really gotten anywhere. I've seen some examples for VB6, but I need vb.net. I know that all...
1
2400
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 features -- not simply different colours, but styles and fonts too. I don't know whether this is the right place to ask this type of question, but...
1
2364
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 Image.I think I found the reason of getting error.But I am not able to solve it I am pasting the code which I wrote The reason I think is when I am extracting the RGB value from the image,R and G will be zero everytime.But I am getting the value of...
0
2884
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 below: chartGenerator.vb class: Imports System.Drawing.Imaging Public Class chartGenerator Private myImage As Bitmap
3
2128
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
6014
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 (converting) thing.... please help me out .. i just uploaded images so i guess it will be of no use for you people if i put my code here ...
2
4097
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 but cant seem to find out what the problem is. I think this could be fixed with a i.e hack??? please advise the problem of the overlapping image is occuring in imagerow2 div on line 56. please see my code below here is my html <!DOCTYPE...
0
10363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10109
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5544
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3847
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.