4
$\begingroup$

I would like to plot the gray scale (average of RGB) of an imported image, and combine the graph with the imported image. How can I do that in Mathematica?

Say, the imported image is a 800x5-pixel image. 800 pixels in the horizontal, and 5 pixels in the vertical. I would like to plot the gray scale (average of RGB) of the image across the horizontal direction, and put it on top of the image to provide the visualization of the image plus the gray scale change along the horizontal direction.

Thanks for the help!

$\endgroup$
2
  • 1
    $\begingroup$ Hello. Should it be averaged over each column too? It is good to provide data to work on :) and show what one have tried so far. $\endgroup$
    – Kuba
    Nov 25, 2013 at 10:02
  • 2
    $\begingroup$ "on top of" = further up the screen/page or superimposed/overlaid? $\endgroup$
    – cormullion
    Nov 25, 2013 at 11:18

1 Answer 1

7
$\begingroup$

It's easy if you don't need coordinate axes: Just turn off all padding/margin options, give them the same ImageSize, put them in a Grid, and the plot and the image are automatically aligned.

img = ExampleData[{"TestImage", "Lena"}];

avgX = Mean /@ Mean /@ ImageData[img];
avgY = Mean /@ Mean[ImageData[img]];

Grid[
 {
  {"", ListLinePlot[avgY, Axes -> {True, False}, ImagePadding -> None,
     PlotRangePadding -> None, ImageSize -> 512]},
  {Rotate[
    ListLinePlot[Reverse[avgX], Axes -> {True, False}, 
     ImagePadding -> None, PlotRangePadding -> None, 
     ImageSize -> 512], 90 \[Degree]], Image[img, ImageSize -> 512]}}]

enter image description here

$\endgroup$

Your Answer

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

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