By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
463,048 Members | 428 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 463,048 IT Pros & Developers. It's quick & easy.

C#-APP: Program that detects difference (in color) between images.

P: 2
Hi, I'm having a lot of troubles trying to build a function to figure out the difference (in color) between two images.


I've tried to build something similar with the ImageMagick API, but I've had many troubles compiling a DLL from the libraries.
I am also unfamiliar with the .net libraries, but I've been reading up on MSDN.

I know how the basic flow of the program should go (I think), I've been having trouble executing the steps.

Load ImageA
Load ImageB
Take the difference (absolute value of the difference in color between the images)
Change Channels of this new image (give color to the masking)
Save this as a different image. (Temporarily: To be used as a mask later.)
Change the channels of this image (To give it color)
Overlap the image with the mask on top
Save the image.



Here is what I have so far.

//Load ImageA
Image ImageA = new Image.From("ImageA.jpg");
//Load ImageB (Assume same size)
Image ImageB = new Image.From("ImageB.jpg");
//Take the difference of the images: If there is a visible difference, display some white, otherwise show black.
//How would I do this for colored images?
//Save this image. (Temporarily [should I turn this into a BLOB?])
ImgTmp = Bitmap("[????].jpg");
//Change Channels of this new image (This section of the code is taken/modified (badly) from <http://www.codeproject.com/KB/GDI-plus/csharpgraphicfilters11.aspx>. I admit now that I don't know what I'm doing.)

unsafe
{
byte * p = (byte *)(void *)Scan0;

int nOffset = stride - b.Width*3;

byte red, green, blue;

for(int y=0;y < b.Height;++y)
{
for(int x=0; x < b.Width; ++x )
{

blue = p[0];
green = p[1];
red = p[2];

p[0] = p[1] = p[2] = (byte)(1 * red
+ 0 * green
+ 0 * blue);

p += 3;
}
p += nOffset;
}
}

//Overlap the image, onto ImageB.
//(Don't know how to do this in the way I want)

//Save Resulting Image.
Final.Save("[Filepath]\Final.jpg", System.Drawing.Imaging.ImageFormat.jpg);
----------------------------------

Please correct me if anything (read: EVERYTHING) is wrong, or a location of a properly functioning Magicknet DLL.

Again, I am learning, so I could use a lot of help on this.

Thanks!
Jan 28 '08 #1
Share this Question
Share on Google+
1 Reply

P: 2
Nevermind: I got it to work! =d
Jan 31 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.