Esempio n. 1
0
    def pixel_processing(self, in_rgb, cctf_decoding=False, cat='Bradford', cctf_encoding=False):
        """

        Args:
            in_rgb: pixel data (numpy array)
            cctf_decoding: bool: apply_cctf_decoding
            cat: chromatic adaptation model
            cctf_encoding: bool

        Returns: pixel data converted with odt applied or not

        """
        if self.in_cs:
            if self.in_cs != self.out_cs or cctf_decoding:
                output_colourspace = colour.RGB_COLOURSPACES[self.out_cs]
                cat = cat
                if self.in_cs == 'XYZ':
                    conversion_rgb = colour.XYZ_to_RGB(in_rgb, output_colourspace.whitepoint,
                                                       output_colourspace.whitepoint,
                                                       output_colourspace.XYZ_to_RGB_matrix,
                                                       chromatic_adaptation_transform=cat)
                else:
                    print("colorspace conversion")
                    input_colourspace = colour.RGB_COLOURSPACES[self.in_cs]
                    conversion_rgb = colour.RGB_to_RGB(in_rgb, input_colourspace, output_colourspace,
                                                       chromatic_adaptation_transform=cat,
                                                       apply_cctf_decoding=cctf_decoding,
                                                       apply_cctf_encoding=cctf_encoding)
            else:
                conversion_rgb = in_rgb
        else:
            conversion_rgb = in_rgb

        odt_result = self.apply_odt(conversion_rgb)
        return odt_result
Esempio n. 2
0
def converter(filepath):
    out_filePath= r'L:\temp\xyz\converted_v2.jpg'
    in_buf_data = oiio.ImageBuf(filepath)
    in_buf_roi = oiio.get_roi(in_buf_data.spec())

    in_buf_rgb = oiio.ImageBufAlgo.channels(in_buf_data, (0, 1, 2))  # Remove other channels(multi-channels exr)

    in_array_rgb = in_buf_rgb.get_pixels()

    colourspace_acescg = colour.RGB_COLOURSPACES['ACEScg']
    colourspace_srgb = colour.RGB_COLOURSPACES['sRGB']
    # conversion = colour.XYZ_to_sRGB(in_array_rgb)
    conversion = colour.XYZ_to_RGB(in_array_rgb, colourspace_acescg.whitepoint, colourspace_acescg.whitepoint,
                                   colourspace_acescg.XYZ_to_RGB_matrix)
    conversion_srgb = colour.RGB_to_RGB(conversion, colourspace_acescg, colourspace_srgb, 'Bradford', apply_cctf_encoding= True)

    converted_array_rgba = conversion_srgb
    in_buf_rgb.set_pixels(in_buf_roi, converted_array_rgba)  # Replace the buffer with the converted pixels
    if in_buf_data.spec().alpha_channel > 0:  # If image has an alpha channel
        in_buf_alpha = oiio.ImageBufAlgo.channels(in_buf_data, (3,))  # copy the Alpha channel
        in_buf_rgba = oiio.ImageBufAlgo.channel_append(in_buf_rgb, in_buf_alpha)  # Merge the alpha channel back
    else:
        in_buf_rgba = in_buf_rgb

    in_buf_rgba.specmod().attribute("compression", "jpg:100")
    in_buf_rgba.specmod().attribute("oiio:ColorSpace", 'sRGB')
    bitdepth = 'uint8'
    in_buf_rgba.set_write_format(bitdepth)
    in_buf_rgba.write(out_filePath)
def rgb_conversion(in_rgb, cat):
    input_colourspace = colour.RGB_COLOURSPACES['sRGB']
    output_colourspace = colour.RGB_COLOURSPACES['ACEScg']

    result = colour.RGB_to_RGB(in_rgb,
                               input_colourspace,
                               output_colourspace,
                               chromatic_adaptation_transform=cat)
    result_list.append(result)
    return result
Esempio n. 4
0
    def apply_odt_aces(self, in_rgb):
        """

        Args:
            in_rgb: pixel data as numpy array

        Returns: pixel data as numpy array with odt applied

        """
        lut_path = os.path.join(self.resources_path, "luts")
        lut_list = ODT_DICO.get(self.odt)

        # Convert from ACEScg to ACES2065-1
        in_rgb_ap0 = colour.RGB_to_RGB(in_rgb, colour.RGB_COLOURSPACES['ACEScg'], colour.RGB_COLOURSPACES['ACES2065-1'],
                                       chromatic_adaptation_transform='Bradford',
                                       apply_cctf_decoding=False)

        lut_rrt = colour.io.read_LUT_SonySPI3D(os.path.join(lut_path, lut_list[0]))
        lin_to_log = colour.models.log_encoding_ACEScc(in_rgb_ap0)
        log_to_rrt = lut_rrt.apply(lin_to_log, interpolator=table_interpolation_tetrahedral)
        return log_to_rrt
Esempio n. 5
0
message_box(
    'Computing the "ACES2065-1" colourspace to "ITU-R BT.709" colourspace '
    "matrix."
)
cat = colour.adaptation.matrix_chromatic_adaptation_VonKries(
    colour.xy_to_XYZ(colourspace.whitepoint),
    colour.xy_to_XYZ(colour.RGB_COLOURSPACES["ITU-R BT.709"].whitepoint),
)
print(
    np.dot(
        colour.RGB_COLOURSPACES["ITU-R BT.709"].matrix_XYZ_to_RGB,
        np.dot(cat, colourspace.matrix_RGB_to_XYZ),
    )
)

print("\n")

RGB = np.array([0.45620519, 0.03081071, 0.04091952])
message_box(
    f'Converting from the "ITU-R BT.709" colourspace to the "ACEScg" '
    f'colourspace given "RGB" values:\n\n\t{RGB}'
)
print(
    colour.RGB_to_RGB(
        RGB,
        colour.RGB_COLOURSPACES["ITU-R BT.709"],
        colour.RGB_COLOURSPACES["ACEScg"],
    )
)
Esempio n. 6
0
print('\nOpto-electronic transfer function from '
      'linear to colourspace:\n{0}'.format(colourspace.encoding_cctf))
print('\nElectro-optical transfer function from '
      'colourspace to linear:\n{0}'.format(colourspace.decoding_cctf))

print('\n')

message_box(
    ('Computing "ACES2065-1" colourspace to "ITU-R BT.709" colourspace '
     'matrix.'))
cat = colour.chromatic_adaptation_matrix_VonKries(
    colour.xy_to_XYZ(colourspace.whitepoint),
    colour.xy_to_XYZ(colour.RGB_COLOURSPACES['ITU-R BT.709'].whitepoint))
print(
    np.dot(colour.RGB_COLOURSPACES['ITU-R BT.709'].XYZ_to_RGB_matrix,
           np.dot(cat, colourspace.RGB_to_XYZ_matrix)))

print('\n')

RGB = np.array([0.45620519, 0.03081071, 0.04091952])
message_box(
    ('Converting from "ITU-R BT.709" colourspace to "ACEScg" colourspace '
     'given "RGB" values:\n'
     '\n\t{0}'.format(RGB)))
print(
    colour.RGB_to_RGB(
        RGB,
        colour.RGB_COLOURSPACES['ITU-R BT.709'],
        colour.RGB_COLOURSPACES['ACEScg'],
    ))
colourspace = colour.RGB_COLOURSPACES['ACES RGB']
print('Name:\n"{0}"'.format(colourspace.name))
print('\nPrimaries:\n{0}'.format(colourspace.primaries))
print('\nNormalised primary matrix to "CIE XYZ":\n{0}'.format(
    colourspace.to_XYZ))
print('\nNormalised primary matrix to "ACES RGB":\n{0}'.format(
    colourspace.to_RGB))
print('\nTransfer function from linear to colourspace:\n{0}'.format(
    colourspace.transfer_function))
print('\nInverse transfer function from colourspace to linear:\n{0}'.format(
    colourspace.inverse_transfer_function))

print('\n')

message_box('Computing "ACES RGB" colourspace to "sRGB" colourspace matrix.')
cat = colour.chromatic_adaptation_matrix(
    colour.xy_to_XYZ(colour.RGB_COLOURSPACES['ACES RGB'].whitepoint),
    colour.xy_to_XYZ(colour.RGB_COLOURSPACES['sRGB'].whitepoint))
print(np.dot(colour.RGB_COLOURSPACES['sRGB'].to_RGB,
             np.dot(cat, colour.RGB_COLOURSPACES['ACES RGB'].to_XYZ)))

print('\n')

RGB = [0.35521588, 0.41, 0.24177934]
message_box(('Converting from "sRGB" colourspace to "ProPhoto RGB" '
             'colourspace given "RGB" values:\n'
             '\n\t{0}'.format(RGB)))
print(colour.RGB_to_RGB(RGB,
                        colour.RGB_COLOURSPACES['sRGB'],
                        colour.RGB_COLOURSPACES['ProPhoto RGB']))
    # linearize YUV
    yuv_linear = colour.models.eotf_PQ_BT2100(rgb_bt2020_pq)

    # convert to RGB in BT2020
    rgb_bt2020_linear = hdr_utils.yuv2rgb_bt2020(yuv_linear[:, :, 0],
                                                 yuv_linear[:, :, 1],
                                                 yuv_linear[:, :, 2])

    # remove out of gamut colors and clip
    # clip luminance to 300 nits --> heuristic, use if it improves appearance
    # rgb_bt2020_linear_clipped = np.clip(rgb_bt2020_linear,0,300)

    # convert to BT709
    rgb_bt709_linear = colour.RGB_to_RGB(rgb_bt2020_linear,
                                         colour.models.RGB_COLOURSPACE_BT2020,
                                         colour.models.RGB_COLOURSPACE_BT709)
    rgb_bt709_linear_clipped = np.clip(rgb_bt709_linear, 0, 100)

    # apply tonemap
    rgb_bt709_tonemapped_linear = hdr_utils.tonemap(rgb_bt709_linear_clipped,
                                                    tonemap_method, exposure)

    rgb_bt709_tonemapped_gamma = colour.models.oetf_BT709(
        rgb_bt709_tonemapped_linear)
    rgb_bt709_tonemapped_gamma = (rgb_bt709_tonemapped_gamma * 255).astype(
        np.uint8)
    end = time.time()
    print(end - yuvend, ' is colour time')
    bgr_bt709_tonemapped_gamma = np.stack(
        (rgb_bt709_tonemapped_gamma[:, :, 2], rgb_bt709_tonemapped_gamma[:, :,
Esempio n. 9
0
print(('\nNormalised primary matrix to "CIE XYZ" '
       'tristimulus values:\n{0}').format(colourspace.RGB_to_XYZ_matrix))
print('\nNormalised primary matrix to "ACES2065-1":\n{0}'.format(
    colourspace.XYZ_to_RGB_matrix))
print('\nOpto-electronic transfer function from '
      'linear to colourspace:\n{0}'.format(colourspace.encoding_cctf))
print('\nElectro-optical transfer function from '
      'colourspace to linear:\n{0}'.format(colourspace.decoding_cctf))

print('\n')

message_box(('Computing "ACES2065-1" colourspace to "Rec. 709" colourspace '
             'matrix.'))
cat = colour.chromatic_adaptation_matrix_VonKries(
    colour.xy_to_XYZ(colour.RGB_COLOURSPACES['ACES2065-1'].whitepoint),
    colour.xy_to_XYZ(colour.RGB_COLOURSPACES['Rec. 709'].whitepoint))
print(
    np.dot(
        colour.RGB_COLOURSPACES['Rec. 709'].XYZ_to_RGB_matrix,
        np.dot(cat, colour.RGB_COLOURSPACES['ACES2065-1'].RGB_to_XYZ_matrix)))

print('\n')

RGB = (0.35521588, 0.41000000, 0.24177934)
message_box(('Converting from "Rec. 709" colourspace to "ACEScg" colourspace '
             'given "RGB" values:\n'
             '\n\t{0}'.format(RGB)))
print(
    colour.RGB_to_RGB(RGB, colour.RGB_COLOURSPACES['Rec. 709'],
                      colour.RGB_COLOURSPACES['ACEScg']))
Esempio n. 10
0
    D = row_as_diagonal(D)

    M_CAT = dot_matrix(np.linalg.inv(M), D)
    M_CAT = dot_matrix(M_CAT, M)

    return M_CAT


M_cat02 = chromatic_adaptation_matrix_VonKries(wp_srgb_xyz, wp_aces_xyz)
print(M_cat02)

model_src = colour.models.rgb.RGB_COLOURSPACES['sRGB']
model_dst = colour.models.rgb.RGB_COLOURSPACES['aces']

print('pub static ref ACES_FROM_SRGB: HashMap<String, RGBf64> = hashmap! {')
xyz_wp = colour.models.rgb.RGB_COLOURSPACES['sRGB'].whitepoint
for swatch_name in colour.COLOURCHECKERS_SDS['BabelColor Average'].keys():
    sd = colour.COLOURCHECKERS_SDS['BabelColor Average'][swatch_name]
    xyz = sd_to_XYZ(sd, cmfs, ill_d65)
    rgb_srgb = colour.XYZ_to_RGB(xyz / 100.0, xyz_wp, model_src.whitepoint,
                                 model_src.XYZ_to_RGB_matrix)

    rgb_aces = colour.RGB_to_RGB(rgb_srgb, model_src, model_dst)
    print('    "%s".into() => rgbf(%.24f, %.24f, %.24f),' %
          (name_map[swatch_name], rgb_aces[0], rgb_aces[1], rgb_aces[2]))
print('};\n')

# Whitepoints
d65_xyz = xy_to_XYZ([0.31270, 0.32900])
print('d65_xyz: ', d65_xyz)