Color subtraction

  • Thread starter Thread starter paul
  • Start date Start date
P

paul

Hi,
I have two bitmaps that look the same, except in color. Is there a
simple way to "subtract" the color of one bitmap, pixel by pixel so
that only the difference in colour remains. For instance, if I take a
pixel at point (50,75), and find that the colours are FF00FF and FF0000
respectively, is there a way to determine that the residual colour is
0000FF ?

Thanks in advance!

Best wishes

Paul
 
Performing an XOR between the bitmaps should
give you the difference.
 
So, something like:

Bitmap3.SetPixel(50,75,
Bitmap1.GetPixel(50,75)^Bitmap2.GetPixel(50,75));

if I wanted to set the pixel color equal to this difference in a third
bitmap?
 
Hi,
I have two bitmaps that look the same, except in color. Is there a
simple way to "subtract" the color of one bitmap, pixel by pixel so
that only the difference in colour remains. For instance, if I take a
pixel at point (50,75), and find that the colours are FF00FF and FF0000
respectively, is there a way to determine that the residual colour is
0000FF ?

It's not immediately clear that the difference between two colours can
be usefully represented by a third colour, but yo umight like to try a
component-wise absolute difference. That is, extract the RGB components
of each input colour, find the differences r1-r2, g1-g2, b1-b2
(ignoring sign), and use those to construct the output colour. Not sure
how useful the output will be though - is the difference between bright
red FF0000 and orange FF8000 really best represented by deep green
008000? I guess it's your application :)
 
Hi,

(e-mail address removed) napisa?(a):
So, something like:

Bitmap3.SetPixel(50,75,
Bitmap1.GetPixel(50,75)^Bitmap2.GetPixel(50,75));

if I wanted to set the pixel color equal to this difference in a third
bitmap?

If you're going to do serious image processing then
you'll need to forget about GetPixel(...), SetPixel(...)
methods.
Look for BitmapData or more advanced classes for image
processing.

HTH
 
Marcin is spot on. Here's a good reference to help you get started. You will
need to use unsafe code to do it, but at least you're using the right
language for it!

http://www.bobpowell.net/lockingbits.htm

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
We got a sick zebra a hat,
you ultimate tuna.
 
Thanks mates, I'll give them a try,

By the way, how would I go about separating an image into its chroma
(colour) and luma (brightness) components?
 
Hi,

Kevin Spencer napisa³(a):
Marcin is spot on. Here's a good reference to help you get started. You will
need to use unsafe code to do it, but at least you're using the right
language for it!

http://www.bobpowell.net/lockingbits.htm

I'm familiar with image processing ;-)

There is a hint to pass by the *unsafe* mode:
"Use the Buffer.BlockCopy(...)"

with regards
 
(e-mail address removed) napisa?(a):
Thanks mates, I'll give them a try,

By the way, how would I go about separating an image into its chroma
(colour) and luma (brightness) components?

chroma:
Color.GetHue(...) or Color.GetSaturation(...)

brightness:
Color.GetBrightness(...) ;-)

Returned values are a type of float with range <0; 1> for
saturation and brightness, and <0;360> for hue.

This works as a standard HSB color representation.

HTH
 
Marcin Grzêbski napisa³(a):
There is a hint to pass by the *unsafe* mode:
"Use the Buffer.BlockCopy(...)"

my error :-( it should be:
"Use the System.Runtime.InteropServices.Marshal.Copy(...)"
 
Hi Paul,

There is a tutorial on this as well as several other filtering techniques on
the same site. It's Bob Powell's "GDI+ FAQ." -

http://www.bobpowell.net/faqmain.htm

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
We got a sick zebra a hat,
you ultimate tuna.
 

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

Back
Top