【问题标题】:How to get an image and a plot to align nicely in Matlab Application Designer如何在 Matlab 应用程序设计器中使图像和绘图很好地对齐
【发布时间】:2021-09-04 14:19:20
【问题描述】:

我正在使用 matlab 应用程序设计器构建一个演示应用程序。 它有两个轴。一个显示图像。另一个显示图像的轮廓,以及轮廓的导数。

在下面的示例中,我有一个 200 列、5 行的图像。

在图像下方,我有一个图像轮廓图和一个导数图。图像配置文件(毫不奇怪)有 200 个元素。我希望 X/Y 图与图像轴一致。

有没有办法控制图像轴,与绘图轴正确对齐?
显然,我可以删除下面的轴(app.AxesImageView,'off')行,然后强制轴打开。但是,这也不起作用,因为轴标签非常不同,所以它们不对齐。我希望它能够灵活地适用于任何尺寸的图像,并且标签尺寸也会影响这一点。

TLDR:是否可以强制绘图或图像中的坐标轴驻留在坐标轴留出用于渲染的区域中的特定位置?

目前渲染图像和绘图的代码是:

w = 5; l = 200;
parms.filterHalfWidth = 20;
img = zeros(w,l);
img(:,ceil(l/2):end)=255;
img = uint8(img);
imagesc(app.AxesImageView,img,[0,255]);
colormap(app.AxesImageView, 'gray');
axis(app.AxesImageView,'off');
title(app.AxesImageView,'Image to find edge');

profile = mean(img,2);
vals    = derivative(profile, parms.filterHalfWidth);
[~, peak] = max(vals);

plot(app.AxesProfiles, profile);
hold(app.AxesProfiles, 'all');
plot(app.AxesProfiles, parms.filterHalfWidth + (1:numel(vals)), vals);
plot(app.AxesProfiles, peak*[1,1], [0,255],'Color','Red','LineWidth',2);
hold(app.AxesProfiles, 'off');

【问题讨论】:

  • 我根本不懂应用设计师。在与所有常规绘图功能相同的经典 GUI 系统中,您可以通过指定绘制数据的矩形来指定轴的位置,标签都在该矩形之外。这使得对齐变得微不足道。
  • 这可能是相关的:mathworks.com/help/matlab/creating_guis/… — 他们基本上建议在 App Designer 中创建一个面板,然后使用 tiledlayout 在里面创建图。
  • @CrisLuengo,平铺布局也会遇到同样的问题。通常,如果我要进行演示,我会手动拉伸东西以使它们对齐。我不清楚如何“通过指定矩形来指定轴的位置......”你能指点我一个文档吗?
  • 坐标区的position 属性。 mathworks.com/help/matlab/ref/…
  • imagesc 应该拉伸图像以适应轴。如果您手动指定轴的位置,这些绘图功能将不会移动它们。如果你不这样做,并使用默认轴,它们的位置将被调整,以便标签都适合窗口。我想这就是你所经历的。您可以通过编程方式“手动拉伸”。

标签: matlab layout matlab-app-designer


【解决方案1】:

我无法重现您的代码,但我用 uifigure 和 ...(主要用于 appdesigner)编写了一段代码 它是完全灵活的 p.s:我不需要工具箱来计算导数,所以我使用了另一个图。

f=uifigure;
f.Units = "normalized"; % essential 
f.Position= [0.3 0.2 0.5 0.7];
f.AutoResizeChildren='off'; % essential 

ax2=uiaxes(f);
ax2.Units = "normalized";
ax2.InnerPosition=[0.1 0.1 0.8 0.4]; %  set Innerposition of axes at your desired position relative to the figureto ensure axes alignment 

ax1=uiaxes(f);
ax1.Units = "normalized";
ax1.InnerPosition=[0.1 0.55 0.8 0.4];



w = 5; l = 200;
parms.filterHalfWidth = 20;
img = zeros(w,l);
img(:,ceil(l/2):end)=255;
img = uint8(img);
imagesc(ax1,img,[0,255]);
colormap(ax1, 'gray');
axis(ax1,'off');
title(ax1,'Image to find edge');

profile = mean(img,2);
vals    = derivative(profile, parms.filterHalfWidth);
[~, peak] = max(vals);

plot(ax2, profile);
hold(ax2, 'all');
plot(ax2, parms.filterHalfWidth + (1:numel(vals)), vals);
plot(ax2, peak*[1,1], [0,255],'Color','Red','LineWidth',2);
hold(ax2, 'off');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-07
    • 1970-01-01
    • 2011-08-11
    • 2013-09-08
    • 2016-10-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多