Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: Comparing images

by brig (Scribe)
on Nov 27, 2006 at 22:11 UTC ( [id://586339]=note: print w/replies, xml ) Need Help??


in reply to Re: Comparing images
in thread Comparing images

Read one pixel out of an arbitrarily large file?

Nine Nines and two sevens? that's 33 out of a hundred billion!

Replies are listed 'Best First'.
Re^3: Comparing images
by BrowserUk (Patriarch) on Nov 27, 2006 at 23:16 UTC

    Yup. Did you read this? Remember, if the two values are the same, you then go on and run a full md5, so there is no risk. But if they are different you saved yourself the bother/expense of doing it. And statistically, that should be the case in a very large percentage of cases.

    The reality of any given set of data probably won't reach that theoretical maximum. For a start, many if not most images don't use the alpha byte, so the range of values is reduced to

    ( ( 2**24 * (2**24 - 2) ) / 2**48 ) == 0.999_999_887_92

    but that's still pretty good odds for the effort of reading 4 bytes and comparing two integers.

    Of course, if the two pictures being compared are

    1. A 640x480x24-bit color image of a black cat in a coal celler inside the Artic Circle in winter, with no flash.
    2. A 640x480x24-bit color image closeup of a black hole.

    Then this quick and simple test may not discriminate between them. But then, will the viewers? :)

    More seriously, it's possible that the camera that took the images has a bad cell in the CCD that means that one pixel in the same place on every image is always black (or white or red), and this test would fail to distinquish them if it happens to check that exact pixel. But if the dword compared is (semi-)randomly chosen, that would be pretty unlucky.

    Even if you mount the camera on a tripod and use a remote trigger to avoid micro-seismic disturbances, and take two frames one after the other, with 16 mlllion colors to choose from for each pixel, even the slightest variation in the light, or focus, or even the battery charge is likely to cause variations in the pixel colors at identical positions in identical shots by the same camera. In 8-bit color/grey scale images, the variation will be less, but then you are comparing 4 pixels not one. In a strictly B&W image, you would be comparing 32 adjacent pixels.

    But when the statistically improbable happens and you get a false positive, that false positive would be caught by the full md5 anyway. The point is to save time by avoiding that full md5 (or similar) where possible--not ditch it all together.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://586339]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (10)
As of 2024-04-18 09:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found