Filter löschen
Filter löschen

How to scan an image from a specified Row?

2 Ansichten (letzte 30 Tage)
Sean
Sean am 10 Feb. 2015
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 Kommentare
Aatheeswaran M
Aatheeswaran M am 9 Okt. 2018
whats A in the function?
Stelios Fanourakis
Stelios Fanourakis am 25 Jan. 2019
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);
>>

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Guillaume
Guillaume am 10 Feb. 2015
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 Kommentare
Guillaume
Guillaume am 10 Feb. 2015
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 am 10 Feb. 2015
Hi, I got the code working! Thanks a lot again for the help. Much appreciated!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by