Finding similar images
In this post we're going to implement a simple algorithm which finds images that look similar to each other. # Overview In order to find images that look similar, we first need to normalize them to a simpler form and compute a fingerprint for each image. The fingerprint is a binary sequence of ones and zeros and it's created from the average color of the image and the average color of each pixel. In order to make the process faster and more flexible (and also to have fingerprints of the same length) the image is first resized to a fixed resolution, which defaults to 64x64. # Algorithm This is the algorithm which creates the fingerprint of an image: averages = [ ] for y in range ( height ) { for x in range ( width ) { rgb = img . get_pixel ( x , y ) averages . append ( sum ( rgb ) / len ( rgb ) ) } } avg = sum ( averages ) / len ( averages ) fingerprint = averages . map { | v | v < avg ? 1 : 0 } It