imwrite from polar surf

1 次查看(过去 30 天)
Pete
Pete 2014-11-12
编辑: Pete 2014-11-18
Hi all,
I'm looking to write image from a polar-plot which is essentially a sine/cosine plot, rotationally symmetric, and have it output as the 'surf' is displayed. I'm only using red channel, and the surf function plots it correctly, but imwrite converts it to a linear sinusoidal plot.
Here's the output surf and imwrite bmp (need bmp as it keeps the red only - tiff changes it to greyscale)
As you can see, the bmp appears to be as a function of Z,R, when I would like it to be XYZ. I can plot in XYZ using the surf without polar system, but I then want the image to be round (missing the "wings"):
Help would be appreciated as this is really my first program set.
Code used is attached for each: Polar.m is the round surf, but the linear image; Cartes.m is the XYZ plot, but the image with wings (codes have been edited so as to work easier, but functionality remains same).
Many thanks everyone,
Pete.
  6 个评论
Star Strider
Star Strider 2014-11-12
My pleasure!
I deleted it because you didn’t accept it or vote it. A lot of us here do that, because it prevents ‘answer pollution’. I didn’t keep that particular code in the file I use to test Answers I post here because it wasn’t generally applicable (so unlikely to be useful elsewhere). I’m glad you found it useful.
Image Analyst
Image Analyst 2014-11-13
? I never delete answers just because no one accepted them or voted for them.

请先登录,再进行评论。

采纳的回答

Pete
Pete 2014-11-18
编辑:Pete 2014-11-18
I've ended up using the latter function (Cartesian), and then applying a cropping mask for the final result. I'm generating a Fresnel Zone Plate for small pixel device, so started from scratch and this is now completed with various input options and a round single channel (from RGB) zone plate being generated. Thanks for the help everyone - it's through a few questions that the code is working as required.

更多回答(1 个)

Kelly Kearney
Kelly Kearney 2014-11-12
If your polar plot already appears as you need it to, it might be easiest to simply steal the data from the plot rather than calculating it. That way you don't have to deal with interpolating white pixels to the region outside your plot (the wings).
% Calculations
NumberWaves = 5;
Each_Division = 0.1;
rmax = NumberWaves * (2 * pi) ;
r = linspace(0, rmax, 100);
theta = linspace(0, 2*pi, 100);
[r,theta] = meshgrid(r, theta);
z = (sin(r) + 1)./2;
x = r .* cos(theta);
y = r .* sin(theta);
% Plot as you want your final image file to appear
hf = figure('units','pixels', 'position', [10 10 300 300]); % size appropriately
ha = axes('position', [0 0 1 1]);
pcolor(x,y,z);
shading flat;
cmap = [linspace(0,1,101)' zeros(101,2)];
colormap(cmap);
set(ha, 'xtick', [], 'ytick', []);
% Grab image data from the axis and save it
im = frame2im(getframe(ha));
imwrite(im, 'test.png');

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by