Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search small images inside of large ones

Status
Not open for further replies.

December

Programmer
Nov 29, 2002
19
UA
Hi all.
Did anybody stormed subj? I'd be glad if you say what you think about optimisation of the search process.
 
Hi,
I would proceed so:

Put the first line Pixel(x,0) of the SmallImg in a structure (Array, StringList, what you prefer),
then scan the big image line per line.
When you find the pixel sequence then compare the second line of SmallImg with the (maybe) corrisponding of the BigImg (Same x of the first occurence, y+1) and so on.
If all the lines are the same, you have find your SmallImg.

I hope this may be usefully.

Ciao,
Geppo Darkson.
 
OK, that's clear.
I mean what ideas have you got concerning optimizing this process? Realization you suggested takes 80 seconds when searching for 16x14 image inside of 800x600 (worst case).
 
Hi,
to optimize it you can do follow:
1) put your BigImage in a structure (Color, x, y)
2) order it by color
3) do the same with your small Img
4) select the color with less pixels
5) search in this structure just for one color, for example:
The small picture have 4 red pixels. Store this information in the form x,y for the first, x+a,y+b for the second and so on. Then take the first pixel in the Big stucture in the "red section". If Abs(x[0]-x[1])=a => it may be the right pixel, else If x[0]-x[2]=a and so on. (check also the y only if it match) When the first two points match, do it again with the third and so on.
Working with in-memory structure (Array or TList or something else) should dramatically increase your speed, because you don't have to manage DeviceContext, Canvas, and other stuff that brakes your procedure, any you read the pixel only ones.
Of course this method won't be the best if you examin the image of a ChessBoard (with many x[0]-x[1]=a), but for many pictures it should be ok.

P.S.
I wrote a better answer, but this site crashes when uploading, and my WellWritingImpulse is gone with it.
Just ask me if something is not clear.

Ciao,
Geppo Darkson.
 
Thank you very much!
An idea with sorting by colors ignored my brain before. I'll work that out.
 
Yeap. But:
-there is no real need to sort colors in small image;
-usage of two figurative points (they are first to check)give excellent speed gain, while the third does not;
-using TBitmap.Scanline is the first a programmer should come to know (for 4 years working with Delphi I used Canvas.pixels[]).
Thank you for participation.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top