如何在Matlab warp中使用极轴?

时间:2016-10-13 20:12:01

标签: matlab matlab-figure polar-coordinates

我想在极地演示的半个圆周上的polaraxes对象上使用warp。没有polaraxeswarp

的代码
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'); 

图1电流输出笛卡尔小丑, 图2半圆周上的极小丑但没有极化, 图3故障排除后的第2节输出(EBH,masi)

enter image description here enter image description here

使用polaraxeswarp的伪代码失败;我只能polaraxes使用polarplot,这还不够

hax2=polaraxes('Parent', f2); 
h=warp(x,y,z, img); 

预期输出:半周的极化

2测试EBH的提案

  1. pax = polaraxes,2。loop,3。warp(I)into pax - looping added
  2. 隐式命令视图和轴失败 - 添加了af = figure('Name', 'Do Not Touch');测试代码以显示隐式命令失败的原因
  3. 使用FastPeakFind测试代码以及​​更多测试图像,图像绘制和图像方向修复
  4. 摘要

    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
    

    图3输出有缺陷的雷达轴;试图在帖子How to integrate Java swing black background toolbar into polaraxes?

    中排除故障

    Matlab:2016b
    操作系统:Debian 8.5 64位
    硬件:华硕Zenbook UX303UA

1 个答案:

答案 0 :(得分:1)

这里的想法是在极轴上绘制经过扭曲的图像,每个轴使用不同的轴:

% 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

polar image

主要关注点是polaraxes创建半圆,而warp创建的半椭圆取决于图形的大小,因此您必须正确设置图形大小。