【发布时间】:2017-05-03 20:30:04
【问题描述】:
我有一张图像,我想在图表下绘制该图像的任意行的强度。
显然,我无法“自动”使这两个图既对齐(它们共享相同的 x 轴)又不失真。
这是一个使用 MATLAB 附带的 kobi.png 图像的 MWE。对于这个解决方案,我使用了this question 的答案,但这并不是我想要的。原因在代码之后就会清楚。
im = imread('kobi.png'); % read default image
img = rgb2gray(im); % convert to grayscale
y = 600; % select line to "scan"
% plot image with highlithed line
subplot(3,3,4:9);
imagesc(img);
colormap gray
hold on
line([0 size(img,2)], [y y], 'Color', 'r', 'LineWidth', 1.5);
hold off
axis image
photoAxs = gca;
photoAxsRatio = get(photoAxs,'PlotBoxAspectRatio');
% plot intensity of selected row
subplot(3,3,1:3);
r = img(y, :);
plot(r);
axis tight
topAxs = gca;
% adjust ratios
topAxsRatio = photoAxsRatio;
topAxsRatio(2) = photoAxsRatio(2)/2.4; % I want to get rid of this number!
set(topAxs,'PlotBoxAspectRatio', topAxsRatio)
如您所见,这产生了(几乎)预期结果,但有一个硬编码的数字(我链接的答案不同,3.8,而这里是2.4),我想排除。另外,我认为这个数字只提供了一个显然对齐的解决方案,但是对于我轻微的强迫症,这个错误空间让我毛骨悚然!
所以问题是:
是否有任何可行的方法来自动对齐具有相同 x 轴的图形和图像,同时保持图像纵横比?
【问题讨论】:
标签: matlab matlab-figure