Python 画像処理 7: 画像の空間鮮明化

1. 画像エッジ検出

微分演算子。エッジ検出と特徴抽出に使用できます。フィルタリング操作は、skimage ライブラリのフィルタ モジュールを通じて実行されます

1. ロバーツオペレーター

Roberts 演算子はエッジの検出に使用されます。

呼び出し形式:
edges=filters.roberts(image) は、
Roberts のクロス カーネルを使用してフィルター処理を行い、クロス エッジを検出するという目的を達成することもできます。
正の対角差分演算子に対応する関数は次のとおりです: roberts_pos_diag(image)
負の対角差分演算子に対応する関数は次のとおりです: roberts_neg_diag(image)

例 1: デジタル画像を読み取り、Roberts 演算子を使用して画像のエッジを検出します。コード例は次のとおりです。

from skimage import data,filters,io 
import matplotlib.pyplot as plt 
from matplotlib.font_manager import FontProperties 
font_set=FontProperties(fname=r"c:\windows\fonts\simsun.ttc",size=12)

img=data.camera()

dst_neg=filters.roberts_neg_diag(img) 
dst_pos=filters.roberts_pos_diag(img) 
dst=filters.roberts(img)

plt.figure('filters',figsize=(8,8))

plt.subplot(221)
plt.title('原图像',fontproperties=font_set) 
plt.imshow(img,plt.cm.gray)

plt.subplot(222) 
plt.title('负对角线算子',fontproperties=font_set) 
plt.imshow(dst_neg,plt.cm.gray)

plt.subplot(223) 
plt.title('正对角线算子',fontproperties=font_set) 
plt.imshow(dst_pos,plt.cm.gray)

plt.subplot(224) 
plt.title('Robers 算子',fontproperties=font_set) 
plt.imshow(dst,plt.cm.gray)
plt.show()

出力:
ACC

2. ソーベル演算子

sobel 演算子関数の呼び出し形式は次​​のとおりです。

edges=filters.sobel(image)
水平エッジ検出演算子に対応する関数は次のとおりです: sobel_h(image)
垂直エッジ検出演算子に対応する関数は次のとおりです: sobel_v(image)

例 2: デジタル画像を読み取り、Sobel オペレーターを使用して画像のエッジを検出します。コード例は次のとおりです。

from skimage import data,filters,io 
import matplotlib.pyplot as plt 
from matplotlib.font_manager import FontProperties 
font_set=FontProperties(fname=r"c:\windows\fonts\simsun.ttc",size=12)

img=data.camera()

img_h=filters.sobel_h(img) 
img_v=filters.sobel_v(img) 
img_sobel=filters.sobel(img)

plt.figure('filters',figsize=(8,8))

plt.subplot(221) 
plt.title('原图像',fontproperties=font_set) 
plt.imshow(img,plt.cm.gray)

plt.subplot(222) 
plt.title('水平边缘',fontproperties=font_set) 
plt.imshow(img_h,plt.cm.gray)

plt.subplot(223) 
plt.title('垂直边缘',fontproperties=font_set) 
plt.imshow(img_v,plt.cm.gray)

plt.subplot(224) 
plt.title('Sobel 算子',fontproperties=font_set) 
plt.imshow(img_sobel,plt.cm.gray)
plt.show()

出力:
広告

3. プレウィット演算子

ソーベルと同じ機能ですが、

呼び出し形式:
edges=filters.prewitt(image)
水平エッジ検出演算子に対応する関数: prewitt_h(image)
垂直エッジ検出演算子に対応する関数: prewitt_v(image)

例 3: デジタル画像を読み取り、Prewitt 演算子を使用して画像のエッジを検出する コード例は次のとおりです。

from skimage import data,filters,io 
import matplotlib.pyplot as plt 
from matplotlib.font_manager import FontProperties 
font_set=FontProperties(fname=r"c:\windows\fonts\simsun.ttc",size=12)

img=data.camera()

img_h=filters.prewitt_h(img) 
img_v=filters.prewitt_v(img) 
img_prewitt=filters.prewitt(img)

plt.figure('filters',figsize=(8,8))

plt.subplot(221) 
plt.title('原图像',fontproperties=font_set) 
plt.imshow(img,plt.cm.gray)

plt.subplot(222) 
plt.title('水平边缘',fontproperties=font_set) 
plt.imshow(img_h,plt.cm.gray)

plt.subplot(223) 
plt.title('垂直边缘',fontproperties=font_set)
plt.imshow(img_v,plt.cm.gray)

plt.subplot(224) 
plt.title('Prewitt 算子',fontproperties=font_set) 
plt.imshow(img_prewitt,plt.cm.gray)
plt.show()

出力:
ACC

4. ラプラシアン演算子

関数呼び出し形式:
edges=filters.laplace(image)

例 4: デジタル イメージを読み取り、ラプラシアン演算子を使用してイメージのエッジを検出します。コード例は次のとおりです。

from skimage import data,filters,io 
import matplotlib.pyplot as plt 
from matplotlib.font_manager import FontProperties 
font_set=FontProperties(fname=r"c:\windows\fonts\simsun.ttc",size=12)

img=data.camera()

img_laplace=filters.laplace(img)
plt.figure('filters',figsize=(8,8))

plt.subplot(121) 
plt.title('原图像',fontproperties=font_set) 
plt.imshow(img,plt.cm.gray)

plt.subplot(122) 
plt.title('Laplacian 算子',fontproperties=font_set) 
plt.imshow(img_laplace,plt.cm.gray)
plt.show()

出力:
アファ

5.ログオペレーター

例 5: デジタル画像を読み取り、LoG 演算子を使用して画像のエッジを検出する コード例は次のとおりです。

from skimage import data,filters,io 
import matplotlib.pyplot as plt 
from matplotlib.font_manager import FontProperties 
font_set=FontProperties(fname=r"c:\windows\fonts\simsun.ttc",size=12)

img=data.camera()

img_gauss=filters.gaussian(img,sigma=2) 
img_laplace=filters.laplace(img) 
img_log=filters.laplace(img_gauss)

plt.figure('filters',figsize=(8,8))
plt.subplot(221) 
plt.title('原图像',fontproperties=font_set) 
plt.imshow(img,plt.cm.gray)

plt.subplot(222) 
plt.title('Laplacian 算子',fontproperties=font_set) 
plt.imshow(img_laplace,plt.cm.gray)

plt.subplot(223)
plt.title('高斯平滑图像',fontproperties=font_set) 
plt.imshow(img_gauss,plt.cm.gray)

plt.subplot(224) 
plt.title('LoG 算子',fontproperties=font_set) 
plt.imshow(img_log,plt.cm.gray)
plt.show()

出力:
集合体

6. コントラスト

from skimage import data,filters,io 
import matplotlib.pyplot as plt 
from matplotlib.font_manager import FontProperties 
font_set=FontProperties(fname=r"c:\windows\fonts\simsun.ttc",size=12)

img=data.camera()

img_gauss=filters.gaussian(img,sigma=2) 
img_laplace=filters.laplace(img) 
img_log=filters.laplace(img_gauss)
img_sobel=filters.sobel(img)
img_prewitt=filters.prewitt(img)
img_Robers=filters.roberts(img)


plt.figure('filters',figsize=(14,14))
plt.subplot(321) 
plt.title('原图像',fontproperties=font_set) 
plt.imshow(img,plt.cm.gray)

plt.subplot(322) 
plt.title('Laplacian 算子',fontproperties=font_set) 
plt.imshow(img_laplace,plt.cm.gray)

plt.subplot(323)
plt.title('Prewitt 算子',fontproperties=font_set) 
plt.imshow(img_prewitt,plt.cm.gray)


plt.subplot(324) 
plt.title('LoG 算子',fontproperties=font_set) 
plt.imshow(img_log,plt.cm.gray)

plt.subplot(325) 
plt.title('Robers 算子',fontproperties=font_set) 
plt.imshow(img_Robers,plt.cm.gray)

plt.subplot(326) 
plt.title('Sobel 算子',fontproperties=font_set) 
plt.imshow(img_sobel,plt.cm.gray)


plt.show()

出力:
ああ

2. 画像の空間鮮明化

鮮明化された画像は元の画像に強調されたエッジを加えたものに等しいため、検出されたエッジ画像に元の画像を加算するだけで済みます。

例 6: デジタル画像を読み取り、ラプラシアン演算子を使用して画像をシャープにする コード例は次のとおりです。

from skimage import data,filters,io 
import matplotlib.pyplot as plt 
from matplotlib.font_manager import FontProperties 
font_set=FontProperties(fname=r"c:\windows\fonts\simsun.ttc",size=12)

img=data.camera()

img_laplace=filters.laplace(img)
img_1=img+2*img_laplace
plt.figure('filters',figsize=(8,8))
plt.subplot(131) 
plt.title('原图像',fontproperties=font_set)
plt.imshow(img,plt.cm.gray)

plt.subplot(132) 
plt.title('Laplacian 算子',fontproperties=font_set) 
plt.imshow(img_laplace,plt.cm.gray)

plt.subplot(133) 
plt.title('锐化图像',fontproperties=font_set) 
plt.imshow(img_1,plt.cm.gray)
plt.show()

出力:
ここに画像の説明を挿入

Daily Pie:
影が見えないように顔を太陽に向けてください

おすすめ

転載: blog.csdn.net/weixin_52051554/article/details/127958519