0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

閾値処理(アダプティブスレッショナルド)

Last updated at Posted at 2020-08-20

#実行環境
Google Colaboratory

#Google Colaboratoryで画像を読み込む為の準備

from google.colab import files
from google.colab import drive
drive.mount('/content/drive')

#必要なライブラリの読み込み

import cv2 #opencv
import matplotlib.pyplot as plt 
%matplotlib inline

#画像準備

img = plt.imread("/content/drive/My Drive/Colab Notebooks/img/Lenna.bmp")
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)

#アダプティブスレッショルド処理

近傍から閾値を求めて変換する。

plt.figure(figsize=(9, 6), dpi=100,
           facecolor='w', linewidth=0, edgecolor='w')

plt.gray()

#オリジナル画像
plt.subplot(2,2,1)
plt.axis('off') 
plt.imshow(gray)

henkango = 255 #閾値を超えたものの数値をどう変換するか
blocksize = 11 #閾値算出の為の近傍領域サイズ(3以降の奇数)
c = 16 #減算値


#アダプティブスレッショナルド処理:MEAN
plt.subplot(2,2,3)
plt.title("MEAN", fontsize=10)
dst = cv2.adaptiveThreshold(gray, henkango, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, blocksize, c)
plt.axis('off') 
plt.imshow(dst)

#アダプティブスレッショナルド処理:GAUSSIAN_C
plt.subplot(2,2,4)
plt.title("GAUSSIAN", fontsize=10)
dst = cv2.adaptiveThreshold(gray, henkango, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, blocksize, c)
plt.axis('off') 
plt.imshow(dst)

image.png

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?