Python skimage.filters.gaussian_filter() Examples

The following are 5 code examples of skimage.filters.gaussian_filter(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module skimage.filters , or try the search function .
Example #1
Source File: imgOp.py    From TextDetector with GNU General Public License v3.0 6 votes vote down vote up
def unsharp(img):
        ''' unsharp(img)
        
        apply unsharp mask to the image
        img: original image array
        Return: image after unsharp masking, array like'''
        def unsharp2d(img):
                if len(img.shape) == 2:
                        blur = gaussian_filter(img, 50) 
                        blur = -0.1*blur
                        return blur + img
                else:
                        raise Exception('The image size is not recognized.')
        if len(img.shape) == 3 and img.shape[2] == 3:
                img[:, :, 0] = unsharp2d(img[:, :, 0])
                img[:, :, 1] = unsharp2d(img[:, :, 1])
                img[:, :, 2] = unsharp2d(img[:, :, 2])
        elif len(img.shape) == 2:
                img = unsharp2d(img)
        else:
                raise Exception('The image size  is not recognized.')
        return img 
Example #2
Source File: celeba.py    From autoencoding_beyond_pixels with MIT License 5 votes vote down vote up
def _resize(args):
    img, rescale_size, bbox = args
    img = img[bbox[0]:bbox[1], bbox[2]:bbox[3]]
    # Smooth image before resize to avoid moire patterns
    scale = img.shape[0] / float(rescale_size)
    sigma = np.sqrt(scale) / 2.0
    img = filters.gaussian_filter(img, sigma=sigma, multichannel=True)
    img = transform.resize(img, (rescale_size, rescale_size, 3), order=3)
    img = (img*255).astype(np.uint8)
    return img 
Example #3
Source File: visualize_atten.py    From Audio-Vision with MIT License 5 votes vote down vote up
def get_blend_map(img, att_map, blur=True, overlap=True):
    att_map -= att_map.min()
    if att_map.max() > 0:
        att_map /= att_map.max()
    att_map = transform.resize(att_map, (img.shape[:2]), order = 3, mode='nearest')
    if blur:
        att_map = filters.gaussian_filter(att_map, 0.02*max(img.shape[:2]))
        att_map -= att_map.min()
        att_map /= att_map.max()
    cmap = plt.get_cmap('jet')
    att_map_v = cmap(att_map)
    att_map_v = np.delete(att_map_v, 3, 2)
    if overlap:
        att_map = 1*(1-att_map**0.7).reshape(att_map.shape + (1,))*img + (att_map**0.7).reshape(att_map.shape+(1,)) * att_map_v
    return att_map 
Example #4
Source File: segmentation_test.py    From DRFNS with MIT License 5 votes vote down vote up
def difference_of_gaussian(self, imin, bigsize=30.0, smallsize=3.0):
        g1 = filters.gaussian_filter(imin, bigsize)
        g2 = filters.gaussian_filter(imin, smallsize)
        diff = 255*(g1 - g2)

        diff[diff < 0] = 0.0
        diff[diff > 255.0] = 255.0
        diff = diff.astype(np.uint8) 
               
        return diff 
Example #5
Source File: image_editor.py    From spyre with MIT License 5 votes vote down vote up
def getImage(self, params):
        sigma = float(params['sigma'])
        r = float(params['red'])
        g = float(params['green'])
        b = float(params['blue'])
        image = data.coffee()
        new_image = filters.gaussian_filter(image, sigma=sigma, multichannel=True)
        new_image[:, :, 0] = r * new_image[:, :, 0]
        new_image[:, :, 1] = g * new_image[:, :, 1]
        new_image[:, :, 2] = b * new_image[:, :, 2]
        return new_image