Making a saved plot image into a two-dimensional image for imbinarize?
2 views (last 30 days)
Show older comments
Giancarlo Eder Guerra Padilla
on 15 Dec 2017
Commented: Image Analyst
on 20 Dec 2017
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?
0 Comments
Accepted Answer
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
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).
More Answers (0)
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!