color matching for pattern


Re: color matching for pattern
#2
Hi Mike,

What you're after is a colour quantisation algorithm. Ideally based on the lab colour space model but more practically based on YUV colour space. In the pseudo-code I use YUV as it is much, much easier and we are not seeking perfection.

Or in pseudo-code we find the square of the distance via:
Code:
# Here T converts RGB -> YUV (and inverse(T) converts backwards)
# and T=matrix([0.299,0.587,0.114],[-0.147,-0.289,0.436],[0.615,-0.515,-0.1])

# We then take the distance in YUV space  - these are from matrix elements of
# transpose(T)*T=matrix([0.489235,-0.098729,-0.091506],[-0.098729,0.693315,-0.007586],
#    [-0.091506,-0.007586,0.213092])

M11=0.489235
M22=0.693315
M33=0.213092
M12=-0.197458
M13=-0.183012
M23=-0.015172

Distance2=(R1-R2)*M11*(R1-R2) + (G1-G2)*M22*(G1-G2) + (B1-B2)*M33*(B1-B2)
+ (R1-R2)*M12*(G1-G2) + (R1-R2)*M13*(B1-B2) + (G1-G2)*M23*(B1-B2)

Note that the red and green components are more important (especially green) than red. This is because our eyes are much better adapted to seeing green - I guess because grass and trees are more common than blueberries.

Hope that helps Smile

Tim
Reply
« Next Oldest | Next Newest »



Messages In This Thread
Re: color matching for pattern - by Tim Gould - 2014-01-01, 21:25
Re: color matching for pattern - by Tim Gould - 2014-01-01, 22:32
Re: color matching for pattern - by Tim Gould - 2014-01-02, 21:43

Forum Jump:


Users browsing this thread: 1 Guest(s)