# Apply effects to images by manipulating colours in the L*a*b* space

Posted 9 years ago
4989 Views
|
0 Replies
|
3 Total Likes
|
 The Wolfram Language has built in support for many standard color model. Among those there is the L* a* b* color space, (LAB henceforth), which may turn out to be particularly useful when it comes to colour processing.The main feature of the LAB is a more perceptually accurate representation of the colours. This means that the distance between two colours in the LAB space should be closer to what a human would estimate by direct comparison. This makes it a much better space than RGB when colour difference measures are involved.Another nice property of LAB is a separate lightness channel that make possible to operate on colours without affecting the brightness of the pixels. The nature of the last two channels is less easy to grasp. Let's just say the are related to the green-red and blue-yellow opponent colours.We can capitalise on this properties to create effects for our images. Here is an example where we apply different form of color negation image = ColorConvert[ Import["http://pixabay.com/static/uploads/photo/2013/11/20/15/18/nicobar-pigeon-213896_640.jpg"], "LAB"]  {ImageApply[{1-#[[1]], #[[2]], #[[3]]} &, image], ImageApply[{#[[1]], -#[[2]], #[[3]]} &, image], ImageApply[{#[[1]], #[[2]], -#[[3]]} &, image], ImageApply[{#[[1]], -#[[2]], -#[[3]]} &, image]} As I mentioned before, LAB is good for computing distancesÂ—even if there is always something betterÂ—and so we can use it to mimic the behaviour of one very commonly used image filter: selective desaturation (not sure about the name here) The basic idea is to select one colour in the image that we want to keep and turn all the others to the correspondent grey levels. image = ColorConvert[ ImageCrop[ Import["http://pixabay.com/static/uploads/photo/2014/06/26/10/37/peacock-377748_640.jpg"], {300, 300}], "LAB"]  bluethatIwhantTokeep = {0.78, -0.22, -0.23}; Image[ImageApply[ With[{d = Clip[2 Norm[# - bluethatIwantTokeep], {0, 1}]}, (1 - d) # + d #2] &, {image, ColorConvert[ColorConvert[image, "Grayscale"], "LAB"]}], ColorSpace -> "LAB"] That's it for the moment. Do you have any fancy code that does magic in the LAB space and you feel like sharing?