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

| improve this answer | |
$\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.