convert images to binary with different gray level backgroung
3 ビュー (過去 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!