matlab - 如何在 Matlab 应用程序设计器中使图像和绘图很好地对齐
问题描述
我正在使用 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');
解决方案
我无法重现您的代码,但我用 uifigure 编写了一段代码,并且......(这是 appdesigner 中主要使用的)它是完全灵活的 ps:我不需要工具箱来计算导数,所以我使用了另一个阴谋。
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');
推荐阅读
- flutter - 如何在 Flutter 中使用媒体查询添加填充?
- python - 将 Python 脚本导入测试时出现“没有名为 google.cloud 的模块”错误,但直接运行时不会出现
- python - Python代码返回错误取决于IDE
- matlab - ifourier 命令没有给出预期的结果?
- nginx - NGINX 卡在服务器上的 HTTPS 重定向
- c# - [BotFrameWork]:如何在使用V4开发的C# Webchat bot中同时有文本提示和选择提示?
- python - 如何使用 NLTK 从 CSV 文件中删除停用词?
- encryption - 用户如何证明特定帐户有权访问 BigQuery?(AEAD 加密和授权视图)
- python - 我们可以使用 PysimpleGUI 创建语音到文本 GUI 吗?
- google-apps-script - 根据 Google 表格中的多个条件创建动态下拉列表