LoginSignup
3
6

More than 5 years have passed since last update.

simple

img = ('img.jpg');
grayImg = rgb2gray(img);
bwImg = im2bw(grayImg);
figure;
imshow(bwImg);

大津の二値化

thresh = graythresh(grayImg); % grayImgは前の流用ということで
bwImg2 = im2bw(grayImg, thresh);
figure;
imshow(bwImg2);

参考

判別分析法(大津の二値化)画像処理ソリューション

manual

imtool(grayImg); % grayImgは前の流用ということで

% ヒストグラムを表示して、それっぽいしきい値を見つける

bwImg3 = grayImg < 60; % しきい値を60にしたい時
figure;
imshow(bwImg3);

もっと楽にmanualする

以下のコードを「スクリプト」として書く

%%
img = ('img.jpg');
grayImg = rgb2gray(img);
imshow(grayImg > 30);
%%

30を右クリックして「値のインクリメントおよびセクションの実行」をクリックすると、四則演算のボタンが出てくる。ここをクリックすると動的に画像を見ながら二値化できる。

3
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
6