How to scan an image from a specified Row?

2 次查看(过去 30 天)
So below is a function Im using to locate the beginning and end of dark regions on a greyscale image:
function [Ssb Seb]=get_Black_edges(A)
[r c]=size(A);
Ssb=[]; %start Black
Seb=[]; %end Black
for k=1:1:c
x=A(:,k);
a=find(x<26);
mid=floor(mean(a));
i=mid;
while(x(i-1) <26 | x(i-2) <26)
i=i-1;
end
sb=i;
Ssb=[Ssb ; sb];
i=mid;
while(x(i+1) <26 | x(i+2) <26)
i=i+1;
end
eb=i;
Seb=[Seb ; eb];
end
return
Say my image is 886x1024, how to I adjust the code so that the scanning ignores the first 40 rows and only scans the remaining 846?
  2 个评论
Stelios Fanourakis
Stelios Fanourakis 2019-1-25
I get the error
Subscript indices must either be real positive integers or logicals.
Error in efr>get_Black_edges (line 16)
while (x(i-1) <26 | x(i-2) <26)
Error in efr (line 3)
get_Black_edges(A);
>>

请先登录,再进行评论。

采纳的回答

Guillaume
Guillaume 2015-2-10
Your code would be so much easier to understand if you'd use meaningful variable names. It's particularly confusing that you're using x to represent pixel intensities when it's usually used to represent pixel coordinates.
In any case, why can't you just pass the portion of the image of interest to your function? That is instead of:
[blackstartingrows, blackendingrows] = get_Black_edges(someimage);
do
[blackstartingrows, blackendingrows] = get_Black_edges(someimage(41:end, :));
blackstartingrows = blackstartingrows + 40; %readjust to original image coordinates
blackendingrows = blackendingrows + 40;
  6 个评论
Guillaume
Guillaume 2015-2-10
Sean, yes, I didn't test the code, just typed it in my answer, so expect some typos and minor bugs.
I forgot that columnpixels was a column (!). Therefore you need a vertical concatenation (a.k.a semicolons), that is:
blackstartrow = find([Inf; columnpixels(1:meanrow)] > 26 & [Inf; Inf; columnpixels(1:meanrow-1) > 26], 1, 'last') + 1;
and
blackendrow = find([columnpixels(meanrow+1:end); Inf] > 26 & [columnpixels(meanrow+2:end); Inf; Inf], 1, 'first') - 1;
Sean
Sean 2015-2-10
Hi, I got the code working! Thanks a lot again for the help. Much appreciated!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by