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?
aditya shrivastava
aditya shrivastava 2020 年 4 月 15 日
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;
aditya shrivastava
aditya shrivastava 2020 年 4 月 15 日
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.
aditya shrivastava
aditya shrivastava 2020 年 4 月 15 日
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)));

カテゴリ

製品

リリース

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