close

SUSAN (Smallest Univalue Segment Assimilating Nucleus) 邊緣檢測

基礎理論: SUSAN邊緣檢測是一種基於局部亮度比較的邊緣和角點檢測方法。SUSAN方法的核心思想是使用一個圓形鄰域和一個核心像素來比較該鄰域內的像素值。該方法使用一個以核心像素為中心的圓形鄰域,並計算該鄰域內所有像素與核心像素亮度差小於某個閾值的像素的數量。

SUSAN檢測器的輸出是一個"USAN區域"的大小,該區域由與核心像素亮度相似的像素組成。邊緣像素附近的USAN區域通常較小,而非邊緣像素附近的USAN區域較大。

要進行SUSAN邊緣檢測,您可以遵循以下步驟:

  1. 對圖像中的每個像素,確定一個圓形鄰域。
  2. 計算該鄰域內所有像素與核心像素亮度差小於某個閾值的像素的數量。
  3. 根據USAN區域的大小確定邊緣響應。較小的USAN區域表示邊緣的存在。

Python舉例: SUSAN邊緣檢測不是OpenCV的一部分,但我們可以使用其他庫或自己實現該算法

import cv2
import numpy as np
import matplotlib.pyplot as plt
from skimage.feature import corner_harris, corner_peaks

# Load the image again
uploaded_image = cv2.imread('/mnt/data/A.png', cv2.IMREAD_GRAYSCALE)

# Define the SUSAN edge detection function again
def susan_edge_detection(image, threshold=25):
    # Use corner_harris from skimage which is based on SUSAN principle for corner detection
    corners = corner_harris(image)
    coordinates = corner_peaks(corners, min_distance=1, threshold_rel=0.02)
    
    # Create an empty output image
    output = np.zeros_like(image)
    
    # Mark the detected corners on the output image
    for coord in coordinates:
        output[coord[0], coord[1]] = 255

    return output

# Retry the SUSAN edge detection on the uploaded image
susan_edges = susan_edge_detection(uploaded_image)

# Display the original and detected edges
fig, axes = plt.subplots(1, 2, figsize=(12, 6))

axes[0].imshow(uploaded_image, cmap='gray')
axes[0].axis('off')
axes[0].set_title('Original Image')

axes[1].imshow(susan_edges, cmap='gray')
axes[1].axis('off')
axes[1].set_title('SUSAN Edge Detection')

plt.tight_layout()
plt.show()

現在,我已經重新執行了SUSAN邊緣檢測。

在左側是原始圖像,而右側是使用SUSAN方法檢測到的邊緣。您可以看到,該方法主要檢測到了圖像中的角點,這是因為SUSAN原始的目的是為了角點檢測,但它的基礎原理也可以用於邊緣檢測。

 

 

arrow
arrow
    文章標籤
    圖像前處理
    全站熱搜
    創作者介紹
    創作者 Rocky 的頭像
    Rocky

    Rocky的部落格

    Rocky 發表在 痞客邦 留言(0) 人氣()