2
$\begingroup$

Let's say I have two images. One is the original and the other is after some photo-manipulation has been applied to it.

I want to show the effect on the color saturation using a scatter chart. Similar to this:

http://lh4.ggpht.com/2vp2fSsdBaP-_yvG-RIISCZbHU5-Zz1FK0lyUSo8I4iLxATq0laxzb4ha8fZz7aoFJ8sZHnc5viIC4tV-za1FxF7O7M

How would I do that?

$\endgroup$

1 Answer 1

7
$\begingroup$

Suppose these are img1 and img2 (in this example img2 is a Deuteranopia colour blindness effect with some contrast adjustment):

img1 img2

You first convert them to the "HSB" colour space using ColorConvert[img1,"HSB"] and likewise for img2. All you then need to do is extract the values in the Saturation channel and pair them up:

points = Transpose[
 Flatten[ImageData[ColorConvert[#, "HSB"]], 1][[All, 2]] & /@ {img1,img2}];

oldcols = RGBColor /@ Flatten[ImageData[img1], 1];

Show[
 Graphics[Riffle[oldcols, Point /@ points]],
 Plot[x, {x, 0, 1}, PlotStyle -> Red],
 Frame -> True, 
 FrameLabel -> {"Input Saturation", "Output Saturation"},
 AspectRatio -> 1]

enter image description here

MORE:

You learn something new every day it seems... Today I found the function ChromaticityPlot which can also be used quite nicely to see what image effects do to colours. Notice how the right image shows the blues and yellows have been stretched out but all other colours have been flattened onto a line (as expected from a colour blindness effect):

colourgamutplots

Image@GraphicsRow[
  {ChromaticityPlot[img1, PlotLabel -> "Before"],
  ChromaticityPlot[img2, PlotLabel -> "After"]}, 
 ImageSize -> 512]
$\endgroup$
2
  • $\begingroup$ Thanks so much! I am an absolute beginner, so I have no idea how to change the color points though. Could you help me with this too? It would look a lot prettier with the colors :)) $\endgroup$ Jun 6, 2015 at 11:28
  • $\begingroup$ @AmyNeville I have updated my answer, I'm also no longer using ListPlot but switched to Graphics for speed reasons. $\endgroup$
    – Histograms
    Jun 6, 2015 at 23:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.