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./{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


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?


closed as off-topic by m_goldberg, MarcoB, Johu, Henrik Schumacher, José Antonio Díaz Navas Oct 19 '18 at 11:43

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – m_goldberg, MarcoB, Johu, Henrik Schumacher, José Antonio Díaz Navas
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    $\begingroup$ In a nutshell: Image[] was not atomic when that book was written, but now it is. Look up ReplacePixelValue[] and use that instead, or work with the result of ImageData[] first before converting back to an image. $\endgroup$ – J. M. is slightly pensive Oct 16 '18 at 10:37
  • $\begingroup$ @ J.M is computer-less: Thanks a lot! Do you by any chance have a reference to a list of all atoms in the latest version of mathematica? $\endgroup$ – Gert Oct 16 '18 at 10:49
  • $\begingroup$ Click on the link in my last comment. $\endgroup$ – J. M. is slightly pensive Oct 16 '18 at 10:53