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.

エッジ検出(ラプラシアン、Sobel、Canny)

Posted at

#実行環境
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.subplot(2,3,1)
plt.axis('off') 
plt.title("Original", fontsize=10)
plt.imshow(gray)

#ラプラシアン
plt.subplot(2,3,4)
plt.axis('off') 
plt.title("Laplacian", fontsize=10)
dst = cv2.Laplacian(gray,ddepth = -1)
plt.imshow(dst)

#Sobel
plt.subplot(2,3,5)
plt.axis('off') 
plt.title("Sobel", fontsize=10)
dst = cv2.Sobel(gray,ddepth = -1,dx = 0,dy = 1) #dx,dyで微分字数を決める。
plt.imshow(dst)

#Sobel
plt.subplot(2,3,6)
plt.axis('off') 
plt.title("Canny", fontsize=10)
dst = cv2.Canny(gray,threshold1 = 64,threshold2 = 128)
#threshold1と2は、小さいほうがエッジ同士の接合に用いられる。
#大きいほうが強いエッジの初期検出に使われる。

plt.imshow(dst)
plt.show()

##結果
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?