예제 #1
0
파일: tools.py 프로젝트: Trineon/lisa
def scharr(data, sliceId=2):
    edges = np.zeros(data.shape)
    if sliceId == 2:
        for idx in range(data.shape[2]):
            edges[:, :, idx] = skifil.scharr(data[:, :, idx])
    elif sliceId == 0:
        for idx in range(data.shape[0]):
            edges[idx, :, :] = skifil.scharr(data[idx, :, :])
    return edges
예제 #2
0
def test_scharr_vertical():
    """Scharr on a vertical edge should be a vertical line."""
    i, j = np.mgrid[-5:6, -5:6]
    image = (j >= 0).astype(float)
    result = F.scharr(image) * np.sqrt(2)
    j[np.abs(i) == 5] = 10000
    assert_allclose(result[j == 0], 1)
    assert (np.all(result[np.abs(j) > 1] == 0))
예제 #3
0
def test_scharr_vertical():
    """Scharr on a vertical edge should be a vertical line"""
    i, j = np.mgrid[-5:6, -5:6]
    image = (j >= 0).astype(float)
    result = F.scharr(image)
    j[np.abs(i) == 5] = 10000
    assert (np.all(result[j == 0] == 1))
    assert (np.all(result[np.abs(j) > 1] == 0))
예제 #4
0
def test_scharr_horizontal():
    """Scharr on an edge should be a horizontal line."""
    i, j = np.mgrid[-5:6, -5:6]
    image = (i >= 0).astype(float)
    result = F.scharr(image) * np.sqrt(2)
    # Fudge the eroded points
    i[np.abs(j) == 5] = 10000
    assert_allclose(result[i == 0], 1)
    assert (np.all(result[np.abs(i) > 1] == 0))
예제 #5
0
def test_scharr_horizontal():
    """Scharr on an edge should be a horizontal line"""
    i, j = np.mgrid[-5:6, -5:6]
    image = (i >= 0).astype(float)
    result = F.scharr(image)
    # Fudge the eroded points
    i[np.abs(j) == 5] = 10000
    assert (np.all(result[i == 0] == 1))
    assert (np.all(result[np.abs(i) > 1] == 0))
예제 #6
0
def delphi_scharr(image_roi, attrs={}, debug=False):
    greyscale = rgb2gray(image_roi)

    edge_magnitude = scharr(greyscale)

    H = np.histogram(edge_magnitude, bins=8, range=(0,1), density=True)[0]

    if debug:
        print "=== Scharr Texture Histogram ==="
        print H
        print

    attrs.update(('Scharr %d' % i, v) for i, v in enumerate(H))
    return attrs
예제 #7
0
def delphi_scharr(image_roi, attrs={}, debug=False):
    greyscale = rgb2gray(image_roi)

    edge_magnitude = scharr(greyscale)

    H = np.histogram(edge_magnitude, bins=8, range=(0, 1), density=True)[0]

    if debug:
        print "=== Scharr Texture Histogram ==="
        print H
        print

    attrs.update(('Scharr %d' % i, v) for i, v in enumerate(H))
    return attrs
예제 #8
0
def filter_function(img_grey, filt='canny'):
    """
    Grayscales and apply edge detectors to image.
    Returns the flattened filtered image array.
    input: raw image 3d tensor
    output: filtered image
    filters: 'sobel', 'roberts', 'scharr'
    default filter = 'canny'
    """
    # grayscale filters:
    if filt == 'sobel':
        return sobel(img_grey)
    elif filt == 'roberts':
        return roberts(img_grey)
    elif filt == 'canny':
        return canny(img_grey)
    elif filt == 'scharr':
        return scharr(image_grey)
    elif filt == ('canny', 'sobel'):
        return canny(sobel(img_grey))
    else:
        raise Exception('No Such Filter!')
예제 #9
0
def test_scharr_mask():
    """Scharr on a masked array should be zero."""
    np.random.seed(0)
    result = F.scharr(np.random.uniform(size=(10, 10)),
                      np.zeros((10, 10), bool))
    assert_allclose(result, 0)
예제 #10
0
def test_scharr_zeros():
    """Scharr on an array of all zeros."""
    result = F.scharr(np.zeros((10, 10)), np.ones((10, 10), bool))
    assert (np.all(result < 1e-16))
예제 #11
0
def edge_detect(pic):
    edges = scharr(color.rgb2grey(pic))
    #return edges
    return to_rgb3a(edges)
예제 #12
0
import os
import matplotlib.pyplot as plt
get_ipython().magic(u'matplotlib inline')

path = '/Users/heymanhn/Virginia/Zipfian/Capstone_Project/Test_Output_Images/boots'
file_name = 'barneys_158585078.jpg'
image = io.imread('%s/%s' % (path, file_name))
plt.imshow(image)
image_grey = color.rgb2gray(image)

# In[58]:

edge_roberts = roberts(image_grey)
edge_canny = canny(image_grey)
edge_sobel = sobel(image_grey)
edge_scharr = scharr(image_grey)

# In[59]:

fig, ((ax0, ax1), (ax3, ax4)) = plt.subplots(2, 2, figsize=(12, 7))

ax0.imshow(edge_roberts, cmap=plt.cm.gray)
ax0.set_title('Roberts Edge Detection')
ax0.axis('off')

ax1.imshow(edge_canny, cmap=plt.cm.gray)
ax1.set_title('Canny Edge Detection')
ax1.axis('off')

ax3.imshow(edge_sobel, cmap=plt.cm.gray)
ax3.set_title('Sobel Edge Detection')
예제 #13
0
def test_scharr_mask():
    """Scharr on a masked array should be zero"""
    np.random.seed(0)
    result = F.scharr(np.random.uniform(size=(10, 10)), np.zeros((10, 10),
                                                                 bool))
    assert (np.all(result == 0))
예제 #14
0
def test_scharr_zeros():
    """Scharr on an array of all zeros"""
    result = F.scharr(np.zeros((10, 10)), np.ones((10, 10), bool))
    assert (np.all(result == 0))
예제 #15
0
def edge_detect(pic):
    edges = scharr(color.rgb2grey(pic))
    #return edges
    return to_rgb3a(edges)