Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|improve this question
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. – Kuba Nov 25 '13 at 10:02
"on top of" = further up the screen/page or superimposed/overlaid? – cormullion Nov 25 '13 at 11:18

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]];

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

enter image description here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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