Esempio n. 1
0
    def test_xyz2lab(self):
        assert_array_almost_equal(xyz2lab(self.xyz_array), self.lab_array, decimal=3)

        # Test the conversion with the rest of the illuminants.
        for I in ["d50", "d55", "d65", "d75"]:
            for obs in ["2", "10"]:
                fname = "lab_array_{0}_{1}.npy".format(I, obs)
                lab_array_I_obs = np.load(os.path.join(os.path.dirname(__file__), "data", fname))
                assert_array_almost_equal(lab_array_I_obs, xyz2lab(self.xyz_array, I, obs), decimal=2)
        for I in ["a", "e"]:
            fname = "lab_array_{0}_2.npy".format(I)
            lab_array_I_obs = np.load(os.path.join(os.path.dirname(__file__), "data", fname))
            assert_array_almost_equal(lab_array_I_obs, xyz2lab(self.xyz_array, I, "2"), decimal=2)
Esempio n. 2
0
def linearProPhotoRGB2Lab(img):
    if not img.shape[2] == 3:
        print('pp_rgb shape', img.shape)
        raise UtilImageError('image channel number is not 3')
    xyz = ProPhotoRGB2XYZ(img)
    lab = color.xyz2lab(xyz)
    return lab
Esempio n. 3
0
    def test_xyz2lab(self):
        assert_array_almost_equal(xyz2lab(self.xyz_array),
                                  self.lab_array, decimal=3)

        # Test the conversion with the rest of the illuminants.
        for I in ["d50", "d55", "d65", "d75"]:
            for obs in ["2", "10"]:
                fname = "color/tests/data/lab_array_{0}_{1}.npy".format(I, obs)
                lab_array_I_obs = np.load(fetch(fname))
                assert_array_almost_equal(lab_array_I_obs,
                                          xyz2lab(self.xyz_array, I, obs),
                                          decimal=2)
        for I in ["a", "e"]:
            fname = "color/tests/data/lab_array_{0}_2.npy".format(I)
            lab_array_I_obs = np.load(fetch(fname))
            assert_array_almost_equal(lab_array_I_obs,
                                      xyz2lab(self.xyz_array, I, "2"),
                                      decimal=2)
Esempio n. 4
0
def xyztolab(image, des):
    illum = chromaticityAdaptation(des)
    out = np.matmul(image, illum)

    out1 = xyz2lab(out).astype(np.float32)
    # print("lab")

    # out2 = (out1 * 255 / np.max(out1)).astype('uint8')

    # out = Image.fromarray(out1)
    return out1
Esempio n. 5
0
    def test_xyz2lab(self):
        assert_array_almost_equal(xyz2lab(self.xyz_array),
                                  self.lab_array, decimal=3)

        # Test the conversion with the rest of the illuminants.
        for I in ["d50", "d55", "d65", "d75"]:
            for obs in ["2", "10"]:
                fname = "lab_array_{0}_{1}.npy".format(I, obs)
                lab_array_I_obs = np.load(
                    os.path.join(os.path.dirname(__file__), 'data', fname))
                assert_array_almost_equal(lab_array_I_obs,
                                          xyz2lab(self.xyz_array, I, obs),
                                          decimal=2)
        for I in ["a", "e"]:
            fname = "lab_array_{0}_2.npy".format(I)
            lab_array_I_obs = np.load(
                os.path.join(os.path.dirname(__file__), 'data', fname))
            assert_array_almost_equal(lab_array_I_obs,
                                      xyz2lab(self.xyz_array, I, "2"),
                                      decimal=2)
Esempio n. 6
0
    def test_xyz2lab(self):
        assert_array_almost_equal(xyz2lab(self.xyz_array),
                                  self.lab_array,
                                  decimal=3)

        # Test the conversion with the rest of the illuminants.
        for I in ["A", "B", "C", "d50", "d55", "d65"]:
            I = I.lower()
            for obs in ["2", "10", "R"]:
                obs = obs.lower()
                fname = f'color/tests/data/lab_array_{I}_{obs}.npy'
                lab_array_I_obs = np.load(fetch(fname))
                assert_array_almost_equal(lab_array_I_obs,
                                          xyz2lab(self.xyz_array, I, obs),
                                          decimal=2)
        for I in ["d75", "e"]:
            fname = f'color/tests/data/lab_array_{I}_2.npy'
            lab_array_I_obs = np.load(fetch(fname))
            assert_array_almost_equal(lab_array_I_obs,
                                      xyz2lab(self.xyz_array, I, "2"),
                                      decimal=2)
def preserve_color_cielch(content, stylized, image_name):

    # extract info and convert to CIE-LCh for each image
    rgbContent = io.imread(content)
    labContent = color.lab2lch(
        color.xyz2lab(color.rgb2xyz(numpy.asarray(rgbContent))))
    labContentArray = numpy.array(labContent)
    rgbStyle = io.imread(stylized)
    labStyle = color.lab2lch(
        color.xyz2lab(color.rgb2xyz(numpy.asarray(rgbStyle))))
    labStyleArray = numpy.array(labStyle)

    # color transfer
    for i in range(len(labContentArray)):
        for j in range(len(labContentArray[0])):
            labContentArray[i][j][0] = labStyleArray[i][j][0]

    labContentArray = color.xyz2rgb(
        color.lab2xyz(color.lch2lab(labContentArray)))
    viewer = ImageViewer(labContentArray)
    viewer.show()
Esempio n. 8
0
def G2_getfeatures(ims, fil_paras, gridshape, mode="reflect", cval=0):
    '''
    A routine which takes an array of images with 4 coords.
    Dim 1 and 2: pixel position.
    Dim 3: RGB channel index.
    Dim 4: Time index.
    '''

    num_ims = ims.shape[3]
    num_feats = gridshape[0] * gridshape[1]

    out = np.zeros(num_ims * num_feats, dtype=np.float32).reshape(
        (num_ims, num_feats))

    # Generate the kernel prior to loop over images.
    fil_values = fil_kernel(paras=fil_paras, n_stds=2)

    # Iterate over images.
    for i in range(num_ims):

        featvec = np.arange(0, dtype=np.float32)

        # Slice -> XYZ -> CIE Lab -> Take only Luminance channel.
        im = col.xyz2lab(col.rgb2xyz(ims[:, :, :, i]))[:, :, 0]

        # Convolution.
        fil_response_real = ndi.convolve(input=im,
                                         weights=fil_values["real"],
                                         mode=mode,
                                         cval=cval)
        fil_response_imag = ndi.convolve(input=im,
                                         weights=fil_values["imag"],
                                         mode=mode,
                                         cval=cval)
        fil_response_magnitude = np.sqrt(
            (fil_response_real**2 + fil_response_imag**2))

        # Per-patch statistics.
        imstats = patch_stats(image=fil_response_magnitude,
                              grid_h=gridshape[0],
                              grid_w=gridshape[1])

        # Pass per-patch statistics through non-linearity to compute final feature vector.
        imfeats = nonlin(imstats["mean"])

        # Store the feature vector for this image.
        out[i, :] = imfeats

    # Output is the array of feature vectors, one feature vector for each image.
    return out
Esempio n. 9
0
 def process_frame(self, n, filename, frame):
     misc.imsave('{}_{}_{}_0.jpg'.format(filename, n, self.hash_type()),
                 frame)
     frame = resize(frame, (self.height, self.width), mode='constant')
     misc.imsave('{}_{}_{}_1.jpg'.format(filename, n, self.hash_type()),
                 frame)
     frame = gaussian(frame, sigma=3.0, multichannel=True)
     misc.imsave('{}_{}_{}_2.jpg'.format(filename, n, self.hash_type()),
                 frame)
     xyz = color.convert_colorspace(frame, 'YUV', 'XYZ')
     misc.imsave('{}_{}_{}_3.jpg'.format(filename, n, self.hash_type()),
                 xyz)
     lab = color.xyz2lab(xyz)
     misc.imsave('{}_{}_{}_4.jpg'.format(filename, n, self.hash_type()),
                 lab)
     return lab
Esempio n. 10
0
 def test_xyz2lab(self):
     assert_array_almost_equal(xyz2lab(self.xyz_array),
                               self.lab_array, decimal=3)
Esempio n. 11
0
    def test_xyz2lab_dtype(self):
        img = self.xyz_array.astype('float64')
        img32 = img.astype('float32')

        assert xyz2lab(img).dtype == img.dtype
        assert xyz2lab(img32).dtype == img32.dtype
Esempio n. 12
0
def linear_rgb2lab(rgb, illuminant="D65", observer="2"):
    """
    Copy of skimage.color.colorconv.rgb2lab for linear RGB values
    """
    return xyz2lab(linear_rgb2xyz(rgb), illuminant, observer)
Esempio n. 13
0
def read_tiff_16bit_img_into_LAB(tiff_fn, exposure=0, normalize_Lab=False):
    xyz = read_tiff_16bit_img_into_XYZ(tiff_fn, exposure)
    lab = color.xyz2lab(xyz)
    if normalize_Lab:
        normalize_Lab_image(lab)
    return lab
Esempio n. 14
0
def hsi2lab(shi_pic):
    tmp_rgb = color.hsv2rgb(hsv)
    tmp_xyz = color.rgb2xyz(tmp_rgb)
    return color.xyz2lab(tmp_xyz)
Esempio n. 15
0
def test_xyz_to_lab_against_skimage(random_xyz):
    assert np.allclose(random_xyz.to_lab(),
                       skcolor.xyz2lab(random_xyz),
                       rtol=1e-2)
Esempio n. 16
0
 def to_lab_from_xyz(self):
     return Image(xyz2lab(self.to_rgb_from_gray()[:, :, :3])).convert_type(self.dtype)
Esempio n. 17
0
 def test_xyz2lab(self):
     assert_array_almost_equal(xyz2lab(self.xyz_array),
                               self.lab_array,
                               decimal=3)
Esempio n. 18
0
def read_tiff_16bit_img_into_LAB(tiff_fn, exposure=0, normalize_Lab=False):
    xyz = read_tiff_16bit_img_into_XYZ(tiff_fn, exposure)
    lab = color.xyz2lab(xyz)
    if normalize_Lab:
        normalize_Lab_image(lab)
    return lab
Esempio n. 19
0
 def test_xyz2lab_channel_axis(self, channel_axis):
     # test conversion with channels along a specified axis
     xyz = np.moveaxis(self.xyz_array, source=-1, destination=channel_axis)
     lab = xyz2lab(xyz, channel_axis=channel_axis)
     lab = np.moveaxis(lab, source=channel_axis, destination=-1)
     assert_array_almost_equal(lab, self.lab_array, decimal=3)
Esempio n. 20
0
from skimage import img_as_float
from skimage.color import rgb2gray
from skimage import exposure
from skimage import color
from scipy import ndimage as ndi
from skimage.morphology import label, binary_erosion, binary_dilation, square, binary_opening, binary_closing
import operator
from itertools import repeat

fn = 'E:\Python\ANN\Projects\固高\定位\Image1.jpg'
img = io.imread(fn)

# using functions in Skimage #
# note the input image is assumed to be sRGB, and will be normalized to [0,1] range #
img_xyz = color.rgb2xyz(img)
img_lab = color.xyz2lab(img_xyz)

#plt.imshow(img_lab, cmap="gray")
#plt.show()


# using VN boy's coversion method #
# assume the input is CIE RGB #
def rgb2xyz_vn(img):
    img = img.copy() / 255.
    conv_mat = np.array([[0.4900, 0.3100, 0.2000], [0.1769, 0.8124, 0.0107],
                         [0.0000, 0.0099, 0.9901]])
    xyz = np.dot(img, conv_mat.T)
    return xyz