Question Image comparison and RGB tolerance

tarunlalwani

Member
Joined
Oct 14, 2007
Messages
7
Programming Experience
Beginner
I have two images and i am currently able to compare them pixel by pixel. I read the images using 24rgb format into an array and compare the arrays. The code runs fine.

But now i want to implement two things
- Compare images with given color tolerance.
- Compare images and return color mismatch tolerance.

What i want is a colored image and a greyscale image comparison should pass when the color tolerance is high (i assume 100% in this case).

I am not very sure on how to implement this. I know that a pixel is represented using RGB color, but i am not able workout how to similar images which differ just in color can be compared.

Waiting for the right pointers
 
Hello.

If you're comparing them Pixel by pixel, you'd just need to check each color if it is within a range, f.e.:
VB.NET:
If firstColor.R > (secondColor.R - tolerance) AND firstColor.R < (secondColor.R + tolerance) Then Return True

Of course, you'd need to check first if the value is within Byte.MaxValue and byte.MinValue.

Also you could sum up all the differences between the pixels, and calculate the average.
VB.NET:
average = firstColor.A - secondColor.A
average = average / TotalPixels

Bobby
 
Thanks Bobby for you inputs. It would take me some time to try and implement this.

One more thing i wanted to ask is my tolerance is based on percentage comparison...so if i keep tolerance as 100% which means the color can deviate from one extreme to another. How do i compare now? i want the images to be same only if the appear similar and have different color. I assume if i put tolerance based on pixel comparison then on 100% all images of same size will come out as similar images?
 
Exactly.
If you want to do Percentage comparison, then you'd simply would need to doPercentage calculation. ;)

I'm sorry, but I'm not good at this calculations...something like firstColor.R is 100%, how many percent is secondColor.R...I always forget how to do such things. :(

Bobby
 
Back
Top