imwrite from polar surf

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 Comments

That doesn’t look like a MATLAB figure window. Octave, perhaps?
Pete
Pete on 12 Nov 2014
Yes, using octave, but is code similar enough or do I try this in matlab?!
The code you write will likely work in both, but Octave may implement the functions differently, so you may get different results. Do it in MATLAB and see what the results are. That’s the only way you’ll find out. (Are other formats such as .png options in your application?)
Hi Star Strider
I've used tiff, but it reverts back to greyscale (RGB) where I need to keep channels separate. Incidentally, it's ended up that the above pic with the wings is the solution you led to on Monday, and I've now got it working, so the above question is solved for my use, so thanks for your help earlier.
Need to get matlab license sorted, but in the meantime just tried the code with .png and it's come back with the linear wave, and in RGB, so I think I'm going with your initial advice
Rad(Rad < X_max) = (((cos(Rad(Rad < X_max))) + 1) / 2);
Rad(Rad >= X_max) = 0;
Z = Rad;
There were some simple bits I missed with this (changed the Rad<X_max from >, but missed the inside brackets with the cos, so had two opposing arguments and then a change in line for the =0 yields the wings to be black (red=0) which as it's being projected is exactly what I am after. Can't stress how useful your (deleted) solution was!
Thanks again.
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.
? I never delete answers just because no one accepted them or voted for them.

Sign in to comment.

 Accepted Answer

Pete
Pete on 18 Nov 2014
Edited: Pete on 18 Nov 2014

0 votes

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.

More Answers (1)

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');

Categories

Find more on Graphics Performance in Help Center and File Exchange

Asked:

on 12 Nov 2014

Edited:

on 18 Nov 2014

Community Treasure Hunt

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

Start Hunting!