views:

56

answers:

2

If I have two images which are both the left side view of a the same shoe in different styles, how can I determine by which color(s) they differ? Perhaps it's a shoe in two styles, one style has pink laces and a white side, the other has white laces and a yellow side. I want:

Image One Colors: C1=Pink, C2=White

Image Two Colors: C1=White, C2=Yellow

No super high level algorithms, but I don't need actual implemented code either. Perhaps just loops, data structures, conditions..

The actual shoe part of the image will be on a white background. These will be photographs similar to what you'd see on endless.com or zappos.com so they're very similar, but require some tolerance.

A: 

you should be able to use something along the lines of the 'diff' command in bash, to compare the contents of the two files directly. Then, you can analyze that data, process it into colors (using a hex chart to aid you) and print out the different colors. To get coherent results from diff, I recommend cating it into a text file, and then processing the text file. Something like 'diff file1.jpeg file2.jpeg > differences.txt'

This can be done from a C program quite easily. This is, however, a solution for a unix based system, I don't know if Windows has the operation available.

Alex Hart
Since I'll be working with compressed images, and not bitmaps, I don't think diff is an option. Also, these are going to be photographs, so I need some degree of tolerance.
MStodd
+2  A: 

Since it sounds like you only want to tell what colours they differ by (without regard to shape etc.) and that you expect the shapes will be highly similar (though not identical), I would:

  1. Compute colour histograms for each image (you may need 3 histograms each for R, G, B)
  2. Subtract them (z = abs(x - y) for each colour)
  3. Identify peaks in the resulting histogram(s)

When a significant area is coloured differently in each image, this will give you two high peaks in the final histogram(s). (Drop the abs() if you need to tell which is which.)

[EDIT] As jilles de wit suggests, it's better to look at frequencies of (R, G, B) triples instead of individual colours (i.e. for each image create one big histogram of size 256*256*256 instead of 3 size-256 histograms). But in this case the histogram vector is huge and likely to be mainly filled with zeros, so it is a good idea to quantise the intensities down from 256 to say 16 levels, giving a more manageable 16*16*16 vector.

j_random_hacker
That's an interesting approach. Sounds like it should do the job.
MStodd
Don't do separate histograms for R, G and B. The combination of R,G,B makes the colour. A red shoe with yellow laces on a black background would lead to peaks in both the R,G and B histograms around 255 and 0 and you wouldn't know which colour caused them (could be red, blue and green, or green and purple, or red and cyan, etc.) Otherwise, finding peaks in the histogram is the most sensible approach.
jilles de wit
@jilles: Do you mean recording the frequency of each (R, G, B) triple? That sounds like a good idea. In that case some quantisation is probably helpful to avoid dealing with highly sparse 256*256*256 vectors.
j_random_hacker
@j_random_hacker: Yes, that is exactly what I mean, including quantisation.
jilles de wit