I have to genarate a binary image of an ellipse having its inside as white while outside as black.But , the problem i am facing is that whenever the foreground and background of my input ellipse is either light or dark then the binary image becomes all black or all white.

댓글 수: 6

Adam Danz
Adam Danz 2020년 4월 15일
What function and parameter values are you using to create the binary image?
redChannel = imag(:, :, 1);
greenChannel = imag(:, :, 2);
blueChannel = imag(:, :, 3);
maxGrayLevelR = max(redChannel(:));
minGrayLevelR = min(redChannel(:));
maxGrayLevelG = max(greenChannel(:));
minGrayLevelG = min(greenChannel(:));
maxGrayLevelB = max(blueChannel(:));
minGrayLevelB = min(blueChannel(:));
%Convert percentage threshold into an actual number.
thresholdLevelR = minGrayLevelR + 0.5*(maxGrayLevelR - minGrayLevelR);
thresholdLevelG = minGrayLevelG + 0.5*(maxGrayLevelG - minGrayLevelG);
thresholdLevelB = minGrayLevelB + 0.5*(maxGrayLevelB - minGrayLevelB);
image_binary = redChannel > (thresholdLevelR,thresholdLevelG,thresholdLevelB)/3;
image_binary = greenChannel > max(thresholdLevelR,thresholdLevelG,thresholdLevelB)/3;
image_binary = blueChannel > max(thresholdLevelR,thresholdLevelG,thresholdLevelB)/3;
But ,it is not separating light background on light foregorund.
Adam Danz
Adam Danz 2020년 4월 15일
Have you tried imbinarize()?
Explore the various methods and optional parameters.
this function works very well.But, i specifically want the foreground of an image to be white and background to be black.So, i am using not(image) function. Is there any way by which i can know if the center pixel of the image is black or white. If it is white then i wont use not function .Otherwise,i will use not function.
Adam Danz
Adam Danz 2020년 4월 15일
편집: Adam Danz 2020년 4월 17일
See my answer.

댓글을 달려면 로그인하십시오.

답변 (1개)

Adam Danz
Adam Danz 2020년 4월 15일

0 개 추천

Use imbinarize(). The output can be used to determine whether the center pixel is black (0) or white (1).
BW = imbinarize(. . .)
centerPixelValue = BW(round(size(BW,1)/2),(round(size(BW,2)/2)));

카테고리

도움말 센터File Exchange에서 Image Segmentation and Analysis에 대해 자세히 알아보기

제품

릴리스

R2020a

태그

질문:

2020년 4월 15일

편집:

2020년 4월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by