4
$\begingroup$

Is there a way I can show the three ImageHistogram[]'s in different colours?

Show[ ImageHistogram[edit[[1]], Appearance -> "Separated"], ImageHistogram[edit[[2]], Appearance -> "Separated"], ImageHistogram[edit[[3]], Appearance -> "Separated"], ]

enter image description here

$\endgroup$
3
  • $\begingroup$ In theory, you should be able to use something like PlotStyle -> Array[ColorData[61], 3], but it does not seem to work here... $\endgroup$ – J. M.'s ennui Feb 4 at 11:09
  • $\begingroup$ @J.M. ChartStyle doesn't seem to work either $\endgroup$ – Teabelly Feb 4 at 11:40
  • 1
    $\begingroup$ Someone else would need to confirm, but I think this is worth reporting to Support. $\endgroup$ – J. M.'s ennui Feb 4 at 11:45
3
$\begingroup$

The second suggestion by @kglr seems like a natural approach (which ensures the result still has Head Graphics and not Image).

Another solution would be to manually make a Histogram for each channel:

GraphicsColumn[
MapThread[Histogram[Flatten[ImageData[#1]],ChartStyle->#2]&,{ColorSeparate[edit1,"RGB"],Array[ColorData[61],3]}]
]

However, this also serves as more of an extended comment to highlight a curious behaviour (as hinted by the comments above). Note that ImageHistogram clearly has special logic for handling RGB images. This can be seen by comparing a 4-channel image ColorSpace, e.g. CMYK:

With[{cmyk = ColorCombine[ColorSeparate[edit1, "CMYK"], "CMYK"]},
 ImageHistogram[cmyk, Appearance -> "Separated"]]

enter image description here

Curiously, adding PlotStyle -> Array[ColorData[57], 4] also fails on this example, returning all histograms with the last specified color.
Perhaps this is indeed worth reporting to WR Support.

$\endgroup$
3
$\begingroup$

You can use ColorReplace to replace {Red, Green, Blue} with desired colors:

ClearAll[colReplace]
colReplace = ColorReplace[ImageHistogram[#, Appearance -> "Separated", ImageSize -> Large], 
    Thread[{Red, Green, Blue} -> #2]] &;

Examples:

edit1 = Import["https://i.stack.imgur.com/jUr0a.png"]

enter image description here

edit2 = ImageAdjust[edit, .1];

edit3 = ColorBalance[edit, .1];

Row[{edit1, edit2, edit3}, Spacer[10]]

enter image description here

colReplace[edit1, ColorData[97] /@ {1, 2, 3}]

enter image description here

Show[MapThread[colReplace, 
  {{edit1, edit2, edit3}, Partition[ColorData[97] /@ Range[9], 3]}]]

enter image description here

You can also use ReplaceAll to get the same results:

ClearAll[replaceColors]
replaceColors = ReplaceAll[Thread[{Red, Green, Blue} -> #2]]@
    ImageHistogram[#, Appearance -> "Separated", ImageSize -> Large] &;
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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