473,385 Members | 1,630 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,385 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 5526

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: chelleybabyger | last post by:
How do i handle a subtraction between 2 entries in a table? they each belong to 2 tables. my code is below. I wish to subtract ordereditems_quantity from product_stock but i have no idea how to do it...
4
by: August1 | last post by:
I've written an interface and implementation file along with a client source file that allows the use of an overloaded subtraction operator. However, when using the program, I'm running into a...
34
by: Andy | last post by:
Hi, Are 1 through 4 defined behaviors in C? unsigned short i; unsigned long li; /* 32-bit wide */ 1. i = 65535 + 3; 2. i = 1 - 3; 3. li = (unsigned long)0xFFFFFFFF + 3; 4. li = 1...
5
by: bruce.james.lee | last post by:
hi i have a problem with integer subtraction in C. printf("%d", c < (a - b)); a is got from a #define and is 0x80000000 and b is got from input and is also 0x80000000. c is ffffffff (-1)....
5
by: Mark Cave-Ayland | last post by:
Hi everyone, I'm trying to calculate an output column which is the difference of two other columns in the query output; the first column is an aggregate of items in stock, while the second...
2
by: prasadmoyarath | last post by:
If i subtract .01 from 100000000000000 like 100000000000000 - Math.pow(10,(-1 * 2)), i am getting 99999999999999.98. If i cut one zero from the number, result is correct and if i add one more zero to...
3
by: muler | last post by:
hi all, After reading this excerpt from "The C# Programming Language", (By Anders) I tried to check it out. Unfortunately, I'm getting compile errors. Can anyone illustrate this with an...
20
by: junky_fellow | last post by:
Hi, In my previous post I asked if sizeof may be implemented as a function. Somebody pointed a link that says that sizeof may calculated as follows with a warning that it is not guaranteed to...
5
by: Keflavich | last post by:
Hey, I have a bit of code that died on a domain error when doing an arcsin, and apparently it's because floating point subtraction is having problems. I know about the impossibility of storing...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.