convert images to binary with different gray level backgroung

조회 수: 10 (최근 30일)
Han
Han 2018년 2월 17일
답변: Image Analyst 2018년 2월 17일
Hi all !
I have the following code:
clc;
OriginalImage = imread('te3.jpg');
subplot(2,2,1);
imshow(OriginalImage);
g = rgb2gray(OriginalImage);
subplot(2,2,2);
imshow(g);
BW = imbinarize(g);
subplot(2,2,3);
imshow(BW);
% level = multithresh(g);
% I = imquantize(g,level);
% subplot(2,2,4);
% imshow(I);
I used two images, see the RESULT below:
the second image:
..
I wonder why this worked in images with dark gray background and didn't work with light gray background !
Can you please explain to me why ! And how can I make it works in the second image ..
Thank you !

답변 (1개)

Image Analyst
Image Analyst 2018년 2월 17일
It may not know what you consider to be the background. For your computer graphics images, you can just take the upper left pixel and then threshold.
backgroundGrayLevel = OriginalImage (1,1);
brightStuff = OriginalImage > backgroundGrayLevel;
darkStuff = OriginalImage < backgroundGrayLevel;
nonBackgroundStuff = OriginalImage ~= backgroundGrayLevel;

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by