如何找到图像中列和行的第一个和最后一个非零值?

编程入门 行业动态 更新时间:2024-10-25 08:24:59
本文介绍了如何找到图像中列和行的第一个和最后一个非零值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我遇到了麻烦,因为我有这张图片,我想做的只是处理不是黑色的像素.但是我必须找到第一个和最后一个非零值来定义边界,我会工作,问题是我可以找到第一个非零值(rowandcolumn),但在列的最后一个出现值 1799,我的图像是 499x631x3 uint8 ,应该是 533 有什么问题??

I'm having trouble, because I have this image, what I want to do is just work with the pixels that aren't black. But I have to find the first and last nonzero values to define the boundaries were I will work, the problem is that I can find the first nonzero values(rowandcolumn), but in the last for the column appears the value 1799,and my image is 499x631x3 uint8 , and it should be 533. What is the problem??

我的代码如下:

%Find where the image begins and starts [r_min, c_min]=find(movingRegistered(:),1,'first'); [r_max, c_max]=find(movingRegistered(:,:),1,'last');

图片链接 www.dropbox/s/6fkwi3xbicwzonz/registered%20image.png?dl=0

推荐答案

找到每列的第一个个非零元素对应的行索引:

To find the row index corresponding to the first nonzero element of each column:

A2 = logical(any(A,3)); %// reduce to 2D array, which equals 0 if all three color %// components are 0, and 1 otherwise [~, row_first] = max(A2,[],1); %// the second output of `max` gives the row index of %// the first maximum within each column

要找到最后一个:

[~, row_last] = max(flipud(A2),[],1); %// matrix upside down to find last, not first row_last = size(A,1)-row_last+1; %// correct because matrix was upside down

要找到 线性索引 意义上的第一个和最后一个:如上计算 A2 并将您的代码应用于该:

To find the first and last in linear indexing sense: compute A2 as above and apply your code to that:

[r_min, c_min]=find(A2,1,'first'); [r_max, c_max]=find(A2,1,'last');

更多推荐

如何找到图像中列和行的第一个和最后一个非零值?

本文发布于:2023-10-24 08:36:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1523458.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:第一个   图像   非零值

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!