Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Analysing if a Jpeg exists in another Jpeg  RSS feed

 
per bonde
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to write a Jpeg that recognizes if it exists in another jpeg.

Example:

I got a jpeg, 50*50 pixels, which I have cut out from a bigger jpeg 100*100

How Do I write a function that can tell me if picture 1 exists within picture 2?

Code example please!

/BondePer
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'd probably have to iterate over the SampleModel pixel by pixel checking for a similar pattern. I can think of a few ways to approach that algorithm, though I'm not at all sure of what would be considered a 'good' approach. Given an image i that we wan't to compare to a larger image i2, you could take the topmost row of pixels of i and compare one band against the same band of each row of pixels in i2 such that the y value is >= the height of i. If you don't find a match you've established that it's not in the image. If you do find a match you can compare the other bands and iterate down from there. If all the bands match all the way through i you've discovered the image within the image. As soon as you find a place that doesn't match you return to where you started with your first band and continue iterating down.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!