How to calculate the distance from a pixel in the Lab-color space to a specific prototype

1.1k views Asked by At

I have Lab-Image and for each pixel in it, i want to know how Red, Green, Blue and Yellow that pixel is.

which means, for the input Lab-Image i should get four images one for Red,Green,Blue and Yellow.

as far as I researched, i knew that could be done by calculating the ecludian distance from each pixel in the Lab-image to the prototype of the color (R,G,B or Y). for an example, if i want to produce an image contains how Red the pixels in the Lab-Image, then for each pixel in the Lab-Image, i have to calculate the distance from that pixel in the Lab-Image to the prototype of the Red color in the Lab-color space

kindly please provide some advice and guidance.

1

There are 1 answers

1
Photon On BEST ANSWER

All you need to do is convert the color value you need (e.g. Red = 255,0,0 in RGB) to Lab (Lref,aref,bref), then calculate euclidean distance between each pixel and this value, and set the distance as the output pixel value.

out_pixel=sqrt(sqr(Lpixel-Lref)+sqr(apixel-aref)+sqr(bpixel-bref))

You may want to normalize the values, if you want the pixel output to fit in 0-255.