2014-11-09 1 views
2

이 편지를 읽어 주셔서 감사 드리며 원어민이 아니기 때문에 불쌍한 영어를 용서하십시오. 예를 들어이미지 컨볼 루션 연산자의 방향이 직관적이지 않은 이유는 무엇입니까?

, 소벨 연산자 가 http://en.wikipedia.org/wiki/Sobel_operator

우측 긍정적이고 상단 Gy의 긍정적 인 동안 왼쪽은 마이너스 GX이다.

저는 이미지 처리 전문가가 아닙니다. 그러나 나는 대부분의 사람들이 이미지의 왼쪽 상단으로부터 픽셀을 센다고 추정한다. 컨볼 루션 과정에서 커널을 "뒤집을"필요가 있기 때문에 운영자를 정의 할 때 Gx가 더 나은 규칙 성을 위해 왜 미러링되지 않았습니까?

기술적으로는 프로그래밍 문제가 아닙니다. 그러나 프로그래밍과 관련이 있습니다. 예를 들어 파이썬의 scipy.ndimagesobel 기능을 제공합니다. 이 함수는 왼쪽 열이 양수이고 오른쪽 열이 음수라는 커널을 사용합니다. 그것은 내가 찾을 수있는 이미지 처리에 관한 모든 자료 (위키피디아 기사 포함)와 다릅니다. 실제 구현이 수학적 정의와 다른 특별한 이유가 있습니까?

+0

** 프로그래밍 ** 질문은 무엇입니까? – Taosique

+0

링크에는 그들이 사용하는 Y 규칙이 나와 있지 않습니다. 오리엔테이션 규칙에 관계없이 F (X + 1, Y) -F (X-1, Y)와 F (X, Y + 1) -F (X, Y-1)를 사용하십시오. –

+0

@Taosique 혼란스럽게 생각합니다. SciPy에 예제를 추가하여 제 질문을보다 명확하게 설명했습니다. – Ukyoi

답변

2

첫째, 나에게 약간 질문을 바꿔 보자

왜 소벨 연산자의 scipy.ndimage의 버전은 위키 백과에 주어진 정의에서 반전이 나타 납니까?

차이점을 보여주는 비교 결과는 다음과 같습니다. 입력을 위해, 우리는 위키 피 디아 문서에서 자전거 이미지를 사용 : 값이 효율적으로 뒤집 http://en.wikipedia.org/wiki/File:Bikesgray.jpg

import matplotlib.pyplot as plt 
import numpy as np 
import scipy.ndimage as ndimage 

# Note that if we leave this as unsigned integers we'll have problems with 
# underflow anywhere the gradient is negative. Therefore, we'll cast as floats. 
z = ndimage.imread('Bikesgray.jpg').astype(float) 

# Wikipedia Definition of the x-direction Sobel operator... 
kernel = np.array([[-1, 0, 1], 
        [-2, 0, 2], 
        [-1, 0, 1]], dtype=float) 
sobel_wiki = ndimage.convolve(z, kernel) 

# Scipy.ndimage version of the x-direction Sobel operator... 
sobel_scipy = ndimage.sobel(z, axis=1) 

fig, axes = plt.subplots(figsize=(6, 15), nrows=3) 
axes[0].set(title='Original') 
axes[0].imshow(z, interpolation='none', cmap='gray') 

axes[1].set(title='Wikipedia Definition') 
axes[1].imshow(sobel_wiki, interpolation='none', cmap='gray') 

axes[2].set(title='Scipy.ndimage Definition') 
axes[2].imshow(sobel_scipy, interpolation='none', cmap='gray') 

plt.show() 

공지있다.

enter image description here


배후 논리

은 소벨 필터 구배 연산자 ( numpy.gradient의 가장자리 제외 [1, 0, -1]와 회선에 상당) 기본적이다. Wikipedia에 주어진 정의는 그라디언트의 수학적 정의가 부정적임을 나타냅니다.

import matplotlib.pyplot as plt 
import numpy as np 
import scipy.ndimage as ndimage 

z = ndimage.imread('/home/jofer/Bikesgray.jpg').astype(float) 

sobel = ndimage.sobel(z, 1) 
gradient_y, gradient_x = np.gradient(z) 

fig, axes = plt.subplots(ncols=2, figsize=(12, 5)) 
axes[0].imshow(sobel, interpolation='none', cmap='gray') 
axes[0].set(title="Scipy's Sobel") 

axes[1].imshow(gradient_x, interpolation='none', cmap='gray') 
axes[1].set(title="Numpy's Gradient") 

plt.show() 

enter image description here

따라서, scipy.ndimage 우리가 수학 그라데이션에서 기대할 수있는 것과 일치의 컨벤션을 사용하고 있습니다 : 예를 들어

numpy.gradientscipy.ndimage의 소벨 필터와 비슷한 결과를 제공 .


빠른 사이드 노트 : 실제로 "sobel 필터"라고하는 것은 실제로 다른 축을 따라 두 개의 소벨 필터에서 계산 된 그래디언트 크기입니다. 또한 모든 문제는 입력 기울기의 절대 값으로 당신이이 경우에 사용하는 규칙 중요하지 않습니다

import matplotlib.pyplot as plt 
import scipy.ndimage as ndimage 

z = ndimage.imread('/home/jofer/Bikesgray.jpg').astype(float) 

sobel = ndimage.generic_gradient_magnitude(z, ndimage.sobel) 

fig, ax = plt.subplots() 
ax.imshow(sobel, interpolation='none', cmap='gray') 
plt.show() 

enter image description here

: scipy.ndimage, 당신은으로 계산 것입니다.

대부분의 경우에 조정 가능한 창 (예 : ndimage.gaussian_gradient_magnitude)이있는 부드러운 그라디언트 필터는 가장자리 감지에 더 적합합니다.

관련 문제