I need to create a random surface (which I created using peaks
) and save it under certain lighting conditions (which I added using light
). The plot itself is created using surf
. Then I set the required viewing angle using view(2)
.
[X,Y] = meshgrid(-2:.025:2);
Z = peaks(X,Y);
h = surf(X,Y,Z);
% Necessary for task
h.AmbientStrength = 0.;
h.SpecularStrength = 0.;
h.DiffuseStrength = 1.;
h.BackFaceLighting = 'unlit';
h.FaceLighting = 'gouraud';
view(2);
l = light('Position',[-2, -2, 50],'Style','local','Color',[1 1 1]);
The Z matrix has dimensions 161x161. I want to save a 161x161 matrix that corresponds to the lighting/shading in the figure. Any ideas?
A sample generated plot:
Edit: I do intend to work with the saved image. The overall goal is to perform photometric stereo (something on these lines). Hence, I need to generate several images of the surface under different lighting conditions.
PS: Thanks for h.LineStyle='none';
I assume you want this for other reasons than processing the data, as getting data from a plot is the worst case. Assuming too that you forgot h.LineStyle='none';
, else you will just not see them.
This code will approximately do the job:
% get the frame plotted in the figure
test=getframe(gca);
% the size of the image will be arbitrary, depends on the size of the figure on screen and your screen resolution. Lets interpolate, so we can get the values at the exact points you want. I use the same bounds as in your description
[Xi,Yi]=meshgrid(linspace(-2,2,size(test.cdata,2)),linspace(-2,2,size(test.cdata,1)));
% Only works if grayscale, repeat x3 for each dimension if you have color
img=interp2(Xi,Yi,double(test.cdata(:,:,1)),X,Y)/255;
figure;imshow(img);