1

In the book "Programming with Mathematica: An Introduction" at the beginning of the chapter on Patterns and rules an example is given where the colors of an image are transformed according to

image=Import[...];
image./{r_,g_,b_} :> 1-{r,g,b}

and the negative of the image is returned.

When I tried to apply this to an image nothing happened though. I checked the FullForm which returned

Image[RawArray["UnsignedInteger8",List[
    List[List[111,117,129,255],List[136,139,162,255],List[124,126,149,255],List[62,42,49,255]],
    List[List[85,92,97,255],List[144,149,171,255],List[99,98,107,255],List[91,15,7,255]],
    List[List[50,60,53,255],List[87,105,92,255],List[150,143,89,255],List[141,120,57,255]],
    List[List[82,98,86,255],List[67,81,71,255],List[149,146,97,255],List[106,95,51,255]]]],
"Byte",Rule[ColorSpace,"RGB"],Rule[Interleaving,True]]

So it turns out that 4 numbers ranging from 0 to 255 are used to determine the colors of the pixels but even when I execute image./{r_,g_,b_,x_}:>{255-r,255-g,255-b,x} nothing happens.

I also tried Replace[image,{r_,g_,b_,x_}:>{255-r,255-g,255-b,x},Infinity] but to no avail.

Does anybody know why nothing happens?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Gert
  • 1,530
  • 8
  • 22

0 Answers0