Detect black pixels in arbitrary region of a an image

조회 수: 10 (최근 30일)
Mary Baratzadeh
Mary Baratzadeh 2020년 1월 5일
댓글: Image Analyst 2020년 1월 5일
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

Community Treasure Hunt

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

Start Hunting!

Translated by