Making a saved plot image into a two-dimensional image for imbinarize?

Hello, I'm using imbinarize function to transform an image into 0 and 1. The image I want to input by using imread is 256x256x3, but imbinarize asks for a two-dimension value. How can I convert this saved image into a two-dimensional value?

 Réponse acceptée

You have an RGB image so you can either use rgb2gray()
grayImage = rgb2gray(rgbImage);
or extract one of the color channels
grayImage = rgbImage(:, :, 1); % Extract red channel.
grayImage = rgbImage(:, :, 2); % Extract green channel.
grayImage = rgbImage(:, :, 3); % Extract blue channel.

4 commentaires

Thank you for the reply. I did as mentioned and added the function
rgbImage = rgb2ind(rgbImage,2)
Is that correct?
No. Why did you do that? Use one of the methods I told you to. What you did was to essentially binarize/posterize the data at some unknown threshold - similar to imbinarize() is going to do for you, but you did it first, and not only did it, but did it in an unpredictable way.
First get a gray level image like I showed you and then call imbinarize() on your gray scale image (not your indexed image that you created) to produce a proper binary image.
Oh yes. My mistake. Actually I have another question. If I want to binarize, but not in a unpredictable way. Imbinarize let's me play with this variable? Or I should look more into the intensity? For an indexed image. Sorry for the questions, I'm not an expert in image processing.
If you know in advanced the fixed (constant) threshold, which is good if you have control over your lighting and exposure, then you can just hard code that in:
binaryImage = grayImage > someThreshold;
If you want it variable, because you don't have control over the subject or image capture conditions, but know in advance that there will always be two classes (foreground and background) then you'll have to use some algorithm, such as the one built into imbinarize() or graythresh(), or the triangle method like I've attached (good for skewed histograms).

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by