Matlab,用于图像像素和实际距离的多轴或刻度 [英] matlab, multiple axes or scales for image pixels and real distance

查看:498
本文介绍了Matlab,用于图像像素和实际距离的多轴或刻度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在matlab中,我创建了一个64x64像素的图像,每个像素的值都不同.

In matlab I have created an image of 64x64 pixels, with varying values for each pixel.

但是我也想在情节上显示图像的真实比例.实际大小为1米,我想使用两个x轴刻度和两个y轴刻度来显示像素位置和实际距离.

But I would also like to display the real scale of the image on the plot. The real size is 1 meter and I would like to have two x-axis scales and two y-axis scales to show both pixel positions and real distance.

我该怎么做?

推荐答案

下面是使用我的答案关于SO的上一个问题.这是每个维度上每个像素有64像素的随机图像的输出:

Here is an example using an approach from my answer to a previous question on SO. That's the output for some random image with 64 pixels on each dimension:

以下代码创建一个包含三个轴的正方形figure.宽度和高度手动设置为相等.为了使轴正确对齐,这是必需的.此后,使用imshow在新轴a中绘制实际图像.请注意,我们需要提供'Parent'属性以在特定轴上绘制. 然后,将现实世界的轴添加到底部b和左侧c.它们的'position'属性分别设置为高度或宽度几乎为零.通过查看所使用的定位值,我们可以看到轴a被设置为位于其他两个轴的顶部/右侧.

The following code creates a square figure that contains three axes. The width and height are manually set to be equal. This is needed for the axes to be aligned properly. After this, the actual image is drawn in a new axes a using imshow. Note that we need to provide the 'Parent'-property to draw on a specific axes. Then we add the real world axes on the bottom b and on the left side c. Their 'position'-properties are set to be of almost zero height or width respectively. By looking at the used values for the positioning, we see that axes a is set to be on top/right side of the two other axes.

这是完整的代码:

% some image data
img = rand(64);

% define variables
imgsize = 500;  % size on screen
xreal = 1;      % meter
yreal = 1;      % meter

% create square figure
figure('Position',[0,0,imgsize,imgsize]);

% pixel axes and actual plot
a=axes('Position',[.2 .2 .7 .7]);
set(a,'Units','normalized');
iptsetpref('ImshowAxesVisible','on');
imshow(img,'Parent',a);

% real world axis (below)
b=axes('Position',[.2 .1 .7 1e-12]);
set(b,'Units','normalized');
set(b,'Color','none');
set(b,'xlim',[0 xreal]);

% real world axis (left)
c=axes('Position',[.1 .2 1e-12 .7 ]);
set(c,'Units','normalized');
set(c,'Color','none');
set(c,'ylim',[0 yreal],'YDir','reverse');

% set labels
xlabel(a,'Pixels')
xlabel(b,'Real distance (m)')
ylabel(a,'Pixels');
ylabel(c,'Real distance (m)');
title(a,'A nice title to this noisy image');

这篇关于Matlab,用于图像像素和实际距离的多轴或刻度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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