Fastest way to find the row number containing the most amount of black pixels in a gray-scale image?

조회 수: 1 (최근 30일)
The way i did it is by looping over the matrix and counting number of black pixels in each row then comparing them ,the criteria i decided to go with for determing if a pixel is black is if the value of the pixel element is 20 or lower (i relied on this image to see which counts as a pure black pixel image).
is there a faster (less time complexity) way to do this ?
and are there any built-in functions in matlab that already do this?
row_blackPix = 0; % Number of the row with highest number of black pixels
black_count = 0; % Black pixel counter for a row
for i=1 : rows
temp_blackCount = 0;
for j=1 : cols
if image(i,j) <= 20
temp_blackCount = temp_blackCount + 1; % Get number of blacks in row i
end
end
if temp_blackCount > black_count
black_count=temp_blackCount;
row_blackPix = i;
end
end

채택된 답변

James Tursa
James Tursa 2020년 4월 2일
[~,row_blackPix] = max(sum(image <= 20,2))

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by