Esempio n. 1
0
def test_prewitt_mask():
    """Prewitt on a masked array should be zero"""
    np.random.seed(0)
    result = F.prewitt(np.random.uniform(size=(10, 10)),
                       np.zeros((10, 10), bool))
    eps = .000001
    assert (np.all(np.abs(result) < eps))
Esempio n. 2
0
def test_prewitt_mask():
    """Prewitt on a masked array should be zero"""
    np.random.seed(0)
    result = F.prewitt(np.random.uniform(size=(10, 10)),
                       np.zeros((10, 10), bool))
    eps = .000001
    assert (np.all(np.abs(result) < eps))
Esempio n. 3
0
def test_prewitt_vertical():
    """Prewitt on a vertical edge should be a vertical line."""
    i, j = np.mgrid[-5:6, -5:6]
    image = (j >= 0).astype(float)
    result = F.prewitt(image) * np.sqrt(2)
    j[np.abs(i) == 5] = 10000
    assert_allclose(result[j == 0], 1)
    assert_allclose(result[np.abs(j) > 1], 0, atol=1e-10)
Esempio n. 4
0
def test_prewitt_horizontal():
    """Prewitt on an edge should be a horizontal line."""
    i, j = np.mgrid[-5:6, -5:6]
    image = (i >= 0).astype(float)
    result = F.prewitt(image) * np.sqrt(2)
    # Fudge the eroded points
    i[np.abs(j) == 5] = 10000
    assert (np.all(result[i == 0] == 1))
    assert_allclose(result[np.abs(i) > 1], 0, atol=1e-10)
Esempio n. 5
0
def test_prewitt_vertical():
    """Prewitt on a vertical edge should be a vertical line"""
    i, j = np.mgrid[-5:6, -5:6]
    image = (j >= 0).astype(float)
    result = F.prewitt(image)
    eps = .000001
    j[np.abs(i) == 5] = 10000
    assert (np.all(result[j == 0] == 1))
    assert (np.all(np.abs(result[np.abs(j) > 1]) < eps))
Esempio n. 6
0
def test_prewitt_vertical():
    """Prewitt on a vertical edge should be a vertical line"""
    i, j = np.mgrid[-5:6, -5:6]
    image = (j >= 0).astype(float)
    result = F.prewitt(image)
    eps = .000001
    j[np.abs(i) == 5] = 10000
    assert (np.all(result[j == 0] == 1))
    assert (np.all(np.abs(result[np.abs(j) > 1]) < eps))
Esempio n. 7
0
def test_prewitt_horizontal():
    """Prewitt on an edge should be a horizontal line"""
    i, j = np.mgrid[-5:6, -5:6]
    image = (i >= 0).astype(float)
    result = F.prewitt(image)
    # Fudge the eroded points
    i[np.abs(j) == 5] = 10000
    eps = .000001
    assert (np.all(result[i == 0] == 1))
    assert (np.all(np.abs(result[np.abs(i) > 1]) < eps))
Esempio n. 8
0
 def prewitt(self, img, width, height):
     from skimage.filter import prewitt
     from skimage.color import rgb2gray
     image = io.imread(img)
     gray_image = rgb2gray(image)
     pre_image = prewitt(gray_image)
     io.imsave("./resource/prewitt.png", pre_image)
     scene = QGraphicsScene()
     scene = self.show_image("./resource/prewitt.png", width, height)
     return scene
Esempio n. 9
0
def test_prewitt_horizontal():
    """Prewitt on an edge should be a horizontal line"""
    i, j = np.mgrid[-5:6, -5:6]
    image = (i >= 0).astype(float)
    result = F.prewitt(image)
    # Fudge the eroded points
    i[np.abs(j) == 5] = 10000
    eps = .000001
    assert (np.all(result[i == 0] == 1))
    assert (np.all(np.abs(result[np.abs(i) > 1]) < eps))
Esempio n. 10
0
def prewitt(parameters):
    """Prewitt edge extraction filter.

    This wraps `skimage.filter.prewitt`. The `mask` option is not supported.

    The wrapped function returns an array with dtype('float64') and values in
    [0, 1]. Keep this in mind before saving the object as an image file.

    During testing there have been some issues with the results. Check the
    corresponding test function for details.

    (TODO improve this doc string as per sobel below)

    :param parameters['data'][0]: input image
    :type parameters['data'][0]: numpy.array

    :return: numpy.array with dtype('float64')

    """
    img = parameters['data'][0]

    result = filter.prewitt(img)

    return result
Esempio n. 11
0
def test_prewitt_mask():
    """Prewitt on a masked array should be zero."""
    np.random.seed(0)
    result = F.prewitt(np.random.uniform(size=(10, 10)),
                       np.zeros((10, 10), bool))
    assert_allclose(np.abs(result), 0)
Esempio n. 12
0
def test_prewitt_zeros():
    """Prewitt on an array of all zeros."""
    result = F.prewitt(np.zeros((10, 10)), np.ones((10, 10), bool))
    assert_allclose(result, 0)
Esempio n. 13
0
def test_prewitt_zeros():
    """Prewitt on an array of all zeros"""
    result = F.prewitt(np.zeros((10, 10)), np.ones((10, 10), bool))
    assert (np.all(result == 0))
Esempio n. 14
0
def test_prewitt_zeros():
    """Prewitt on an array of all zeros"""
    result = F.prewitt(np.zeros((10, 10)), np.ones((10, 10), bool))
    assert (np.all(result == 0))
# In[10]:

imName='images/7th49th/cctv4391.jpg'
image=Image.open(imName).convert("L")
image=array(image)


                Perform the edge detection algorithms
                
# In[11]:

edge_roberts = roberts(image)
edge_sobel = sobel(image)
edge_canny = canny(image,low_threshold=100, high_threshold=200)
edge_gaussian= gaussian_filter(image,1)
edge_prewitt = prewitt(image)


                Plot the results
                
# In[12]:

fig, ax = plt.subplots(ncols=3, nrows=2, sharex=True, sharey=True,
                       figsize=(10, 5))

ax[0,0].imshow(image, cmap=plt.cm.gray)
ax[0,0].set_title('Original Image')

ax[0,1].imshow(edge_sobel, cmap=plt.cm.gray)
ax[0,1].set_title('Sobel Edge Detection')
Esempio n. 16
0
File: hw3.py Progetto: crbates/ay250
def extract_features(image_path_list):
    '''
    This function takes a list of image paths and computes several features of each 
    image in order to classify them. This include both basic properties like size 
    and aspect ratio as well as doing object recognition and counting. This runs at
    about 1/s/core on a quad-core with HT 2.93 GHz i7.
    '''
    feature_list = []
    name_list = []
    file_list = []
    #iterate through all the image paths
    for image_path in image_path_list:
        image_array = imread(image_path)
        feature = []
        feature.append(image_array.size)
        shape = image_array.shape
        #check if the image isblack or white 
        if len(shape) > 2:
            feature.append(1)
            #convert color images to grey so they can be compared with greyscale ones
            image_array = color.rgb2grey(image_array)
            '''
            # Can't use these because there is nothing comparable for black and
            # white images
            feature.append(sum(sum(image_array[:,:,0])))        
            feature.append(sum(sum(image_array[:,:,1])))
            feature.append(sum(sum(image_array[:,:,2])))
            hsv = color.rgb2hsv(img_as_float(image_array))              
            feature.append(sum(sum(hsv[:,:,0])))        
            feature.append(sum(sum(hsv[:,:,1])))        
            feature.append(sum(sum(hsv[:,:,2])))
            '''
        else:
            feature.append(0)
            #print "bw: ", image_path
        #determine basic image shape properties
        feature.append(shape[0])
        feature.append(shape[1])
        feature.append(shape[0]/shape[1])
        #compute the amount of different shades of grey and their ratios
        black = np.average(image_array.flat <= 0.25 )
        darkgrey = np.average((image_array.flat > 0.25) & (image_array.flat <= 0.5))
        lightgrey = np.average((image_array.flat > 0.5) & (image_array.flat <= 0.75)) 
        white = np.average(image_array.flat > 0.75)
        feature.append(black)
        feature.append(darkgrey)
        feature.append(lightgrey)
        feature.append(white)
        feature.append(black/(white+1))
        feature.append(lightgrey/(darkgrey+1))
        feature.append(lightgrey/(black+1))
        
        # compute the average of several common filter outputs
        feature.append(np.average(flt.sobel(image_array)))
        feature.append(np.average(ndimage.morphological_gradient(image_array, size=(2,2))))
        feature.append(np.average(flt.prewitt(image_array)))
        feature.append(np.average(flt.canny(image_array)))
        
        #Use the canny filter to delineate object and then count the objects and 
        #their average size
        p = flt.canny(image_array)
        #plt.imshow(p,cmap=plt.cm.gray,interpolation='nearest')
        #plt.show()
        labels, count = ndimage.label(p)
        area = np.sum((labels>0))/count        
        feature.append(area)
        feature.append(count)
        
        #determine the filename for the results file and the image type for the 
        #training set.
        filename = image_path.split("/")[-1]
        file_list.append(filename)
        image = filename.split('_')[0]        
        name_list.append(image)        
        feature_list.append(feature)
    return name_list, feature_list, file_list