471,319 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Color subtraction

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
--
http://www.paullee.com

Feb 15 '06 #1
10 5340

Performing an XOR between the bitmaps should
give you the difference.

Feb 15 '06 #2
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?

Feb 15 '06 #3

pa**@paullee.com wrote:
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 :)

--
Larry Lard
Replies to group please

Feb 15 '06 #4
Hi,

pa**@paullee.com 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 Grze;bski
mg*******@taxussi.no.com.spam.pl
Feb 15 '06 #5
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.
"Marcin Grze;bski" <mg*******@taxussi.no.com.spam.pl> wrote in message
news:ds**********@atlantis.news.tpi.pl...
Hi,

pa**@paullee.com 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 Grze;bski
mg*******@taxussi.no.com.spam.pl

Feb 15 '06 #6
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?

Feb 15 '06 #7
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
--
Marcin Grzębski
mg*******@taxussi.no.com.spam.pl
Feb 16 '06 #8
pa**@paullee.com 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 Grze;bski
mg*******@taxussi.no.com.spam.pl
Feb 16 '06 #9
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(...)"

Feb 16 '06 #10
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.
<pa**@paullee.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
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?

Feb 16 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by bruce.james.lee | last post: by
20 posts views Thread by junky_fellow | last post: by
reply views Thread by rosydwin | last post: by

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.