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 commentaires

Adam Danz
Adam Danz le 15 Avr 2020
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;
aditya shrivastava
aditya shrivastava le 15 Avr 2020
But ,it is not separating light background on light foregorund.
Adam Danz
Adam Danz le 15 Avr 2020
Have you tried imbinarize()?
Explore the various methods and optional parameters.
aditya shrivastava
aditya shrivastava le 15 Avr 2020
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 le 15 Avr 2020
Modifié(e) : Adam Danz le 17 Avr 2020
See my answer.

Connectez-vous pour commenter.

Réponses (1)

Adam Danz
Adam Danz le 15 Avr 2020
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)));

Produits

Version

R2020a

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by