MATLAB:返回大矩阵中两个坐标之间的值数组(对角线)

发布于 2024-10-23 16:46:22 字数 430 浏览 7 评论 0原文

如果我解释原因,这可能更有意义

我有一个逻辑矩阵(103x3488)输出测量人员的照片已经通过边缘检测(1=边缘,0=无边缘)。目的 - 计算标尺上刻度之间的像素距离。问题是,工作人员在中间下垂。

想法:用户输入员工每一端和下垂中点的坐标(使用ginput或其他东西),然后如果可以将这些点之间的边缘提取到数组中,我可以轻松找到边缘的位置。

有什么方法可以以这种方式从矩阵中提取数组吗?

也对其他想法持开放态度,只使用matlab一个月,所以大多数功能对我来说都是未知的。

编辑: 链接到 image

它显示了矩阵的一小部分区域,因此在本例中 1 和 2 是我想在之间进行采样,并且我想返回沿红线出现的点。

干杯

If I explain why, this might make more sense

I have a logical matrix (103x3488) output of a photo of a measuring staff having been run through edge detect (1=edge, 0=noedge). Aim- to calculate the distance in pixels between the graduations on the staff. Problem, staff sags in the middle.

Idea: User inputs co-ordinates (using ginput or something) of each end of staff and the midpoint of the sag, then if the edges between these points can be extracted into arrays I can easily find the locations of the edges.

Any way of extracting an array from a matrix in this manner?

Also open to other ideas, only been using matlab for a month, so most functions are unknown to me.

edit:
Link to image

It shows a small area of the matrix, so in this example 1 and 2 are the points I want to sample between, and I'd want to return the points that occur along the red line.

Cheers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青衫儰鉨ミ守葔 2024-10-30 16:46:22

试试这个

dat=imread('83zlP.png');

figure(1)
pcolor(double(dat))
shading flat
axis equal

% get the line ends
gi=floor(ginput(2))
x=gi(:,1);
y=gi(:,2);

xl=min(x):max(x); % line pixel x coords
yl=floor(interp1(x,y,xl)); % line pixel y coords


pdat=nan(length(xl),1);
for i=1:length(xl)
    pdat(i)=dat(yl(i),xl(i));
end

figure(2)
plot(1:length(xl),pdat)

peaks=find(pdat>40); % threshhold for peak detection
bigpeak=peaks(diff(peaks)>10); % threshold for selecting only edge of peak

hold all
plot(xl(bigpeak),pdat(bigpeak),'x')
meanspacex=mean(diff(xl(bigpeak)));
meanspacey=mean(diff(yl(bigpeak)));
meanspace=sqrt(meanspacex^2+meanspacey^2);

矩阵 pdat 给出沿您选择的线的像素。 meanspace 是以像素为单位的边缘间距。根据图像的不同,阈值可能需要调整。

Try this

dat=imread('83zlP.png');

figure(1)
pcolor(double(dat))
shading flat
axis equal

% get the line ends
gi=floor(ginput(2))
x=gi(:,1);
y=gi(:,2);

xl=min(x):max(x); % line pixel x coords
yl=floor(interp1(x,y,xl)); % line pixel y coords


pdat=nan(length(xl),1);
for i=1:length(xl)
    pdat(i)=dat(yl(i),xl(i));
end

figure(2)
plot(1:length(xl),pdat)

peaks=find(pdat>40); % threshhold for peak detection
bigpeak=peaks(diff(peaks)>10); % threshold for selecting only edge of peak

hold all
plot(xl(bigpeak),pdat(bigpeak),'x')
meanspacex=mean(diff(xl(bigpeak)));
meanspacey=mean(diff(yl(bigpeak)));
meanspace=sqrt(meanspacex^2+meanspacey^2);

The matrix pdat gives the pixels along the line you have selected. The meanspace is edge spacing in pixel units. The thresholds might need fiddling with, depending on the image.

辞旧 2024-10-30 16:46:22

看到图片后,我不确定你所说的“下垂”发生在哪里。图像已旋转,但您可以使用 imrotate。需要旋转的程度应该足够容易;只需输入坐标 AB 并使用反正切求出相对于 0 度的角度偏移量。

关于这些点,一旦直线对齐,您所需要做的就是在图像矩阵中指定一行(它将是一个 1 x 3448 向量)并使用 find 获取非零向量索引。由于旋转函数可能对像素进行了某种插值,因此每“行”可能会获得多个索引,但它们可以被识别为连续数字,并且您可以对它们进行平均以获得近似值。

After seeing the image, I'm not sure where the "sagging" you're referring to is taking place. The image is rotated, but you can fix that using imrotate. The degree to which it needs to be rotated should be easy enough; just input the coordinates A and B and use the inverse tangent to find the angle offset from 0 degrees.

Regarding the points, once it's aligned straight, all you need to do is specify a row in the image matrix (it would be a 1 x 3448 vector) and use find to get non-zero vector indexes. As the rotate function may have interpolated the pixels somewhat, you may get more than one index per "line", but they'll be identifiable as being consecutive numbers, and you can just average them to get an approximate value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文