Пример #1
0
def get_saliency_tile_mean(im, min_max=None, vis_order=None):
    """
    Gets the mean lab averages per tile
    """

    if vis_order == 'bgr':
        lidx = [2, 1, 0]
    else:
        lidx = [0, 1, 2]

    layers = scale_rgb(im[0], min_max, lidx)

    # Transpose the image to RGB
    layers = layers.transpose(1, 2, 0)

    # Perform RGB to CIE Lab color space conversion
    layers = rgb2rgbcie(layers)

    # Compute Lab average values
    lm = layers[:, :, 0].mean(axis=0).mean()
    am = layers[:, :, 1].mean(axis=0).mean()
    bm = layers[:, :, 2].mean(axis=0).mean()

    lab_means = (lm, am, bm)

    return None, lab_means
Пример #2
0
 def test_rgbcie2rgb_conversion(self, channel_axis):
     rgb = np.moveaxis(self.colbars_array,
                       source=-1,
                       destination=channel_axis)
     round_trip = rgbcie2rgb(rgb2rgbcie(rgb, channel_axis=channel_axis),
                             channel_axis=channel_axis)
     # only roundtrip test, we checked rgb2rgbcie above already
     assert_almost_equal(round_trip, rgb)
Пример #3
0
 def test_rgb2rgbcie_conversion(self):
     gt = np.array([[[0.1488856, 0.18288098, 0.19277574],
                     [0.01163224, 0.16649536, 0.18948516],
                     [0.12259182, 0.03308008, 0.17298223],
                     [-0.01466154, 0.01669446, 0.16969164]],
                    [[0.16354714, 0.16618652, 0.0230841],
                     [0.02629378, 0.1498009, 0.01979351],
                     [0.13725336, 0.01638562, 0.00329059], [0., 0., 0.]]])
     assert_almost_equal(rgb2rgbcie(self.colbars_array), gt)
Пример #4
0
 def test_rgb2rgbcie_conversion(self):
     gt = np.array([[[ 0.1488856 ,  0.18288098,  0.19277574],
                     [ 0.01163224,  0.16649536,  0.18948516],
                     [ 0.12259182,  0.03308008,  0.17298223],
                     [-0.01466154,  0.01669446,  0.16969164]],
                    [[ 0.16354714,  0.16618652,  0.0230841 ],
                     [ 0.02629378,  0.1498009 ,  0.01979351],
                     [ 0.13725336,  0.01638562,  0.00329059],
                     [ 0.        ,  0.        ,  0.        ]]])
     assert_almost_equal(rgb2rgbcie(self.colbars_array), gt)
Пример #5
0
def saliency(i_info, parameter_object, i_sect, j_sect, n_rows, n_cols):
    """
    References:
        Federico Perazzi, Philipp Krahenbul, Yael Pritch, Alexander Hornung. Saliency Filters. (2012).
            Contrast Based Filtering for Salient Region Detection. IEEE CVPR, Providence, Rhode Island, USA, June 16-21.

            https://graphics.ethz.ch/~perazzif/saliency_filters/

        Ming-Ming Cheng, Niloy J. Mitra, Xiaolei Huang, Philip H. S. Torr, Shi-Min Hu. (2015).
            Global Contrast based Salient Region detection. IEEE TPAMI.
    """

    # min_max = sputilities.get_layer_min_max(i_info)
    min_max = [(parameter_object.image_min, parameter_object.image_max)] * 3

    if parameter_object.vis_order == 'bgr':
        lidx = [2, 1, 0]
    else:
        lidx = [0, 1, 2]

    # Read the section.
    layers = i_info.read(bands2open=[1, 2, 3],
                         i=i_sect,
                         j=j_sect,
                         rows=n_rows,
                         cols=n_cols,
                         d_type='float32')

    layers = scale_rgb(layers, min_max, lidx)

    # Transpose the image to RGB
    layers = layers.transpose(1, 2, 0)

    # Perform RGB to CIE Lab color space conversion
    layers = rgb2rgbcie(layers)

    # Compute Lab average values
    # lm = layers[:, :, 0].mean(axis=0).mean()
    # am = layers[:, :, 1].mean(axis=0).mean()
    # bm = layers[:, :, 2].mean(axis=0).mean()
    lm = parameter_object.lab_means[0]
    am = parameter_object.lab_means[1]
    bm = parameter_object.lab_means[2]

    return np.uint8(
        rescale_intensity(
            (layers[:, :, 0] - lm)**2. + (layers[:, :, 1] - am)**2. +
            (layers[:, :, 2] - bm)**2.,
            in_range=(-1, 1),
            out_range=(0, 255)))
Пример #6
0
    def test_rgb2rgbcie_conversion(self, channel_axis):
        gt = np.array([[[0.1488856, 0.18288098, 0.19277574],
                        [0.01163224, 0.16649536, 0.18948516],
                        [0.12259182, 0.03308008, 0.17298223],
                        [-0.01466154, 0.01669446, 0.16969164]],
                       [[0.16354714, 0.16618652, 0.0230841],
                        [0.02629378, 0.1498009, 0.01979351],
                        [0.13725336, 0.01638562, 0.00329059], [0., 0., 0.]]])

        img = np.moveaxis(self.colbars_array,
                          source=-1,
                          destination=channel_axis)
        out = rgb2rgbcie(img, channel_axis=channel_axis)

        out = np.moveaxis(out, source=channel_axis, destination=-1)

        assert_almost_equal(out, gt)
Пример #7
0
def extract_color_descriptors(image, space=None, verbose=False):
    """
    Extract color descriptors of the image

    Parameters
    ----------
    image:

    space:
        None, equivalent to rgb
        rgb
        hsv
        xyz
        rgbcie

    Returns
    -------
    Descriptors
    """
    if space == 'hsv':
        image = color.rgb2hsv(image)
    elif space == 'xyz':
        image = color.rgb2xyz(image)
    elif space == 'rgbcie':
        image = color.rgb2rgbcie(image)
    elif space == 'gray' or space == 'grey':
        image = color.rgb2gray(image)

    gen = get_patch(image, size=1)
    descs = []
    for patch, coord in gen:
        if verbose and coord[1] % 5 == 0 and coord[0] == 0:
            print 'computed up to %d, %d' % coord
        desc = patch.flatten()
        desc = np.concatenate((desc, np.array(coord)))
        descs.append(desc)
    return np.array(descs)
Пример #8
0
 def trans(self, img):
     rst = color.rgb2rgbcie(img)
     np.maximum(rst, 0, out=rst)
     print('============', rst.min(axis=(0, 1)), rst.max(axis=(0, 1)))
     rst *= 255 / 50 * 255
     return rst.astype(np.uint8)
Пример #9
0
    def test_rgbcie2rgb_dtype(self):
        img = rgb2rgbcie(self.colbars_array).astype('float64')
        img32 = img.astype('float32')

        assert rgbcie2rgb(img).dtype == img.dtype
        assert rgbcie2rgb(img32).dtype == img32.dtype
Пример #10
0
 def test_rgbcie2rgb_conversion(self):
     # only roundtrip test, we checked rgb2rgbcie above already
     assert_almost_equal(rgbcie2rgb(rgb2rgbcie(self.colbars_array)),
                         self.colbars_array)
Пример #11
0
 def test_rgbcie2rgb_conversion(self):
     # only roundtrip test, we checked rgb2rgbcie above already
     assert_almost_equal(rgbcie2rgb(rgb2rgbcie(self.colbars_array)),
                         self.colbars_array)
Пример #12
0
 def __call__(self, img):
     img = np.asarray(img, np.uint8)
     img = color.rgb2rgbcie(img)
     return img
 def rgb2rgbcie(self,imageArray):
     return color.rgb2rgbcie(imageArray)
#%%
def rgb2ycbcr(im_rgb):
 im_rgb = im_rgb.astype(np.float32)
 im_ycrcb = cv2.cvtColor(im_rgb, cv2.COLOR_RGB2YCR_CB)
 im_ycbcr = im_ycrcb[:,:,(0,2,1)].astype(np.float32)
 im_ycbcr[:,:,0] = (im_ycbcr[:,:,0]*(235-16)+16)/255.0 #to [16/255, 235/255]
 im_ycbcr[:,:,1:] = (im_ycbcr[:,:,1:]*(240-16)+16)/255.0 #to [16/255, 240/255]
 return im_ycbcr
#%%
path_img = "./201208172_T-12-58-58_Dive_01_041.jpg"
img = imread(path_img)
img = img/255
img_hsv = color.rgb2hsv(img)
img_lab = color.rgb2lab(img)
img_hed = color.rgb2hed(img)
img_rgbcie = color.rgb2rgbcie(img)
img_xyz = color.rgb2xyz(img)
img_yuv = color.rgb2yuv(img)
img_yiq = color.rgb2yiq(img)
img_ycbcr = color.rgb2ycbcr(img)
img1 = color.ycbcr2rgb(img_ycbcr)
#%%


#%%
fig, ax = plt.subplots(2, 4, figsize=(15,8))
ax[0, 0].imshow(img)
ax[0, 0].set_title("RGB image")
ax[0, 1].imshow(img_hsv)
ax[0, 1].set_title("HSV image")
ax[0, 2].imshow(img_lab)