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

2 views (last 30 days)
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?

Accepted Answer

Image Analyst
Image Analyst on 15 Dec 2017
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 Comments
Giancarlo Eder Guerra Padilla
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 on 20 Dec 2017
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).

Sign in to comment.

More Answers (0)

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!