Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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
1  
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
2  
"on top of" = further up the screen/page or superimposed/overlaid? –  cormullion Nov 25 '13 at 11:18

1 Answer 1

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

share|improve this answer

Your Answer

 
discard

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.