如何将Matlab曲面的曲面贴图输出传递给export_fig? [英] How to pass surface map output of Matlab warp to export_fig?

查看:101
本文介绍了如何将Matlab曲面的曲面贴图输出传递给export_fig?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经线对象位于极坐标中,我无法用axes进行分配,因此无法将表面对象直接传递给export_fig. 生成图像的代码,但我无法为export_fig捕获它,如下所示,因为它没有句柄

Warp object is in polar coordinates which I cannot assign with axes so I cannot pass the surface object directly to export_fig. Code which generates the image but I cannot catch it for export_fig as shown below because no handle for it

clear all; close all; clc; 
img=imread('peppers.png'); 
% http://stackoverflow.com/a/7586650/54964
[h,w,~] = size(img);
s = min(h,w)/2;
[rho,theta] = meshgrid(linspace(0,s-1,s), linspace(0,2*pi,s));
[x,y] = pol2cart(theta, rho);
z = zeros(size(x));
figure;
h=warp(x, y, z, img); 
view(2), axis square tight off

export_fig接受图形和语法处理程序,但不接受表面图,因此我无法将h传递给函数

The export_fig accepts the figure and syntax handlers but not the surface map so I cannot pass h to the function

% https://github.com/altmany/export_fig
export_fig(figure_handle, filename);
export_fig(axes_handle, filename);

示例代码因提案而失败

clear all; close all; clc; 

fp=figure();
hax_polar=axes(fp);

f_do_not_touch=figure('Name', 'Do not touch'); 

index=0;
I=imread('peppers.png'); 
while index < 7
    [x, y, z]=makePolar(I);
    h=warp(x, y, z, I);
    view(2), axis square tight off
    %
    [Ip, alpha] = export_fig('/home/masi/Images/masi', '-png', '-native', '-q101', '-a1', '-m1', '-RGB', '-nofontswap',  '-transparent', '-dpng', ...
        hax_polar);
    p=FastPeakFind(Ip); % https://se.mathworks.com/matlabcentral/fileexchange/37388-fast-2d-peak-finder
    imagesc(hax_polar, Ip); hold on
    plot(hax_polar, p(1:2:end),p(2:2:end),'r+')
    hold off
    index=index+1;
end

function [x, y, z]=makePolar(img)
% http://stackoverflow.com/a/7586650/54964
[h,w,~] = size(img);
s = min(h,w)/2;
[rho,theta] = meshgrid(linspace(0,s-1,s), linspace(0,2*pi,s));
[x,y] = pol2cart(theta, rho);
z = zeros(size(x));
end

图. 1输出图Do not touch获取内容且主图因隐式声明而中断

Fig. 1 Output where the figure Do not touch gets content and the main figure breaks because implicit declarations

Matlab:2016a
操作系统:Debian 8.5 64位

Matlab: 2016a
OS: Debian 8.5 64 bit

推荐答案

几个问题,如果我们解决它们,就会得到您期望的结果.

A couple of issues that if we fix them we get what you expect.

  1. 由于warp不接受'Parent'属性,因此需要确保要在其上显示的axes是当前轴.您可以使用axes函数强制执行此操作,并将轴手柄传递给它.

  1. Since warp doesn't accept a 'Parent' property, you need to be sure that the axes on which you want it to appear is the current axes. You can force this by using the axes function and pass the axes handle to it.

axes(hax_polar)
h = warp(x, y, z, I);

% Explicitly modify this axes
view(hax_polar, 2)
axis(hax_polar, 'square')
axis(hax_polar, 'tight')
axis(hax_polar, 'off')

  • 在调用imagescplot时,使用'Parent'属性值对而不是将父级指定为第一个输入要清晰得多(并且在整个系统中更可靠地工作).

  • When calling imagesc and plot it is much clearer (and works more reliably across systems) to use the 'Parent' property value pair rather than specifying the parent as the first input.

    imagesc(Ip, 'Parent', hax_polar);
    plot(p(1:2:end), p(2:2:end), 'r+', 'Parent', hax_polar);
    hold(hax_polar, 'off')
    

  • 修复所有这些问题后,我们将获得一张看起来正确的图像

    Once we fix all of these things, we get an image that looks like what appears to be correct

    clear all; close all; clc;
    
    fp=figure();
    hax_polar=axes('Parent', fp);
    
    f_do_not_touch=figure('Name', 'Do not touch');
    
    index=0;
    I=imread('peppers.png');
    while index < 7
        [x, y, z]=makePolar(I);
    
        axes(hax_polar)
    
        h=warp(x, y, z, I);
    
        % Different
        view(hax_polar, 2);
        axis(hax_polar, 'square')
        axis(hax_polar, 'tight')
        axis(hax_polar, 'off')
        %
        [Ip, alpha] = export_fig('test.png', '-png', '-native', '-q101', '-a1', '-m1', '-RGB', '-nofontswap',  '-transparent', '-dpng', ...
            hax_polar);
        p=FastPeakFind(Ip); % https://se.mathworks.com/matlabcentral/fileexchange/37388-fast-2d-peak-finder
        imagesc(Ip, 'Parent', hax_polar); hold on
        plot(p(1:2:end),p(2:2:end),'r+', 'Parent', hax_polar)
        hold(hax_polar, 'off')
        index=index+1;
    end
    
    function [x, y, z]=makePolar(img)
    % http://stackoverflow.com/a/7586650/54964
    [h,w,~] = size(img);
    s = min(h,w)/2;
    [rho,theta] = meshgrid(linspace(0,s-1,s), linspace(0,2*pi,s));
    [x,y] = pol2cart(theta, rho);
    z = zeros(size(x));
    

    这篇关于如何将Matlab曲面的曲面贴图输出传递给export_fig?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆