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?

 採用された回答

Image Analyst
Image Analyst 2017 年 12 月 15 日

1 投票

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 件のコメント

Thank you for the reply. I did as mentioned and added the function
rgbImage = rgb2ind(rgbImage,2)
Is that correct?
Image Analyst
Image Analyst 2017 年 12 月 20 日
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.
Giancarlo Eder Guerra Padilla
Giancarlo Eder Guerra Padilla 2017 年 12 月 20 日
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.
Image Analyst
Image Analyst 2017 年 12 月 20 日
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).

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by