mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-03 13:11:25 +08:00
BUG: Correctly convolve integer and floating point arrays.
This commit is contained in:
@@ -67,9 +67,10 @@ def hsobel(image, mask=None):
|
||||
big_mask = binary_erosion(mask,
|
||||
generate_binary_structure(2, 2),
|
||||
border_value = 0)
|
||||
result = np.abs(convolve(image, np.array([[ 1, 2, 1],
|
||||
[ 0, 0, 0],
|
||||
[-1,-2,-1]]).astype(float) / 4.0))
|
||||
result = np.abs(convolve(image.astype(float),
|
||||
np.array([[ 1, 2, 1],
|
||||
[ 0, 0, 0],
|
||||
[-1,-2,-1]]).astype(float) / 4.0))
|
||||
result[big_mask == False] = 0
|
||||
return result
|
||||
|
||||
@@ -103,9 +104,10 @@ def vsobel(image, mask=None):
|
||||
big_mask = binary_erosion(mask,
|
||||
generate_binary_structure(2, 2),
|
||||
border_value=0)
|
||||
result = np.abs(convolve(image, np.array([[1, 0, -1],
|
||||
[2, 0, -2],
|
||||
[1, 0, -1]]).astype(float) / 4.0))
|
||||
result = np.abs(convolve(image.astype(float),
|
||||
np.array([[1, 0, -1],
|
||||
[2, 0, -2],
|
||||
[1, 0, -1]]).astype(float) / 4.0))
|
||||
result[big_mask == False] = 0
|
||||
return result
|
||||
|
||||
@@ -161,9 +163,10 @@ def hprewitt(image, mask=None):
|
||||
big_mask = binary_erosion(mask,
|
||||
generate_binary_structure(2, 2),
|
||||
border_value=0)
|
||||
result = np.abs(convolve(image, np.array([[ 1, 1, 1],
|
||||
[ 0, 0, 0],
|
||||
[-1,-1,-1]]).astype(float) / 3.0))
|
||||
result = np.abs(convolve(image.astype(float),
|
||||
np.array([[ 1, 1, 1],
|
||||
[ 0, 0, 0],
|
||||
[-1,-1,-1]]).astype(float) / 3.0))
|
||||
result[big_mask == False] = 0
|
||||
return result
|
||||
|
||||
@@ -197,8 +200,9 @@ def vprewitt(image, mask=None):
|
||||
big_mask = binary_erosion(mask,
|
||||
generate_binary_structure(2, 2),
|
||||
border_value=0)
|
||||
result = np.abs(convolve(image, np.array([[1, 0, -1],
|
||||
[1, 0, -1],
|
||||
[1, 0, -1]]).astype(float) / 3.0))
|
||||
result = np.abs(convolve(image.astype(float),
|
||||
np.array([[1, 0, -1],
|
||||
[1, 0, -1],
|
||||
[1, 0, -1]]).astype(float) / 3.0))
|
||||
result[big_mask == False] = 0
|
||||
return result
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import os
|
||||
|
||||
from numpy.testing import *
|
||||
import numpy as np
|
||||
from scipy.ndimage import binary_dilation, binary_erosion
|
||||
|
||||
import scikits.image.filter as F
|
||||
from scikits.image import data_dir
|
||||
|
||||
class TestSobel():
|
||||
def test_00_00_zeros(self):
|
||||
@@ -35,6 +39,16 @@ class TestSobel():
|
||||
assert (np.all(result[j == 0] == 1))
|
||||
assert (np.all(result[np.abs(j) > 1] == 0))
|
||||
|
||||
def test_convolution_upcast(self):
|
||||
i, j = np.mgrid[-5:6, -5:6]
|
||||
image = np.load(os.path.join(data_dir, 'lena_GRAY_U8.npy'))
|
||||
|
||||
result1 = F.sobel(image)
|
||||
image = image.astype(float)
|
||||
result2 = F.sobel(image)
|
||||
|
||||
assert_array_equal(result1, result2)
|
||||
|
||||
class TestHSobel():
|
||||
def test_00_00_zeros(self):
|
||||
"""Horizontal sobel on an array of all zeros"""
|
||||
|
||||
Reference in New Issue
Block a user