I want to use polaraxes
on the warp
object on the half circumference of the polar presentation. Code without polaraxes
but with warp
close all; clear all; clc;
% https://stackoverflow.com/a/7586650/54964
load clown;
img = ind2rgb(X,map);
[h,w,~] = size(img);
s = min(h,w)/2;
[rho,theta] = meshgrid(linspace(0,s-1,s), linspace(0,pi));
[x,y] = pol2cart(theta, rho);
z = zeros(size(x));
f1=figure();
hax=axes('Parent', f1);
imagesc(img, 'Parent', hax);
box(hax, 'off');
axis(hax, 'off');
set(hax, 'yTickLabel', []);
set(hax, 'xTickLabel', []); % for polar presentation
set(hax, 'Ticklength', [0 0]); % https://stackoverflow.com/a/15529630/54964
f2=figure();
hax2=axes('Parent', f2);
h=warp(x, y, z, img);
view(hax2, 2);
axis(hax2, 'square');
axis(hax2, 'tight');
Fig.1 Current output Cartesian clown, Fig. 2 Polar clown on half circumference but without polaraxes, Fig. 3 Output of Section 2 after troubleshoots (EBH, masi)
Pseudocode unsuccessfully with polaraxes
and warp
; I can only do polaraxes
with polarplot
which is not enough here
hax2=polaraxes('Parent', f2);
h=warp(x,y,z, img);
Expected output: polaraxes on the half circumference
2 Testing EBH's proposals
- pax=polaraxes, 2. loop, 3. warp(I) into pax - looping added
- Implicit commands view and axis fail - test code added
af = figure('Name', 'Do Not Touch');
to show why the implicit commands fail - Test code with
FastPeakFind
and more test images, Image drawing and Image orientation fixes
Summary
close all; clear all; clc;
fp=figure('Name', 'Test', ...
'Position',[200 200 851 404],'Resize','off'); % only half circle in polaraxes although warp can do eclipses
ThetaTicks = 0*pi:pi/10:1*pi;
pax = polaraxes( 'ThetaAxisUnits', 'radians', ...
'ThetaLim',[min(ThetaTicks) max(ThetaTicks)],...
'Color','none',...
'GridAlpha',1,...
'GridColor',[1 1 1],...
'ThetaTick',ThetaTicks, ...
'Parent', fp);
af = figure('Name', 'Do Not Touch');
testImages = { 'peppers.png', 'bag.png', 'glass.png', 'circles.png', 'fabric.png', 'testpat1.png', 'office_1.jpg', ...
'onion.png', 'pears.png', 'rice.png', 'westconcordorthophoto.png', 'coins.png' };
imax = axes('Parent', fp, 'Visible', 'off');
for testImage=testImages
I = imread(testImage{1,1});
angleRadians=-pi;
[x, y, z]=makePolar(I, angleRadians);
fp=figure(fp); % put this every time you switch between figures to go back to 'fp'
imax.Children = warp(x, y, z, I);
set(imax,'view',[-180 -90],'Visible','off')
axis(imax,'tight');
pause(1);
% https://stackoverflow.com/a/40006051/54964
Ip=getframe(pax);
Ip=Ip.cdata;
imwrite(Ip, '/tmp/testMasi.png', 'png');
assert(isa(Ip, 'uint8'), sprintf('I is not uint8 but %s', class(Ip)));
p=FastPeakFind(Ip);
imagesc(Ip, 'Parent', imax);
axis(imax, 'off');
hold(imax, 'on');
plot(p(1:2:end),p(2:2:end),'r+', 'Parent', imax);
hold(imax, 'off');
drawnow;
end
Output in Fig. 3 where buggy radar axis; trying to troubleshoot it in the thread How to integrate Java swing black background toolbar into polaraxes?
Matlab: 2016b
OS: Debian 8.5 64 bit
Hardware: Asus Zenbook UX303UA
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.
来源:https://stackoverflow.com/questions/40030096/how-to-use-polar-axes-with-matlab-warp