Detect black pixels in arbitrary region of a an image

5 次查看(过去 30 天)
I want help to detecting black pixels in arbitrary region of a an image in matlab , i want to detect black line on right of below image and If the new image has a black line on the right then let the user know about the black line in the image.
  1 个评论
Image Analyst
Image Analyst 2020-1-5
What do you mean by "below right"? Do you mean the last line of the image, and on the right half? If so, that contradicts "arbitrary region" which seems to indicate that it could be anywhere in the image.
Is there any requirement on the size of the line region? Or is one pixel big enough?
What do you mean by "below image"? The image is everything. Even the bottom of the image is in the image, not below it. Do you have some kind of medical image screenshot where you have the image in the center and then black surround with some kind of text annotation there? You forgot to attach images where you show where there ARE and ARE NOT a black line region that you want to detect. Please attach one image of each type.

请先登录,再进行评论。

回答(1 个)

awezmm
awezmm 2020-1-5
编辑:awezmm 2020-1-5
if img is the variable name of your original rgb image:
redChannel = img(:,:,1);
greenChannel = img(:,:,2);
blueChannel = img(:,:,3);
% black pixels are where red channel and green channel and blue channel in an rgb image are 0;
blackpixelsmask = redChannel == 0 & greenChannel == 0 & blueChannel == 0;
% show binary image where the black pixels were
imshow(blackpixelsmask)
% check and alert if any pixels where black by checking binary image for any '1' elements
if any(blackpixelsmask(:))
% alert user
disp("black pixels in image found!")
end

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by