How to use polar axes with Matlab warp?

戏子无情 提交于 2019-11-28 13:14:58

The idea here is plotting the warpped image on a polar axes, using different axes for each:

% first we create a figure with defined size, because 'polaraxes' are always
% half a circle, and we need to keep the output surface of 'warp' in this
% shape, and not in an ellipse. Switching off the 'Resize' is just an option
fp = figure('Name', 'Test', ...
    'Position',[200 200 851 404],'Resize','off'); 
% Then we define the polaraxes:
ThetaTicks = 0:pi/10:pi; % for the opposite side use pi:pi/10:2*pi
pax = polaraxes( 'ThetaAxisUnits', 'radians', ...
    'ThetaLim',[min(ThetaTicks) max(ThetaTicks)],...
    'ThetaTick',ThetaTicks, ...
    'Parent', fp);

testImages = {'peppers.png', 'bag.png', 'glass.png', 'circles.png',...
    'fabric.png', 'testpat1.png', 'office_1.jpg', 'pears.png',...
    'rice.png', 'westconcordorthophoto.png', 'coins.png'};

figure(fp) %<-- put this every time you want to bring the focuse back to 'fp'
imax = axes('Parent',fp); % this will be the axes for the image
for testImage = testImages
    I = imread(testImage{1,1});
    angleRadians = -pi; % for the opposite side use pi
    [h,w,~] = size(I);
    s = min(h,w)/2;
    [rho,theta] = meshgrid(linspace(0,s-1,s), linspace(0,angleRadians,s));
    [x,y] = pol2cart(theta, rho);
    z = zeros(size(x));
    imax.Children = warp(x, y, z, I); % display the image in 3D surface
    set(imax,'view',[0 90],'Visible','off'); % rotate to a top view and hide the axes
    axis(imax,'tight') % calibrate the image to the figure size
    drawnow;
    pause(0.5)
end

The main cavet is polaraxes creates half circle, while the warp creates half ellipse that depends on the size of the figure, so you have to set correctly the figure size.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!