compare 2 bitmaps?

Just starting out? Need help? Post your questions and find answers here.
Jimboi
User
User
Posts: 19
Joined: Fri Jul 25, 2008 10:41 am
Location: Malaysia

compare 2 bitmaps?

Post by Jimboi »

What's the fastest way to compare 2 bitmaps?
User avatar
IceSoft
Addict
Addict
Posts: 1682
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: compare 2 bitmaps?

Post by IceSoft »

Jimboi wrote:What's the fastest way to compare 2 bitmaps?
Use only very different bitmaps...So you can see it with your own eyes (Ok joke, sorry ;-) )
Belive! C++ version of Puzzle of Mystralia
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

Run through the two images, comparing pixel by pixel in a For-loop by reading the image buffer with DrawingBuffer().
PB 4.30

Code: Select all

onErrorGoto(?Fred)
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post by pdwyer »

It depends what answer you are looking for.

Do you just want "isIdentical" True/False or "how different" answer is a distance function (number of identical pixels or distance of the colour etc).

When you compare pixel by pixel you could just jump out of the loop at the first point that doesn't match.

You could compare to CRC's of the image too perhaps.
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Jimboi
User
User
Posts: 19
Joined: Fri Jul 25, 2008 10:41 am
Location: Malaysia

Post by Jimboi »

thanks guy!..very fast reply :D
but my grandmother say..compare pixel by pixel can be slow.. :(
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

No, that's wrong.

Comparing pixel by pixel with Point() is very slow...
Comparing pixel by pixel with the method I've described above is very fast!

If you only find 100% identical double images, you can also use MD5FileFingerprint(), but then the whole file must be abso-fuckin-lutely identical!!
PB 4.30

Code: Select all

onErrorGoto(?Fred)
y3an
User
User
Posts: 56
Joined: Sun Mar 09, 2008 6:06 am

Post by y3an »

Also, .bmp are very simple to read with ReadFile()

http://en.wikipedia.org/wiki/BMP_file_format

So you have not to "ask" necessarily the video buffer
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Something like this (I didn't test it):

Code: Select all

ReadFile(0, "c:\file1.bmp")
ReadFile(1, "c:\file2.bmp")
Len = Lof(0)
If Len = Lof(1)
  Mem1 = AllocateMemory(Len)
  Mem2 = AllocateMemory(Len)
  ReadData(0, Mem1, Len)
  ReadData(1, Mem2, Len)
  Result = CompareMemory(Mem1, Mem2, Len)
EndIf
CloseFile(0)
CloseFile(1)
Jimboi
User
User
Posts: 19
Joined: Fri Jul 25, 2008 10:41 am
Location: Malaysia

Post by Jimboi »

Thanks guy.. i never espect that nice people like u all
still exists in this world. :D
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

This might be faster than the MD5-method, but the file must be present on your HDD. For example, you cannot compare 2 images that you received via network.

And you code fails, when comparing a PNG to a GIF for example.

I think it would be the best, if the thread creator tells us more details about his needs.
//Edit
Do you only want to compare BMPs or all image formats?
PB 4.30

Code: Select all

onErrorGoto(?Fred)
Jimboi
User
User
Posts: 19
Joined: Fri Jul 25, 2008 10:41 am
Location: Malaysia

Post by Jimboi »

That enough for today..i will try yours guide when get home..
anyway..this is just an idea... i try to compare internet captcha image with my collections captcha image stored in my harddisk.. since coding someting like OCR is very tough for me.. this might be usefull for auto login to website that i visit everyday like bux site..
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

If you copy both images over each other with XOr, each difference will leave a set bit in a desert of zeros.

... but I doubt it would be faster, because you could do the compare in the first loop, instead of first copy it and then find a zero...

but it's the most effektive method if you want to compare the pictures visually.
oh... and have a nice day.
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

i try to compare internet captcha image with my collections captcha image stored in my harddisk
Okay, first up i want to tell that captcha's are made so bots/other software will be restricted from doing things. They are there for a purpose, not to annoy users, rather to protect them. They are MADE to be very very hard for software to read/understand, so the chance that you or practically anybody can read the newer generation captchas is VERY little.

Secondly, neither of the above solutions will work here as these captchas are probably generated on the fly. You need some kind of estimate to see if they are likely to be equal. So you need some analysis tools, byte to byte will have no effect with captchas. Neural networks might be used to create some sort of heuristic analysis, but this is not an easy thing to code and it will be tricket by artifacts and traps in the images.

And with the more and more advanced captchas on today, you will need code to eliminate vertical lines and bogus characters/graphic. This is not an easy job, trust me on that one. Simply comparing bytes will get you no where in this situation.


edit:
i know you are also looking for an OCR dll to help you with this, but i can tell you that i really doubt you'll find anything that works with just the slightly more advanced captchas. Again, captchas are MADE not to be machine-readable.

Could you eventually post an example captcha, eg take a screenshot of one from there so we can see what exactly it is we are dealing with?
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

oh, I just overlooked the sentence with the captchas...

I agree to thefool

it would be absolutely useless I think, because one captcha just have to be altered in one pixel to be two different images but still the same captcha.

you won't be able to store enough comparison images and compare them in time before the universe ends to identify ANY captcha.

... better pay someone to read the captchas for you, that would be far far more effektive.
oh... and have a nice day.
Jimboi
User
User
Posts: 19
Joined: Fri Jul 25, 2008 10:41 am
Location: Malaysia

Post by Jimboi »

i agree too.. just learn how captcha made :(

so..how about OCR (Optical Character Recognition) is it any possibality to handle captcha thing?
Post Reply