Exemple #1
0
def test_sobel_vertical():
    """Sobel on a vertical edge should be a vertical line."""
    i, j = cp.mgrid[-5:6, -5:6]
    image = (j >= 0).astype(float)
    result = filters.sobel(image) * np.sqrt(2)
    assert_allclose(result[j == 0], 1)
    assert cp.all(result[cp.abs(j) > 1] == 0)
Exemple #2
0
def test_hsv_value_with_non_float_output():
    # Since `rgb2hsv` returns a float image and the result of the filtered
    # result is inserted into the HSV image, we want to make sure there isn't
    # a dtype mismatch.
    filtered = edges_hsv_uint(COLOR_IMAGE)
    filtered_value = color.rgb2hsv(filtered)[:, :, 2]
    value = color.rgb2hsv(COLOR_IMAGE)[:, :, 2]
    # Reduce tolerance because dtype conversion.
    assert_allclose(filtered_value, filters.sobel(value), rtol=1e-5, atol=1e-5)
Exemple #3
0
def test_sobel_horizontal():
    """Sobel on a horizontal edge should be a horizontal line."""
    i, j = cp.mgrid[-5:6, -5:6]
    image = (i >= 0).astype(float)
    result = filters.sobel(image) * np.sqrt(2)
    # Check if result match transform direction

    assert_allclose(result[i == 0], 1)
    assert_allclose(result[cp.abs(i) > 1], 0)
Exemple #4
0
def _singlescale_basic_features_singlechannel(img,
                                              sigma,
                                              intensity=True,
                                              edges=True,
                                              texture=True):
    results = ()
    gaussian_filtered = filters.gaussian(img, sigma)
    if intensity:
        results += (gaussian_filtered, )
    if edges:
        results += (filters.sobel(gaussian_filtered), )
    if texture:
        results += (*_texture_filter(gaussian_filtered), )
    return results
Exemple #5
0
def test_sobel_mask():
    """Sobel on a masked array should be zero."""
    result = filters.sobel(cp.random.uniform(size=(10, 10)),
                           cp.zeros((10, 10), dtype=bool))
    assert cp.all(result == 0)
Exemple #6
0
def test_sobel_zeros():
    """Sobel on an array of all zeros."""
    result = filters.sobel(cp.zeros((10, 10)), cp.ones((10, 10), bool))
    assert cp.all(result == 0)
Exemple #7
0
def test_hsv_value():
    filtered = edges_hsv(COLOR_IMAGE)
    value = color.rgb2hsv(COLOR_IMAGE)[:, :, 2]
    assert_allclose(color.rgb2hsv(filtered)[:, :, 2], filters.sobel(value))
Exemple #8
0
def test_each_channel():
    filtered = edges_each(COLOR_IMAGE)
    for i, channel in enumerate(cp.rollaxis(filtered, axis=-1)):
        expected = img_as_float(filters.sobel(COLOR_IMAGE[:, :, i]))
        assert_allclose(channel, expected)
Exemple #9
0
def test_gray_scale_image():
    # We don't need to test both `hsv_value` and `each_channel` since
    # `adapt_rgb` is handling gray-scale inputs.
    assert_allclose(edges_each(GRAY_IMAGE), filters.sobel(GRAY_IMAGE))
Exemple #10
0
def edges_hsv_uint(image):
    return img_as_uint(filters.sobel(image))
Exemple #11
0
def edges_hsv(image):
    return filters.sobel(image)
Exemple #12
0
def edges_each(image):
    return filters.sobel(image)