NO

Author Topic: Searching a small image into a big one  (Read 794 times)

Offline HellOfMice

  • Member
  • *
  • Posts: 62
  • Never be pleased, always improve
Searching a small image into a big one
« on: September 24, 2023, 04:46:31 PM »
I know how to do it in a stupid and mean way, that is to say, search byte by byte.
I would prefer a more efficient method, so I am asking for your help.
I search the image named "k0.jpg" into any image.
The image named "# Original.jpg" was used to create the mask.

I need your help.
Thank You
--------------------------------
Kenavo

Offline John Z

  • Member
  • *
  • Posts: 796
Re: Searching a small image into a big one
« Reply #1 on: September 25, 2023, 10:45:00 AM »
Hi HellOfMice,

Are you looking for ideas to try or complete solutions?  I have an idea  ::)

First you know the dimensions of the smaller looking for image LX,LY that you are looking for within the bigger image SX,SY.

My thought is to search for a small byte run in the horizontal direction say 32 pixels worth, adjustable of course.
if these match the 32 pixels starting in the upper left top of the original image then check 32 pixels down in the vertical
direction if these match (meaning a possible corner found) then XOR the search image you are looking for with the bigger image starting at the SX,SY position that matched as a  possible image start and then check for all zeros within the LW,LH space, if all zeros you have found a matching space in the bigger image.
If not found then the next search moves over of course to check again. 
Maybe it would be shorter ....

Another possibility is
Maybe ask ChatGPT or Bard how to do it and have it generate some code to do the search?

John Z


Offline HellOfMice

  • Member
  • *
  • Posts: 62
  • Never be pleased, always improve
Re: Searching a small image into a big one
« Reply #2 on: September 25, 2023, 12:58:39 PM »
Hi John,

That was my first idea and I know that I hae to search for the image with (the big) less the part of image that is used for finding. Idem with the height.
Example if the big image is 5000x6000 and the small image is 400 x 400, I have to search for 5000 - 400 and 6000 - 400. I stop when I am in row 4961 or in column 5961.
But take a loo to my previous post, there is a mask so I cannot use your solution.

I would like to write such a program because I found an image and did not know if it was in my images folder.
The image folder has more than 8000 images! Not easy to find something.

I have analyzed many ways to do that but the solutions found were too complicated and I imaged the user filling all fields...

That would help in finding doubles images but for that t is more difficult.
--------------------------------
Kenavo

Offline HellOfMice

  • Member
  • *
  • Posts: 62
  • Never be pleased, always improve
Re: Searching a small image into a big one
« Reply #3 on: September 25, 2023, 01:45:28 PM »
My idea is to apply a Sobel filter to the two images
That will be easier to search.
I must convert the original colour image in grey and then apply a 3x3 sobel operator
Idem for the small images.
The original is on the right, the grey conversion in at the center and the sobel operator is on the left
--------------------------------
Kenavo

Offline John Z

  • Member
  • *
  • Posts: 796
Re: Searching a small image into a big one
« Reply #4 on: September 25, 2023, 02:29:16 PM »
Hi HellOfMice,

OK maybe I misunderstand.  So are you looking for
1) a sub-image within a larger image (like the button sub-image within the toolbar larger image)
or
2) an exact duplicate image within a sub-directory of all images
or
3) Both ?

If number 2 I think SHA256 comparison can at least significantly reduce the number of images needing closer inspection.

John Z

Offline HellOfMice

  • Member
  • *
  • Posts: 62
  • Never be pleased, always improve
Re: Searching a small image into a big one
« Reply #5 on: September 25, 2023, 05:08:34 PM »
John,

That's right I join an image for what I want to do.
I search for a rectangular area but it can be an ellipse, or a polygon...
After I have applied the Sobel filter/operator I will use the SHA256.
I had forgotten SHA256 and did not Keccak which is too big and a bit slow.
You gave me the second question (that I wiil not send!)
Do you understand now?

A+

Philippe
« Last Edit: September 25, 2023, 05:14:34 PM by HellOfMice »
--------------------------------
Kenavo

Offline John Z

  • Member
  • *
  • Posts: 796
Re: Searching a small image into a big one
« Reply #6 on: September 26, 2023, 11:35:48 AM »
Yup I understand now :0

Clearly if the sub-image is not bounded by straight lines searching for a corner is useless.
will ponder more

John Z

Offline HellOfMice

  • Member
  • *
  • Posts: 62
  • Never be pleased, always improve
Re: Searching a small image into a big one
« Reply #7 on: September 26, 2023, 11:50:09 AM »
Here is what I can have to search.
I have used CFE to create the sub-image because what I will find will not have the same number of color or could be converted in grey or may be compressed more so strange pixels are presents.
I have joint the mask that I will use.

--------------------------------
Kenavo