imwrite from polar surf
1 view (last 30 days)
Show older comments
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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/146085/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/146086/image.png)
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"):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/146087/image.png)
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 Comments
Star Strider
on 12 Nov 2014
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
on 13 Nov 2014
? I never delete answers just because no one accepted them or voted for them.
Accepted Answer
More Answers (1)
Kelly Kearney
on 12 Nov 2014
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');
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!