How to binarize this image?

2 ビュー (過去 30 日間)
Nanda Sulthan Estupratama
Nanda Sulthan Estupratama 2018 年 6 月 27 日
コメント済み: Image Analyst 2019 年 6 月 7 日
hi, I have a code :
image=imread('guava.jpg');
figure
imshow(image)
imR1=image(:,:,1);
imG1=image(:,:,2);
imB1=image(:,:,3);
gray = uint8(0.299*double(imR1) + 0.587*double(imG1) + 0.114*double(imB1));
%opening operation
di = strel('line',50,100);
dilate = imdilate(gray,di);
er = strel('line',50,100);
erode = imerode(dilate,er);
%difference image between opening operation and grayscale
difference_image = double(gray) - double(erode);
figure; % Open up another figure window.
subplot (2,2,1)
imshow(dilate)
subplot (2,2,2)
imshow(erode)
subplot(2,2,3)
imshow(difference_image, []); % Display the difference image.
outputImage = uint8(255 * mat2gray(difference_image));
figure
imshow(outputImage)
the result is like :
I need to transform that image into this one :
they said "convert to binary image". I tried with imbinarize and im2bw, the result is all white. what should I do to get that binary image?
  2 件のコメント
Walter Roberson
Walter Roberson 2018 年 6 月 27 日
Can you provide the original image?
Nanda Sulthan Estupratama
Nanda Sulthan Estupratama 2018 年 6 月 27 日
編集済み: Nanda Sulthan Estupratama 2018 年 6 月 27 日
sure
that's the original image

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

採用された回答

Image Analyst
Image Analyst 2018 年 6 月 27 日
The image you show is more like a gray scale image. To get a binary image, do this:
rgbImage = imread('original2.PNG');
binaryImage = rgbImage(:,:,1) < 200;
imshow(binaryImage);
  3 件のコメント
Walter Roberson
Walter Roberson 2019 年 6 月 6 日
Zhiyu Xiao comments to Nanda Sulthan Estupratama:
This is a really important question whose answer can be applied to many other things.
Image Analyst
Image Analyst 2019 年 6 月 7 日
It looks like you can just pass Nanda's original low contrast image into imadjust() to get an image with increased contrast.

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by