how to check the value 0 in row (200 till 240) ,whole column is true?

1 view (last 30 days)
i have binary image (320 columns 240 rows).
i want to check the value of row(200-240) is all white(0).

Answers (1)

Walter Roberson
Walter Roberson on 5 May 2015
subimage = YourImage(200:240, :);
if all(subimage(:) == 0)
disp('rows were all pure white');
else
disp('there was at least one pixel somewhere in one of the rows that was not pure white');
end
  2 Comments
Walter Roberson
Walter Roberson on 5 May 2015
Untested code:
rows_of_interest = 200:240;
subimage = YourImage(rows_of_interest, :);
rowmax = max(subimage,2);
row_is_all_blank = rowmax == 0;
if all(row_is_all_blank)
disp('all rows were all pure white');
else
disp('Some rows had non white.');
disp('row# contains');
rows_with_nonblank = rows_of_interest(~row_is_all_blank);
max_in_nonblank_row = rowmax(~row_is_all_blank);
fprintf(' %3d %3d\n', [rows_with_nonblank(:), max_in_nonblank_row(:)].' );
end
Keep in mind that your question was not to figure out which rows were all white: your question was to figure out whether all of that portion of the image is white, where you defined white as strictly being equal to 0, not (for example) the very next shade up.
Also keep in mind that when it comes to images, "white" is associated with the maximum value, and the value associated with 0 is typically "black". This code uses your definition of white as being 0 rather than as white being the maximum value.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!