Borrar filtros
Borrar filtros

How to scan an image from a specified Row?

2 visualizaciones (últimos 30 días)
Sean
Sean el 10 de Feb. de 2015
Comentada: Stelios Fanourakis el 25 de En. de 2019
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 comentarios
Aatheeswaran M
Aatheeswaran M el 9 de Oct. de 2018
whats A in the function?
Stelios Fanourakis
Stelios Fanourakis el 25 de En. de 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);
>>

Iniciar sesión para comentar.

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by