Plotting intensity vs (x,y) in matlab.

4 views (last 30 days)
Apurv Gupta
Apurv Gupta on 28 Jun 2015
Commented: Star Strider on 28 Jun 2015
Hi, I am new to matlab and trying to plot a #D plot of the intensity of a grayscale image vs (x,y) coordinates of a pixel. I wrote the following code, but it doesn't seem to work:
>> f=imread('peppers.png');
>> f=rgb2gray(f);
>> [x,y]=meshgrid(1:1:384,1:1:512);
>> mesh(x,y,f(x,y))
The error reported is:
??? Maximum variable size allowed by the program is exceeded.
Please tell me what is wrong with my code. Also tell me a way to plot the intensity.

Answers (1)

Star Strider
Star Strider on 28 Jun 2015
You do not need the meshgrid call.
This works:
f=imread('peppers.png');
f=rgb2gray(f);
figure(1)
mesh(f)
grid on
  2 Comments
Apurv Gupta
Apurv Gupta on 28 Jun 2015
@Star Strider, can we do it using the mesh grid call?
Star Strider
Star Strider on 28 Jun 2015
You can, but it doesn’t change the plot:
f=imread('peppers.png');
f=rgb2gray(f);
[x,y]=meshgrid(1:1:512, 1:1:384);
figure(1)
mesh(x, y, f)
grid on
I believe your using f(x,y) in your mesh call threw the error, since ‘x’ and ‘y’ are matrices, not vectors.
You don’t need that anyway, because ‘f’ is an array, not a function, and for arrays (in this instance) subscripts are not required.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!