469,143 Members | 1,101 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,143 developers. It's quick & easy.

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

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
1 2540
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.

Similar topics

reply views Thread by Phil Galey | last post: by
15 posts views Thread by Geoff Cox | last post: by
3 posts views Thread by Simon | last post: by
7 posts views Thread by tiger786 | last post: by
4 posts views Thread by Kevin D. Smith | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.