![](/img/trans.png)
[英]How to find the first zero column (or last non-zero column) in an array, greater than a certain column value
[英]How to find the first and last non-zero values for column and row in an image?
我遇到了麻烦,因为我有这张图片,我想做的就是使用非黑色像素。 但是我必须找到第一个和最后一个非零值来定义要工作的边界,问题是我可以找到第一个非零值(rowandcolumn),但是在该列的最后一个出现值1799,并且我的图像是499x631x3 uint8,应该是533。是什么问题?
我的代码如下:
%Find where the image begins and starts
[r_min, c_min]=find(movingRegistered(:),1,'first');
[r_max, c_max]=find(movingRegistered(:,:),1,'last');
图片链接https://www.dropbox.com/s/6fkwi3xbicwzonz/registered%20image.png?dl=0
要查找与每一列的第一个非零元素相对应的行索引:
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
并将代码应用于该代码:
[r_min, c_min]=find(A2,1,'first');
[r_max, c_max]=find(A2,1,'last');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.