コード例 #1
0
def make_srgb_2015_color_checker():
    # get color checker spectrum
    cc_spectrum, cc_shape = load_colorchecker_spectrum()
    cc_shape = SpectralShape(390, 730, 1)
    cc_spectrum.trim(cc_shape)
    cc_spectrum = cc_spectrum.interpolate(SpectralShape(interval=1),
                                          interpolator=LinearInterpolator)

    # get d65 spd, cie1931 cmfs
    d65_spd = load_d65_spd_1nmdata().trim(cc_shape)
    cmfs_cie2015 =\
        STANDARD_OBSERVERS_CMFS['CIE 2012 2 Degree Standard Observer'].copy()
    cmfs_cie2015.trim(cc_shape)
    d65_spd_1nm = d65_spd.values[:, 1]
    cmfs_cie2015_1nm = cmfs_cie2015.values

    # get large xyz data from spectrum
    large_xyz = colorchecker_spectrum_to_large_xyz_2015(
        d_light=d65_spd_1nm,
        cc_spectrum=cc_spectrum,
        cmfs=cmfs_cie2015_1nm,
        temperature=6500)

    # convert from XYZ to sRGB
    rgb = color_checker_large_xyz_to_rgb(large_xyz)

    rgb[rgb < 0] = 0
    # rgb[rgb > 1] = 1

    rgb = np.uint8(np.round(oetf_sRGB(rgb) * 255))

    # plot
    tpg.plot_color_checker_image(rgb)

    return rgb
コード例 #2
0
def make_color_checker_from_spectrum():
    # get color checker spectrum
    cc_spectrum, cc_shape = load_colorchecker_spectrum()

    # get d65 spd, cie1931 cmfs
    d65_spd = load_d65_spd_1nmdata().trim(cc_shape)
    cmfs_cie1931 = load_cie1931_1nm_data().trim(cc_shape)
    d65_spd_5nm = d65_spd.values[::5, 1]
    cmfs_cie1931_5nm = cmfs_cie1931.values[::5]

    # get large xyz data from spectrum
    large_xyz = colorchecker_spectrum_to_large_xyz(d_light=d65_spd_5nm,
                                                   cc_spectrum=cc_spectrum,
                                                   cmfs=cmfs_cie1931_5nm,
                                                   temperature=6500)

    # convert from XYZ to sRGB
    rgb = color_checker_large_xyz_to_rgb(large_xyz)

    rgb[rgb < 0] = 0
    # rgb[rgb > 1] = 1

    rgb = np.uint8(np.round(oetf_sRGB(rgb) * 255))
    print(rgb)

    # plot
    tpg.plot_color_checker_image(rgb)
    # tpg.plot_color_checker_image(rgb, rgb2=np.uint8(rgb/1.1))
    return rgb
コード例 #3
0
def get_reiwa_color():
    """
    reiwa color を得たい。
    梅:3.4RP7.4/6.8
    菫:7.1P2.9/3
    桜:2.8RP8.8/2.7
    """
    ume = "3.4RP 7.4/6.8"
    sumire = "7.1P 2.9/3"
    sakura = "2.8RP 8.8/2.7"
    reiwa_munsell_colors = [ume, sumire, sakura]
    reiwa_xyY_colors = [munsell_colour_to_xyY(x) for x in reiwa_munsell_colors]
    reiwa_rgb_colors = [
        xyY_to_rgb_with_illuminant_c(xyY) for xyY in reiwa_xyY_colors
    ]
    reiwa_rgb_colors = np.array(
        [np.round((oetf_sRGB(rgb)) * 255) for rgb in reiwa_rgb_colors])
    reiwa_rgb_colors = np.uint8(reiwa_rgb_colors)

    # preview
    img = np.ones((720, 1280, 3), dtype=np.uint8) * 255
    ume = np.ones((200, 200, 3), dtype=np.uint8) * reiwa_rgb_colors[0]
    sumire = np.ones((200, 200, 3), dtype=np.uint8) * reiwa_rgb_colors[1]
    sakura = np.ones((200, 200, 3), dtype=np.uint8) * reiwa_rgb_colors[2]
    tpg.merge(img, ume, (100, 100))
    tpg.merge(img, sumire, (400, 100))
    tpg.merge(img, sakura, (700, 100))
    tpg.preview_image(img)
    print(reiwa_rgb_colors)
コード例 #4
0
    def test_as_8_bit_BGR_image(self):
        """
    Defines :func:`colour_checker_detection.detection.segmentation.\
as_8_bit_BGR_image` definition unit tests methods.
        """

        image_i = read_image(PNG_FILES[0])
        image_o = as_8_bit_BGR_image(image_i)

        self.assertEqual(image_o.dtype, np.uint8)
        np.testing.assert_almost_equal(image_o[16, 16, ...],
                                       (oetf_sRGB(image_i[16, 16, ::-1]) *
                                        255).astype(np.uint8))
コード例 #5
0
def as_8_bit_BGR_image(image):
    """
    Converts and encodes given linear float *RGB* image to 8-bit *BGR* with
    *sRGB* reverse OETF.

    Parameters
    ----------
    image : array_like
        Image to convert.

    Returns
    -------
    ndarray
        Converted image.

    Notes
    -----
    -   In the eventuality where the image is already an integer array, the
        conversion is by-passed.

    Examples
    --------
    >>> from colour.algebra import random_triplet_generator
    >>> prng = np.random.RandomState(4)
    >>> image = list(random_triplet_generator(8, random_state=prng))
    >>> image = np.reshape(image, [4, 2, 3])
    >>> print(image)
    [[[ 0.96702984  0.25298236  0.0089861 ]
      [ 0.54723225  0.43479153  0.38657128]]
    <BLANKLINE>
     [[ 0.97268436  0.77938292  0.04416006]
      [ 0.71481599  0.19768507  0.95665297]]
    <BLANKLINE>
     [[ 0.69772882  0.86299324  0.43614665]
      [ 0.2160895   0.98340068  0.94897731]]
    <BLANKLINE>
     [[ 0.97627445  0.16384224  0.78630599]
      [ 0.00623026  0.59733394  0.8662893 ]]]
    >>> image = as_8_bit_BGR_image(image)
    >>> print(image)
    [[[ 23 137 251]
      [167 176 195]]
    <BLANKLINE>
     [[ 59 228 251]
      [250 122 219]]
    <BLANKLINE>
     [[176 238 217]
      [249 253 128]]
    <BLANKLINE>
     [[229 112 252]
      [239 203  18]]]
    >>> as_8_bit_BGR_image(image)
    array([[[ 23, 137, 251],
            [167, 176, 195]],
    <BLANKLINE>
           [[ 59, 228, 251],
            [250, 122, 219]],
    <BLANKLINE>
           [[176, 238, 217],
            [249, 253, 128]],
    <BLANKLINE>
           [[229, 112, 252],
            [239, 203,  18]]], dtype=uint8)
    """

    image = np.asarray(image)

    if image.dtype == np.uint8:
        return image

    return cv2.cvtColor((oetf_sRGB(image) * 255).astype(np.uint8),
                        cv2.COLOR_RGB2BGR)
コード例 #6
0
def linear_to_srgb_8bit(x):
    return np.uint8(np.round(oetf_sRGB(x) * 255))