Message Boards Message Boards

0 Replies
3 Total Likes
View groups...
Share this post:

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

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[""], "LAB"]

nicobar pigeon

{ImageApply[{1-#[[1]], #[[2]], #[[3]]} &, image],
 ImageApply[{#[[1]], -#[[2]], #[[3]]} &, image],
 ImageApply[{#[[1]], #[[2]], -#[[3]]} &, image],
 ImageApply[{#[[1]], -#[[2]], -#[[3]]} &, image]}

lab inversion

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[
  {300, 300}],


bluethatIwhantTokeep = {0.78, -0.22, -0.23};
  With[{d = 
      Clip[2 Norm[# - bluethatIwantTokeep], {0, 1}]}, (1 - d) # + 
     d #2] &, {image, 
   ColorConvert[ColorConvert[image, "Grayscale"], "LAB"]}], 
 ColorSpace -> "LAB"]

blue peacock

That's it for the moment. Do you have any fancy code that does magic in the LAB space and you feel like sharing?

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract