Posts: 1,002
Threads: 50
Joined: May 2022
Reputation:
27
(11-18-2022, 09:30 PM)Pete Wrote: If the variables are equal, the images are the same....
By variables do you now mean the same number of pixels? That would mean nothing.
Hundreds of thousands of pixels in picture 1 and 2 does not mean that they are identical, not even if it is the same color distribution.
Simple example:
10,000 Red - 15,000 Yellow - 20,000 White - 10,000 Green and X = 100,000 pixels. Even if the second image has the same number of colors, it does not mean that the images are the same.
Posts: 660
Threads: 142
Joined: Apr 2022
Reputation:
58
11-18-2022, 09:41 PM
(This post was last modified: 11-18-2022, 09:42 PM by James D Jarvis.)
(11-18-2022, 09:37 PM)SMcNeill Wrote: (11-18-2022, 09:30 PM)Pete Wrote: If the images are in a file, just open each into a variable with BINARY.
If the variables are equal, the images are the same....
Pete
This may not work for a variety of reasons. Different formats of the same image. One was saved compressed, the other wasn't. One has additional file attributes attached to it, that the other doesn't. You'd want to load the files into memory and compare the contents of the image once they're loaded. After all, you want to know if the IMAGES are identical; not the files which contain them.
What SMCNeill said.
Posts: 660
Threads: 142
Joined: Apr 2022
Reputation:
58
The string compare method is a great way to do it, if there is no noise and the images are the same size. But it will not work if there is noise or they are different size images.
Posts: 2,177
Threads: 222
Joined: Apr 2022
Reputation:
104
This worked for me. I made a copy of an instagram icon and changed the name. I compared the original to the one with the changed name to see if the name change would affect the results. It did not. This is a very fast method, but sure, you'd have to look into any particulars that it might not be reliable.
For now, if you are curious, here is how it's done.
Code: (Select All) IF _FILEEXISTS("instagram_icon.jpg") THEN
OPEN "instagram_icon.jpg" FOR BINARY AS #1
a$ = SPACE$(LOF(1))
GET #1, , a$
CLOSE #1
PRINT LEN(a$)
END IF
IF _FILEEXISTS("junk-for-qb64-test.jpg") THEN ' This is a renamed copy of the instigram icon.
OPEN "junk-for-qb64-test.jpg" FOR BINARY AS #1
b$ = SPACE$(LOF(1))
GET #1, , b$
CLOSE #1
PRINT LEN(b$)
END IF
IF LEN(a$) AND LEN(b$) THEN
IF a$ = b$ THEN PRINT "Same Image" ELSE PRINT "Different Image"
ELSE
PRINT "An image couldn't be found."
END IF
Pete
Shoot first and shoot people who ask questions, later.
Posts: 733
Threads: 103
Joined: Apr 2022
Reputation:
14
(11-18-2022, 09:15 PM)Kernelpanic Wrote: (11-18-2022, 09:10 PM)Spriggsy Wrote: (11-18-2022, 09:08 PM)Kernelpanic Wrote: A deer must recognize at first glance whether what it sees is harmless or dangerous (such as a wolf) I don't know, man. Deer are quite retarded. A deer will jump at the slightest twig movement but will watch a 2,000 pound metal machine roar towards it and not budge an inch.
Because the machine doesn't know it and therefore can't classify it (first time): dangerous or not
PS:
There is a video (but where now), about twelve years old, that shows the German Bundeswehr during target practice with howitzers - and about 200 to 300 meters away deer are grazing peacefully. Why? Because they've realized by now that the banging isn't aimed at them.
I love how we can start off talking about comparing images, and before long I'm hearing interesting stories about deer and artillery practice, LoL!
Posts: 733
Threads: 103
Joined: Apr 2022
Reputation:
14
(11-18-2022, 09:21 PM)James D Jarvis Wrote: squish the two images down to a really small image. If they don't match when they are 2 by 2 pixels they sure aren't going to match when they are say 200 by 200 pixels.
if it matches keep comparing pixels by pixel in slightly larger scaled image until back up to original size.
This is a creative approach - it's kind of like that collision detection method where you progressively test smaller areas.
I'll give that code a look when I am back in the IDE. Thanks!
Posts: 2,177
Threads: 222
Joined: Apr 2022
Reputation:
104
I think we are at the point of asking exactly what images are to be compared? If I were using/making my own, they would all have the consistency to be compared as apples to apples. No one saved via compression vs the identical one being saved in the standard format. But what about a jpeg that is saved at high resolution vs low? Exact same image, but less definition. So is it the same or not here?
Many times to get the solution for the situation requires much more involved info.
Pete
Shoot first and shoot people who ask questions, later.
Posts: 1,586
Threads: 59
Joined: Jul 2022
Reputation:
52
11-18-2022, 11:14 PM
(This post was last modified: 11-18-2022, 11:17 PM by mnrvovrfc.)
ORIGINAL POST:
(11-18-2022, 07:51 PM)madscijr Wrote: Is there a fast way to test whether 2 images are exactly the same?
Mis dos centavos.
Better hope it's in BMP format, then your brute-force method would be sufficient, except you have to figure out the "parameters" for each image such as its dimensions and its being 24-bit or 32-bit. Palette could be a pain... but I don't know that much about binary file formats. :/
Otherwise with JPEG and PNG, this could be impossible. Because anything that creates eg. PNG, has to dither which is something I can't comprehend away from its needing to compress to a small size. Check out the main restrictions for having an avatar in a forum like this one -- no BMP file will do, but not because there is hate for M$, because most of the time they are too big!
Especially for a photograph, many computer viewports haven't yet reached the DPI (I'm ignorant of the term to use in place of this) to take up the fantastic real-life detail. Therefore even JPEG has to compromise itself with "blending" and other mind-boggling algorithms so that it looks realistic enough zoomed at any level. Although zooming in too closely could cause any algorithm to fall apart. This is the same with music: set the sampling rate and/or bit rate too low and eventually you're going to hear either silence or glitches; setting it too high could produce ugly anti-aliasing or sound that only dogs could enjoy (like an image that is zoomed out toward "SCREEN 13" or smaller dimensions LOL).
There are applications that cost money that could compare one picture file to another, even if they're different formats. What the user is looking for about comparing is left to another discussion.
Posts: 1,586
Threads: 59
Joined: Jul 2022
Reputation:
52
https://qb64phoenix.com/forum/showthread.php?tid=1004
Has anybody gone into this example? I've tried it with a picture of the earth I had to download from somewhere. How about when you zoom in and out too much? That is the basic problem with compressed formats that have to dither and do other things so a pretty face looks like a pretty face "because I don't like jaggies".
Yes I know, it's not a good example but... away from BMP or ancient text-file-only PPM, just forget about comparing images with a program written with QB64PE or something else like that.
Posts: 2,697
Threads: 327
Joined: Apr 2022
Reputation:
217
How fast are you needing your compares to be? Somehow, it seems like everyone overlooked my working example here: https://qb64phoenix.com/forum/showthread...1#pid10221
2000 full-screen compares of 720p HD images in 3 seconds. That's 666 per second, or a comparison every 0.00something seconds.
Since this isn't the type of routine which one needs to do repetitively, I'd think the little function I'd posted should be quick enough for most use cases.
If not, then you could probably save time with it considerably by writing a DECLARE LIBRARY routine and using memcmp directly, without having to copy the memory over into a set of temp strings to compare instead.
|