Beispiel #1
0
def plot_components(components,
                    patches_size=(DEFAULT_PATCHE_SIZE, DEFAULT_PATCHE_SIZE)):
    import cv2
    for i, comp in enumerate(components):
        c_img = (255 * minmaxnormalization(
            comp.reshape(patches_size[0], patches_size[1], 3))).astype('uint8')
        imwrite('c%d.png' % i, c_img)
def frequency_tuned_saliency(image):
    """
    Frequency Tuned Saliency.
    Find the Euclidean distance between
    the Lab pixel vector in a Gaussian filtered image
    with the average Lab vector for the input image.
    R. Achanta, S. Hemami, F. Estrada and S. Susstrunk,
    Frequency-tuned Salient Region
    Detection, IEEE International Conference on Computer
     Vision and Pattern Recognition

    Args:
        image (numpy.array): an image.

    Returns:
       a 2d image saliency map.
    """
    image = cv2.cvtColor(image, cv2.COLOR_BGR2LAB)
    #mean of each channel
    means = []
    for c in range(image.shape[2]):
        means.append(image[:, :, c].mean())
    means = numpy.asarray(means)

    image = cv2.medianBlur(image, 9)
    dist = (image - means) ** 2
    print("mean color is %s" % means)
    salmap = numpy.zeros((dist.shape[0], dist.shape[1]))
    for i in range(dist.shape[0]):
        for j in range(dist.shape[1]):
            salmap[i][j] = numpy.sqrt(dist[i][j].sum())
    return minmaxnormalization(salmap)
Beispiel #3
0
    patches = extract_patches_2d(image, patches_size)
    patches = numpy.reshape(patches, (patches.shape[0], -1))
    encoded = []
    for s in gen_even_slices(len(patches), 100):
        encoded.extend(encoder.transform(patches[s]))
    return numpy.asarray(encoded)


def plot_components(components,
                    patches_size=(DEFAULT_PATCHE_SIZE, DEFAULT_PATCHE_SIZE)):
    import cv2
    for i, comp in enumerate(components):
        c_img = (255 * minmaxnormalization(
            comp.reshape(patches_size[0], patches_size[1], 3))).astype('uint8')
        imwrite('c%d.png' % i, c_img)


if __name__ == '__main__':
    from cv2 import imread, imwrite
    import sys
    image = imread(sys.argv[1])
    sal = dictionary_saliency(image, 'ica', True)
    sal = 255 * minmaxnormalization(sal)
    imwrite('saliency_ica.png', sal.astype('uint8'))
    del image
    del sal

    #image = imread(sys.argv[1])
    #sal = dictionary_saliency(image, 'kmeans')
    #imwrite('saliency_kmeans.jpg', (255 * sal).astype('uint8'))
def plot_components(components, patches_size=(DEFAULT_PATCHE_SIZE,DEFAULT_PATCHE_SIZE)):
    import cv2
    for i, comp in enumerate(components):
        c_img = (255 * minmaxnormalization(comp.reshape(patches_size[0],patches_size[1],3))).astype('uint8')
        imwrite('c%d.png'%i, c_img)
def image_to_components_space(image, encoder,  patches_size=(DEFAULT_PATCHE_SIZE,DEFAULT_PATCHE_SIZE)):
    patches = extract_patches_2d(image, patches_size)
    patches = numpy.reshape(patches, (patches.shape[0],-1))
    encoded = []
    for s in gen_even_slices(len(patches), 100):
        encoded.extend(encoder.transform(patches[s]))
    return numpy.asarray(encoded)


def plot_components(components, patches_size=(DEFAULT_PATCHE_SIZE,DEFAULT_PATCHE_SIZE)):
    import cv2
    for i, comp in enumerate(components):
        c_img = (255 * minmaxnormalization(comp.reshape(patches_size[0],patches_size[1],3))).astype('uint8')
        imwrite('c%d.png'%i, c_img)


if __name__ == '__main__':
    from  cv2 import imread, imwrite
    import sys
    image = imread(sys.argv[1])
    sal = dictionary_saliency(image, 'ica', True)
    sal = 255 * minmaxnormalization(sal)
    imwrite('saliency_ica.png', sal.astype('uint8'))
    del image
    del sal

    #image = imread(sys.argv[1])
    #sal = dictionary_saliency(image, 'kmeans')
    #imwrite('saliency_kmeans.jpg', (255 * sal).astype('uint8'))