C language > Expert questions

Searching a small image into a big one

(1/2) > >>

HellOfMice:
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

John Z:
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

HellOfMice:
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.

HellOfMice:
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

John Z:
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

Navigation

[0] Message Index

[#] Next page

Go to full version