convert images to binary with different gray level backgroung
조회 수: 10 (최근 30일)
이전 댓글 표시
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 !
댓글 수: 0
답변 (1개)
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;
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!