Search similitary of a picture in folder of thousand others

Everything else that doesn't fall into one of the other PB categories.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Search similitary of a picture in folder of thousand oth

Post by Kwai chang caine »

Again thanks 8)
Apparently it's the same result.

Your code is not sensible to the rotate ?? the lightning ?? etc ..
What's modification not modify your code ???

In fact i can mixing several methods for be sure to the result.
For exampler, like i say above, the color dominance (image blue or red) + your hash....and perhaps again another idea ??
Like that, it's surely impossible to an image to have exactely the same result in several test ...

Except perhaps an white image with just title like that :
Image
dHash - Compare two differents pictures of extremely different record
-2770167811735213228
2609421560056017481
34

dHash - Compare exactely the same picture of the same record
-2770167811735213228
-2770167811735213228
0

dHash - Compare two differents picture of the same record
-2770167811735213228
-2842226509793678442
13

dHash - Compare the same picture rotating
-2770167811735213228
9173101322984576773
21

dHash - Compare the same picture lightning
-2770167811735213228
-2770167811735213100
1

***************************************

dHash2 - Compare two differents pictures of extremely different record
-2770167811735213228
2609421560056017481
34

dHash2 - Compare exactely the same picture of the same record
-2770167811735213228
-2770167811735213228
0

dHash2 - Compare two differents pictures of the same record
-2770167811735213228
-2842226509793678442
13

dHash2 - Compare the same picture rotating
-2770167811735213228
9173101322984576773
21

dHash2 - Compare the same picture lightning
-2770167811735213228
-2770167811735213100
1
ImageThe happiness is a road...
Not a destination
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Search similitary of a picture in folder of thousand oth

Post by wilbert »

Something isn't right.
The hashes for the modified procedure can't be the same :?

dHash is sensible to rotate.
Lighting isn't important.

Best would be probably if someone who is familiar with discrete cosine transform could implement pHash.
Besides the dct it's not that different from dHash.
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Search similitary of a picture in folder of thousand oth

Post by Kwai chang caine »

Ok, :( never mind, your code is when even a move for me 8)
I apply it, monday on the 12000 records for see, if they are a strange result :D

The kind IDLE give to me another approach 8) , but unfortunately, he can't for the moment finish his code (Not enough time) :cry: perhaps a day :D
If someone have another idea, for testing something in an image and return a number i adding the result in my "KEY", like your "Count used colors" for exampler :wink:
And perhaps with numerous tests, i can create a unique key ???
Adding of the test of imageMagick or another library like openCV, or other.... i can have a perfect result.... we never say :D

This is the result for two image white
http://erdsjb.free.fr/PureStorage/Provi ... lbert2.zip
ImageThe happiness is a road...
Not a destination
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Search similitary of a picture in folder of thousand oth

Post by wilbert »

Here's my own attempt ...
I think it doesn't perform very bad (actually pretty good) :wink:
I also converted the compare procedure to asm for speed.
If you don't like that, you can still use the other compare procedure since the results are the same.
For your album collection it will probably be best to pass 1 (or 2) for edge to the dHash3 procedure.
This way the outer part of the image is ignored when producing the hash.

Code: Select all

UseJPEGImageDecoder()
UsePNGImageDecoder()

Global Dim sample_x(63)
Global Dim sample_y(63)

For y = 0 To 7
  For x = 0 To 7
    i = (x & 4) >> 2 + (x & 2) << 1 + (x & 1) << 4 + (x!y & 4) >> 1 + (x!y & 2) << 2 + (x!y & 1) << 5
    sample_x(i) = x
    sample_y(i) = y
  Next
Next

Procedure.q dHash3(filename.s, edge = 0)
  Protected.i img, b, c, r0, g0, b0, r1, g1, b1, hash.q
  
  img = LoadImage(#PB_Any, filename)
  If img And ResizeImage(img, 8 + edge << 1, 8 + edge << 1)
    StartDrawing(ImageOutput(img))
    g0 = Point(sample_x(31) + edge, sample_y(31) + edge) & $ff00
    b0 = Point(sample_x(47) + edge, sample_y(47) + edge) & $ff0000
    r0 = Point(sample_x(63) + edge, sample_y(63) + edge) & $ff
    For b = 0 To 63
      c = Point(sample_x(b) + edge, sample_y(b) + edge)
      If b < 32
        g1 = c & $ff00
        If g0 < g1 : hash | 1 << b : EndIf
        g0 = g1
      ElseIf b < 48
        b1 = c & $ff0000
        If b0 < b1 : hash | 1 << b : EndIf
        b0 = b1
      Else
        r1 = c & $ff
        If r0 < r1 : hash | 1 << b : EndIf
        r0 = r1
      EndIf
    Next
    StopDrawing()
    FreeImage(img)
  EndIf
  
  ProcedureReturn hash
EndProcedure

Procedure.i dHashCompare(hash1.q, hash2.q)
  !xor eax, eax
  !mov ecx, [p.v_hash1]
  !xor ecx, [p.v_hash2]
  !jz dhashcompare1  
  !dhashcompare0:
  !mov edx, ecx
  !dec edx
  !inc eax
  !and ecx, edx
  !jnz dhashcompare0
  !dhashcompare1:
  !mov ecx, [p.v_hash1 + 4]
  !xor ecx, [p.v_hash2 + 4]
  !jz dhashcompare3
  !dhashcompare2:
  !mov edx, ecx
  !dec edx
  !inc eax
  !and ecx, edx
  !jnz dhashcompare2
  !dhashcompare3:
  ProcedureReturn  
EndProcedure
The hash checks for differences in intensity of the red, green and blue channels in a bayer matrix order.
Image
Last edited by wilbert on Wed May 31, 2017 3:08 pm, edited 7 times in total.
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Search similitary of a picture in folder of thousand oth

Post by Kwai chang caine »

Thanks a lot my friend WILBERT 8)

You are crazy !!! i not like ASM.....i love ASM 8) 8) 8) 8)

The only problem, it's ASM not love me :mrgreen:
In fact, i find it's the most beautiful langage of the world... :shock: 8)
And i'm proud PB can manage ASM..
But for me it's just nice :oops: like hieroglyph :oops: :oops:

Imagine i don't understand the C, but i dream a day write a little bit C 8)
But for the assembler, it's for another life :mrgreen:

Again thanks, i try your code today and give to you some news 8)
Have a good day :D
ImageThe happiness is a road...
Not a destination
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Search similitary of a picture in folder of thousand oth

Post by wilbert »

I'm very sorry but I found a problem with the code I posted.
I updated the code above. It should produce better results now hopefully.
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Search similitary of a picture in folder of thousand oth

Post by Kwai chang caine »

No problem 8)
You are already so generous to spend your time for me 8)

I have not can test your kind works, because my wife ask to me go to the store with her, so..no PC :(
But you know the womens....what the woman want...god want :cry:

She's far in the house now....i can return to the PC :D

I test your code immediately 8)
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Search similitary of a picture in folder of thousand oth

Post by Kwai chang caine »

I have testing tour splendid works !!!
And it's very impressive, apparently no error, with rotate, lightning, white image or all similar red picture :shock: :D
See yourself :
http://erdsjb.free.fr/PureStorage/Provi ... 40118W.zip
dHash3 - Compare two pictures all red (Same style)
4 ==> 5
-3083388455138815319
-8441649740850181227
31

***************************************
dHash3 - Compare two differents white pictures of little bit different records
Blanc1 ==> Blanc2
4991564864893004981
-5755581219490229978
31

***************************************
dHash3 - Compare two differents pictures of extremely different record
1 ==> 3
6146965533075745482
-2672370532549603159
37

***************************************
Compare exactely the same picture of the same record
1 ==> 1
6146965533075745482
6146965533075745482
0

***************************************
dHash3 - Compare two differents picture of the same record and not the same size
1 ==> 2 (Reduce)
6146965533075745482
6146402583122397635
8

***************************************
dHash3 - Compare two differents picture of the same record
1 ==> 2
6146965533075745482
6146965533075819459
6

***************************************
dHash3 - Compare the same picture rotating
1 ==> 1 (Rotate)
6146965533075745482
4995451425972365970
18

***************************************
dHash3 - Compare the same picture lightning
1 ==> 1 (Lightning)
6146965533075745482
6146965533075745482
0

***************************************
Monday, i continue to encode each 12000 records and test your code on much case :D

Thanks a lot WILBERT !!!! 8)
ImageThe happiness is a road...
Not a destination
Thade
Enthusiast
Enthusiast
Posts: 266
Joined: Sun Aug 03, 2003 12:06 am
Location: Austria

Re: Search similitary of a picture in folder of thousand oth

Post by Thade »

Hi

Perhaps you can use this: http://www.panotools.org/dersch/

There are algorithms to discover similarity in different pictures to prepare stiching of panoramas.
I know they are used by this guy (link below), who sells one of the best panaorama makers.
I am using it quite often und know that it finds similarities even if the pictures are rotated or have another exposure.
http://www.ptgui.com/
http://www.ptgui.com/support.html

.
--------------
Yes, its an Irish Wolfhound.
Height: 107 cm; Weight: 88 kg
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Search similitary of a picture in folder of thousand oth

Post by Kwai chang caine »

Thanks THADE,

This time, during my numerous research, i don't see this lib 8)
Surely because i don't imagine, that a panorama viewver can detect similitary picture .. :shock:
Thanks for this new approach...
I try to understand what it can do for me :wink:

Again thanks for your link
ImageThe happiness is a road...
Not a destination
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Search similitary of a picture in folder of thousand oth

Post by wilbert »

The goal is very different.
A panorama stitcher tries to find overlapping parts on different images and should do so with the best quality possible.
All my dHash3 code I posted above does is take 64 areas of an image and compare either the red, green or blue intensity of that area with that of another area.
It simply answers the question if the intensity of one area is less compared to that of another one. The 64 answers to those 64 questions result in a 64 bit value.
You can store those values and compare them at a later time. The more different answers to those questions, the more likely the image doesn't match.
It can result in false positives (an image that looks totally different to us can have the same answers) but also allows to compare maybe 100.000 images (if the hashes are already available) in less than a second.
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Search similitary of a picture in folder of thousand oth

Post by Kwai chang caine »

Yes, your code is exactely what i search 8)
Already because i can attibute a value by image and test it after
And the result is good for some image i have tested.
Tommorow i use it for all my record and store the result in file for found very quickly a picture 8) 8)
After i give to you the result, for see what is the percent of error on 12 000 records :wink:

Further at your code i want to use the code of IDLE, i believe it's another approach for analysing the picture (The moment)
In fact i don't know what is it, because i have not really understand, :oops: but i believe it's different to the hash
Because the moment not care of rotation and scaling of the picture. :shock:

I think your two codes together can give a perfect result... 8)
ImageThe happiness is a road...
Not a destination
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Search similitary of a picture in folder of thousand oth

Post by wilbert »

@KCC, if you don't want to create something yourself but are looking for some freeware application, take a look at imgSeek ( http://www.imgseek.net/ ).
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Search similitary of a picture in folder of thousand oth

Post by Kwai chang caine »

Waooouhh !!! i have not see this link during my research !!! :shock:
I take a look for see if it's what i search for do the job i have to do immediately.. 8)
So your super and also IDLE code give to me when even the envy to try again a little bit :D :oops:
It's a pity that you have all worked for me, and i abandon also quickly :?
If the final result is enough good, and if this new software, or other do the job i use it...
For the moment, it's interesting to try to move a maximum to the solution :D

So thanks again a lot for all...i take a look this afternoon :wink:
ImageThe happiness is a road...
Not a destination
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Search similitary of a picture in folder of thousand oth

Post by IdeasVacuum »

Experimenting with the dHash3 code. Works well with colour images but I have hit a wall with greyscale images. What I'm trying to do is find greyscale images that are similar to a colour 'master image'. So, for my experiment I made 2 greyscale versions of the colour image, 1 with IrfanView, one with PB. Of course the PB produced image uses the same to-grey procedure as that applied to the master at run time, and the result is therefore perfect. The IrfanView greyscale is surprisingly different though - the naked eye can see nuances, but dHash3 exposes the fact that it is very different. So, the image is not found to be similar to the master, even though it was made from the master.

Image
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply