示例#1
0
def test_12bit_error():
    # 1024x1024 のRampパターン作成
    inc12 = np.arange(4096)
    img_org = np.dstack([inc12, inc12, inc12])
    img_org = img_org * np.ones((2160, 1, 3))  # V方向に拡張
    img_normalized = img_org / np.max(img_org)

    # 保存
    fname = 'inc12.dpx'
    attr_dpx = {"oiio:BitsPerSample": 12}
    save_img_using_oiio(img_normalized, fname,
                        out_img_type_desc=oiio.UINT16, attr=attr_dpx)

    # 読み込み
    img_load, attr = load_img_using_oiio(fname)
    img_load_12bit = np.uint16(np.round(normalize_by_dtype(img_load) * 4095))

    # とりあえずプロット
    ax1 = pu.plot_1_graph()
    ax1.plot(img_load_12bit[0, :, 0])
    plt.show()

    # オリジナルデータとの差分確認
    diff = np.sum(np.abs(img_org - img_load_12bit))
    print(diff)

    # 隣接ピクセルとの差分確認
    line_data = img_load_12bit[0, :, 0]
    diff = line_data[1:] - line_data[:-1]
    print(np.sum(diff != 1))
示例#2
0
def quadratic_bezier_curve(t, p0, p1, p2, samples=1024):
    # x = ((1 - t) ** 2) * p0[0] + 2 * (1 - t) * t * p1[0]\
    #     + (t ** 2) * p2[0]
    # y = ((1 - t) ** 2) * p0[1] + 2 * (1 - t) * t * p1[1]\
    #     + (t ** 2) * p2[1]

    x = ((1 - t) ** 2) * p0[0] + 2 * (1 - t) * t * p1[0]\
        + (t ** 2) * p2[0]
    y = ((1 - t) ** 2) * p0[1] + 2 * (1 - t) * t * p1[1]\
        + (t ** 2) * p2[1]

    ax1 = pu.plot_1_graph(fontsize=20,
                          figsize=(10, 8),
                          graph_title="Title",
                          graph_title_size=None,
                          xlabel="X Axis Label", ylabel="Y Axis Label",
                          axis_label_size=None,
                          legend_size=17,
                          xlim=None,
                          ylim=None,
                          xtick=None,
                          ytick=None,
                          xtick_size=None, ytick_size=None,
                          linewidth=3,
                          minor_xtick_num=None,
                          minor_ytick_num=None)
    ax1.plot(x, y, label='aaa')
    plt.legend(loc='upper left')
    plt.show()
示例#3
0
def plot_rrt():
    fname = "./aces_1.0.3/luts/Dolby_PQ_4000_nits_Shaper.RRT.P3-D60_ST2084__4000_nits_.spi3d"
    title = os.path.basename(fname)
    x = tylut.load_3dlut_spi_format(fname)[0]
    print(x.shape)
    grid_num = 65
    x2 = np.linspace(0, 1, grid_num)
    y = []
    for idx in range(grid_num):
        line_idx = (grid_num ** 2) * idx + (grid_num ** 1) * idx\
            + idx
        y.append(x[line_idx, 0])

    y = np.array(y)

    ax1 = pu.plot_1_graph(fontsize=20,
                          figsize=(10, 8),
                          graph_title=title,
                          graph_title_size=None,
                          xlabel="Input",
                          ylabel="Output",
                          axis_label_size=None,
                          legend_size=17,
                          xlim=None,
                          ylim=(0, 1),
                          xtick=None,
                          ytick=None,
                          xtick_size=None,
                          ytick_size=None,
                          linewidth=3,
                          minor_xtick_num=None,
                          minor_ytick_num=None)
    ax1.plot(x2, y)
    plt.show()
示例#4
0
def plot_n_log_stops():
    x_max = tf.n_log_decoding(1.0)
    x = get_log_scale_x(sample_num=64, x_max=x_max, stops=20)

    gray18_linear_light = 0.20

    y = tf.n_log_encoding(x) * 1023

    ax1 = pu.plot_1_graph(fontsize=20,
                          figsize=(10, 8),
                          graph_title="N-Log Characteristics",
                          graph_title_size=None,
                          xlabel="Input linear light stops",
                          ylabel="10bit code value",
                          axis_label_size=None,
                          legend_size=17,
                          xlim=[-8, 8],
                          ylim=[0, 1024],
                          xtick=[x for x in range(-8, 9)],
                          ytick=[x * 128 for x in range(8)],
                          xtick_size=None,
                          ytick_size=None,
                          linewidth=2)
    ax1.plot(np.log2(x / gray18_linear_light), y, '-o', label="N-Log OETF")
    plt.legend(loc='upper left')
    plt.show()
示例#5
0
def plot_rgb_histgram(r_data, g_data, b_data, title=None):
    """
    RGB3色のヒストグラムを作成する
    """
    plot_range = [-3, 3]
    three_color_width = 0.7
    each_width = three_color_width / 3

    # データ生成
    r = make_histogram_data(r_data, plot_range)
    g = make_histogram_data(g_data, plot_range)
    b = make_histogram_data(b_data, plot_range)

    # plot
    xtick = [x for x in range(plot_range[0], plot_range[1] + 1)]
    ax1 = pu.plot_1_graph(graph_title=title,
                          graph_title_size=22,
                          xlabel="Difference",
                          ylabel="Frequency",
                          xtick=xtick,
                          grid=False)
    range_r = np.arange(plot_range[0], plot_range[1] + 1) - each_width
    range_g = np.arange(plot_range[0], plot_range[1] + 1)
    range_b = np.arange(plot_range[0], plot_range[1] + 1) + each_width
    ax1.bar(range_r, r[0], color=R_BAR_COLOR, label="Red", width=each_width)
    ax1.bar(range_g, g[0], color=G_BAR_COLOR, label="Green", width=each_width)
    ax1.bar(range_b, b[0], color=B_BAR_COLOR, label="Blue", width=each_width)
    ax1.set_yscale("log", nonposy="clip")
    plt.legend(loc='upper left')
    fname = "figures/" + title + "three.png"
    plt.savefig(fname, bbox_inches='tight', pad_inches=0.1)
    plt.show()
示例#6
0
def plot_log_stops():
    # oetf_list = [tf.LOGC, tf.SLOG3, tf.DLOG, tf.FLOG, tf.NLOG]
    oetf_list = [tf.LOGC, tf.SLOG3_REF]
    ax1 = pu.plot_1_graph(fontsize=20,
                          figsize=(16, 10),
                          graph_title="Characteristics of the camera log",
                          graph_title_size=None,
                          xlabel="Exposure [stops].",
                          ylabel="10bit code value",
                          axis_label_size=None,
                          legend_size=19,
                          xlim=[-8, 8],
                          ylim=[0, 1024],
                          xtick=[x for x in range(-8, 9)],
                          ytick=[x * 128 for x in range(9)],
                          xtick_size=None,
                          ytick_size=None,
                          linewidth=3)
    # centerd_spins(ax1)
    for oetf_name in oetf_list:
        x_max = tf.MAX_VALUE[oetf_name]
        x = get_log_scale_x(sample_num=64, x_max=x_max, stops=20)
        x2 = x / 0.20 if oetf_name == tf.SLOG3 else x / 0.18
        y = tf.oetf(x / x_max, oetf_name) * 1023
        ax1.plot(np.log2(x2), y, '-o', label=oetf_name)

    # Plot A-Log
    alog = ALOG_DATA
    x = get_log_scale_x(sample_num=64, x_max=ALOG_MAX, stops=20)
    x2 = x / 0.18
    ax1.plot(np.log2(x2), alog, '-o', label="Astrodesign A-Log??")

    plt.legend(loc='upper left')
    plt.savefig('camera_logs.png', bbox_inches='tight', pad_inches=0.1)
    plt.show()
示例#7
0
def plot_from_white_to_primary_rgb_value_with_bar(
        primary_color='green', step=5, name=cs.BT709, oetf_name=tf.GAMMA24):
    rgb = get_from_white_to_primary_rgb_value(
        'green', step=5, name=cs.BT709, oetf_name=tf.GAMMA24)
    normalize_coef = np.sum(rgb, axis=-1).reshape((rgb.shape[0], 1))
    rgb_normalized = rgb / normalize_coef * 100

    x_caption = ["No.{}".format(x) for x in range(rgb.shape[0])]
    x_val = np.arange(rgb.shape[0])

    ax1 = pu.plot_1_graph(fontsize=20,
                          figsize=(9, 9),
                          graph_title="色とRGBの割合の関係",
                          xlabel=None,
                          ylabel="Percentage of RGB values [%]",
                          ylim=(0, 105))
    for no_idx in range(rgb.shape[0]):
        bottom = 0
        for c_idx in range(3):
            x = no_idx
            y = rgb_normalized[no_idx][c_idx]
            color = RGB_COLOUR_LIST[c_idx]
            ax1.bar(x, y, bottom=bottom, width=0.7, color=color)
            bottom += y
    plt.xticks(x_val, x_caption)
    plt.savefig('stacked_graph.png', bbox_inches='tight', pad_inches=0.1)
    plt.show()
示例#8
0
def plot_d65():
    d65_file = "./src_data/d65_CIE_S_014-2.csv"
    d65 = np.loadtxt(d65_file, delimiter=',').T
    wl = d65[0].flatten()
    d65_spd = d65[2].flatten()
    d65_spd_sprague = make_day_light_by_calculation(
        temperature=6504.0, interpolater=SpragueInterpolator)
    d65_spd_linear = make_day_light_by_calculation(
        temperature=6504.0, interpolater=LinearInterpolator)

    ax1 = pu.plot_1_graph(fontsize=20,
                          figsize=(10, 8),
                          linewidth=5,
                          graph_title="CIE Illuminant D65",
                          xlabel="wavelength [nm]",
                          ylabel="rerative spectral power distributions")
    ax1.plot(wl, d65_spd, '-', color=R_PLOT_COLOR, label='D65 CIE S 014-2')
    ax1.plot(wl,
             d65_spd_linear[1, ...],
             '--',
             lw=2,
             color=G_PLOT_COLOR,
             label='D65 Calc with LinearInterpolation')
    ax1.plot(wl,
             d65_spd_sprague[1, ...],
             '-',
             lw=2,
             color=B_PLOT_COLOR,
             label='D65 Calc with SpragueInterpolation')
    plt.legend(loc='upper left')
    plt.show()
示例#9
0
def compare_1nm_value_and_target_value(spd, org_cmfs):
    """
    各種変換方式と、公式の1nmのCMFSの誤差を比較
    """
    # intp_methods = ["linear", "sprague", "spline"]
    intp_methods = ["sprague", "spline"]
    spds = [
        interpolate_5nm_cmfs_data(spd, intp_method)
        for intp_method in intp_methods
    ]
    wl = spds[0].wavelengths
    diffs = [org_cmfs - spds[idx].values for idx in range(len(intp_methods))]
    error_rates = np.array([diff / org_cmfs for diff in diffs])
    error_rates[np.isinf(error_rates)] = 0
    error_rates[np.isnan(error_rates)] = 0

    ax1 = pu.plot_1_graph(fontsize=20,
                          figsize=(10, 8),
                          linewidth=3,
                          graph_title="Comparison of interpolation methods.",
                          xlabel="Wavelength [nm]",
                          ylabel='Error rate of y [%]',
                          xlim=[490, 510],
                          ylim=[-0.1, 0.1])

    for idx in range(len(intp_methods)):
        y = error_rates[idx, :, 2] * 100
        ax1.plot(wl, y, '-o', label=intp_methods[idx])
    plt.legend(loc='lower right')
    plt.show()
示例#10
0
def plot_rgb_stacked_bar_graph(data):
    """
    Examples
    --------
    >>> data = {"ACES AP0": np.array([[100, 0, 0], [0, 100, 0], [0, 0, 100]]),
                "BT.709": np.array([[70, 20, 10], [10, 70, 20], [20, 10, 70]]),
                "BT.2020": np.array([[85, 10, 5], [5, 85, 10], [10, 5, 85]])}
    >>> plot_rgb_stacked_bar_graph(data)
    """
    x_val = np.arange(len(data)) + 1
    x_offset = [-0.25, 0.0, 0.25]
    ax1 = pu.plot_1_graph(fontsize=20,
                          figsize=(12, 9),
                          graph_title="Color Space Conversion to ACES AP0",
                          xlabel="Source Gamut",
                          ylabel="Percentage of RGB values [%]",
                          ylim=(0, 105))
    for gg, gamut in enumerate(data):  # 色域のループ
        value = data[gamut]
        value[value < 0] = 0
        value[value > 1] = 1
        normalize_val = np.sum(value, axis=-1) / 100
        value = value / normalize_val.reshape(value.shape[0], 1)
        for ii in range(3):  # 原色が3種類ある、のループ
            x = x_val[gg] + x_offset[ii]
            bottom = 0
            for jj in range(3):  # R, G, B の各要素のループ
                y = value[ii][jj]
                color = RGB_COLOUR_LIST[jj]
                ax1.bar(x, y, bottom=bottom, width=0.2, color=color)
                bottom += y
    plt.xticks(x_val, list(data.keys()))
    plt.savefig('stacked_ap0.png', bbox_inches='tight', pad_inches=0.1)
    plt.show()
示例#11
0
def plot_shaper():
    fname = "./aces_1.0.3/luts/Dolby_PQ_1000_nits_Shaper_to_linear.spi1d"
    title = os.path.basename(fname)
    x = tylut.load_1dlut_spi_format(fname)[..., 0]
    sample_num = len(x)
    y = np.linspace(0, 1, sample_num)
    ax1 = pu.plot_1_graph(fontsize=20,
                          figsize=(10, 8),
                          graph_title=title,
                          graph_title_size=None,
                          xlabel="Linear (log scale)",
                          ylabel="Output",
                          axis_label_size=None,
                          legend_size=17,
                          xlim=None,
                          ylim=None,
                          xtick=None,
                          ytick=None,
                          xtick_size=None,
                          ytick_size=None,
                          linewidth=3,
                          minor_xtick_num=None,
                          minor_ytick_num=None)
    ax1.plot(np.log2(x / 0.18), y)
    plt.show()
示例#12
0
def canon_log3_eotf(x, plot=False):
    """
    Defines the *Canon Log 3* log decoding curve / electro-optical transfer
    function. This function is based on log_decoding_CanonLog3 in Colour.

    Parameters
    ----------
    x : numeric or ndarray
        normalized code value. Interval is [0:1] .

    Returns
    -------
    numeric or ndarray
        Linear data y.

    Notes
    -----
    -   Input *x* code value is converted to *IRE* as follows:
        `IRE = (CV - 64) / (940 - 64)`.

    Examples
    --------
    >>> x = np.linspace(0, 1, 1024)
    >>> y = canon_log3_eotf(x, plot=True)
    """

    # convert x to the 10bit code value
    code_value = x * 1023

    # convert code_value to ire value
    ire = (code_value - 64) / (940 - 64)

    y = np.select((ire < 0.04076162, ire <= 0.105357102, ire > 0.105357102),
                  (-(10**((0.069886632 - ire) / 0.42889912) - 1) / 14.98325,
                   (ire - 0.073059361) / 2.3069815,
                   (10**((ire - 0.069886632) / 0.42889912) - 1) / 14.98325))

    if plot:
        ax1 = pu.plot_1_graph(fontsize=20,
                              figsize=(10, 8),
                              graph_title="Title",
                              graph_title_size=None,
                              xlabel="X Axis Label",
                              ylabel="Y Axis Label",
                              axis_label_size=None,
                              legend_size=17,
                              xlim=None,
                              ylim=None,
                              xtick=None,
                              ytick=None,
                              xtick_size=None,
                              ytick_size=None,
                              linewidth=3)
        ax1.plot(x, y, label="Canon Log3 EOTF")
        plt.legend(loc='upper left')
        plt.show()

    return y
示例#13
0
def canon_log2_eotf(x, plot=False):
    """
    Defines the *Canon Log 2* log decoding curve / electro-optical transfer
    function. This function is based on log_decoding_CanonLog2 in Colour.

    Parameters
    ----------
    x : numeric or ndarray
        normalized code value. Interval is [0:1] .

    Returns
    -------
    numeric or ndarray
        Linear data y.

    Notes
    -----
    -   Input *x* code value is converted to *IRE* as follows:
        `IRE = (CV - 64) / (940 - 64)`.

    Examples
    --------
    >>> x = np.linspace(0, 1, 1024)
    >>> y = canon_log2_eotf(x, plot=True)
    """

    # convert x to the 10bit code value
    code_value = x * 1023

    # convert code_value to ire value
    clog2_ire = (code_value - 64) / (940 - 64)

    y = np.where(
        clog2_ire < 0.035388128,
        -(10**((0.035388128 - clog2_ire) / 0.281863093) - 1) / 87.09937546,
        (10**((clog2_ire - 0.035388128) / 0.281863093) - 1) / 87.09937546)

    if plot:
        ax1 = pu.plot_1_graph(fontsize=20,
                              figsize=(10, 8),
                              graph_title="Title",
                              graph_title_size=None,
                              xlabel="X Axis Label",
                              ylabel="Y Axis Label",
                              axis_label_size=None,
                              legend_size=17,
                              xlim=None,
                              ylim=None,
                              xtick=None,
                              ytick=None,
                              xtick_size=None,
                              ytick_size=None,
                              linewidth=3)
        ax1.plot(x, y, label="Canon Log2 EOTF")
        plt.legend(loc='upper left')
        plt.show()

    return y
示例#14
0
def canon_log3_oetf(x, plot=False):
    """
    Defines the *Canon Log 3* log encoding curve / opto-electronic transfer
    function. This function is based on log_encoding_CanonLog3 in Colour.

    Parameters
    ----------
    x : numeric or ndarray
        Linear data.

    Returns
    -------
    numeric or ndarray
        Canon Log3 normalized code value(10bit).

    Notes
    -----
    -   output *y* code value is converted to *normalized code value*
        as follows: `NCV = (IRE * (940 - 64) + 64 / 1023)` .

    Examples
    --------
    >>> linear_max = canon_log3_eotf(1.0, plot=True)
    >>> x = np.linspace(0, 1, 1024)
    >>> y = canon_log3_eotf(x * linear_max, plot=True)
    """
    clog3_ire = np.select(
        (x < _log_decoding_CanonLog3(0.04076162),
         x <= _log_decoding_CanonLog3(0.105357102),
         x > _log_decoding_CanonLog3(0.105357102)),
        (-(0.42889912 *
           (np.log10(-x * 14.98325 + 1)) - 0.069886632), 2.3069815 * x +
         0.073059361, 0.42889912 * np.log10(x * 14.98325 + 1) + 0.069886632))

    code_value = (clog3_ire * (940 - 64) + 64) / 1023

    if plot:
        ax1 = pu.plot_1_graph(fontsize=20,
                              figsize=(10, 8),
                              graph_title="Title",
                              graph_title_size=None,
                              xlabel="X Axis Label",
                              ylabel="Y Axis Label",
                              axis_label_size=None,
                              legend_size=17,
                              xlim=None,
                              ylim=None,
                              xtick=None,
                              ytick=None,
                              xtick_size=None,
                              ytick_size=None,
                              linewidth=3)
        ax1.plot(x, code_value, label="Canon Log3 OETF")
        plt.legend(loc='upper left')
        plt.show()

    return code_value
示例#15
0
def plot_log_graph():
    stops = 29
    sample_num = 1024

    # Canon Log1
    max_val1 = canon_log_eotf(1.0, plot=False)
    x = np.linspace(0, stops, sample_num)
    logx1 = (1 / 2**(x)) * max_val1
    clog1 = canon_log_oetf(logx1, plot=False)

    # Canon Log2
    max_val2 = canon_log2_eotf(1.0, plot=False)
    x = np.linspace(0, stops, sample_num)
    logx2 = (1 / 2**(x)) * max_val2
    clog2 = canon_log2_oetf(logx2, plot=False)

    # Canon Log3
    max_val3 = canon_log3_eotf(1.0, plot=False)
    x = np.linspace(0, stops, sample_num)
    logx3 = (1 / 2**(x)) * max_val3
    clog3 = canon_log3_oetf(logx3, plot=False)

    # ACEScct
    max_val_aces_cct = 65504
    x = np.linspace(0, stops, sample_num)
    logx_aces_cct = (1 / 2**(x)) * max_val_aces_cct
    aces_cct = aces_cct_oetf(logx_aces_cct, plot=False)

    ax1 = pu.plot_1_graph(fontsize=20,
                          figsize=(16, 10),
                          graph_title="Characteristics of the OETF",
                          graph_title_size=None,
                          xlabel="Relative Stop from 18% Gray",
                          ylabel="10bit Code Value",
                          axis_label_size=None,
                          legend_size=17,
                          xlim=(-10, 10),
                          ylim=(0, 1024),
                          xtick=[x for x in range(-10, 11)],
                          ytick=[x * 64 for x in range(1024 // 64 + 1)],
                          xtick_size=None,
                          ytick_size=None,
                          linewidth=3)
    x_axis = np.log2(logx1 / 0.20)
    y_axis = clog1 * 1023
    ax1.plot(x_axis, y_axis, 'r-', label="Hoge Log")
    x_axis = np.log2(logx2 / 0.20)
    y_axis = clog2 * 1023
    ax1.plot(x_axis, y_axis, 'b-', label="Hoge Log2")
    x_axis = np.log2(logx3 / 0.20)
    y_axis = clog3 * 1023
    ax1.plot(x_axis, y_axis, 'g-', label="Hoge Log3")
    x_axis = np.log2(logx_aces_cct / aces_cct_oetf(0.18))
    y_axis = aces_cct * 1023
    ax1.plot(x_axis, y_axis, 'c-', label="ACEScct")
    plt.legend(loc='upper left')
    plt.show()
示例#16
0
def get_l_focal(hue=45):
    """
    hueから L_focal を得る
    """

    # まずは L_cusp を求める
    # ---------------------
    lab_709, lab_2020, rgb = get_lab_edge(hue)
    chroma_709 = get_chroma(lab_709)
    chroma_2020 = get_chroma(lab_2020)

    bt709_cusp_idx = np.argmax(chroma_709)
    bt2020_cusp_idx = np.argmax(chroma_2020)

    bt709_point = sympy.Point(chroma_709[bt709_cusp_idx],
                              lab_709[bt709_cusp_idx, 0])
    bt2020_point = sympy.Point(chroma_2020[bt2020_cusp_idx],
                               lab_2020[bt2020_cusp_idx, 0])
    chroma_line = sympy.Line(bt709_point, bt2020_point)
    lightness_line = sympy.Line(sympy.Point(0, 0), sympy.Point(0, 100))
    intersection = sympy.intersection(chroma_line, lightness_line)[0].evalf()
    l_cusp = np.array(intersection)

    # BT.2407 に従って補正
    # ---------------------

    # plot
    ax1 = pu.plot_1_graph(fontsize=20,
                          figsize=(10, 8),
                          graph_title=None,
                          graph_title_size=None,
                          xlabel="Chroma",
                          ylabel="Lightness",
                          axis_label_size=None,
                          legend_size=17,
                          xlim=[0, 220],
                          ylim=[0, 100],
                          xtick=None,
                          ytick=None,
                          xtick_size=None, ytick_size=None,
                          linewidth=3)
    ax1.plot(chroma_709, lab_709[..., 0], c="#808080", label='BT.709')
    ax1.plot(chroma_2020, lab_2020[..., 0], c="#000000", label='BT.2020')
    ax1.plot(chroma_709[bt709_cusp_idx], lab_709[bt709_cusp_idx, 0], 'or',
             markersize=10, alpha=0.5)
    ax1.plot(chroma_2020[bt2020_cusp_idx], lab_2020[bt2020_cusp_idx, 0], 'or',
             markersize=10, alpha=0.5)
    ax1.plot(l_cusp[0], l_cusp[1], 'ok', markersize=10, alpha=0.5)
    # annotation
    ax1.annotate(r'L^*_{cusp}', xy=(l_cusp[0], l_cusp[1]),
                 xytext=(l_cusp[0] + 10, l_cusp[1] + 10),
                 arrowprops=dict(facecolor='black', shrink=0.1))
    ax1.plot([chroma_2020[bt2020_cusp_idx], l_cusp[0]],
             [lab_2020[bt2020_cusp_idx, 0], l_cusp[1]], '--k', alpha=0.3)
    plt.legend(loc='upper right')
    plt.show()
示例#17
0
def canon_log2_oetf(x, plot=False):
    """
    Defines the *Canon Log 2* log encoding curve / opto-electronic transfer
    function. This function is based on log_encoding_CanonLog2 in Colour.

    Parameters
    ----------
    x : numeric or ndarray
        Linear data.

    Returns
    -------
    numeric or ndarray
        Canon Log2 normalized code value(10bit).

    Notes
    -----
    -   output *y* code value is converted to *normalized code value*
        as follows: `NCV = (IRE * (940 - 64) + 64 / 1023)` .

    Examples
    --------
    >>> linear_max = canon_log2_eotf(1.0, plot=True)
    >>> x = np.linspace(0, 1, 1024)
    >>> y = canon_log2_eotf(x * linear_max, plot=True)
    """

    clog2_ire = np.where(
        x < _log_decoding_CanonLog2(0.035388128),
        -(0.281863093 * (np.log10(-x * 87.09937546 + 1)) - 0.035388128),
        0.281863093 * np.log10(x * 87.09937546 + 1) + 0.035388128)

    code_value = (clog2_ire * (940 - 64) + 64) / 1023

    if plot:
        ax1 = pu.plot_1_graph(fontsize=20,
                              figsize=(10, 8),
                              graph_title="Title",
                              graph_title_size=None,
                              xlabel="X Axis Label",
                              ylabel="Y Axis Label",
                              axis_label_size=None,
                              legend_size=17,
                              xlim=None,
                              ylim=None,
                              xtick=None,
                              ytick=None,
                              xtick_size=None,
                              ytick_size=None,
                              linewidth=3)
        ax1.plot(x, code_value, label="Canon Log2 OETF")
        plt.legend(loc='upper left')
        plt.show()

    return code_value
示例#18
0
def plot_chromaticity_diagram(gamut, data, title=None):
    xyY = ryr.rgb_to_xyY(data, gamut)
    gamut_xy, _ = tpg.get_primaries(gamut)
    cmf_xy = tpg._get_cmfs_xy()

    rate = 1.0
    ax1 = pu.plot_1_graph(fontsize=20 * rate,
                          figsize=(8 * rate, 9 * rate),
                          graph_title=title,
                          graph_title_size=16,
                          xlabel=None,
                          ylabel=None,
                          axis_label_size=None,
                          legend_size=18 * rate,
                          xlim=(0, 0.8),
                          ylim=(0, 0.9),
                          xtick=[x * 0.1 for x in range(9)],
                          ytick=[x * 0.1 for x in range(10)],
                          xtick_size=17 * rate,
                          ytick_size=17 * rate,
                          linewidth=4 * rate,
                          minor_xtick_num=2,
                          minor_ytick_num=2)
    color = data.reshape((data.shape[0] * data.shape[1], data.shape[2]))
    ax1.plot(cmf_xy[..., 0], cmf_xy[..., 1], '-k', lw=3.5 * rate, label=None)
    ax1.plot((cmf_xy[-1, 0], cmf_xy[0, 0]), (cmf_xy[-1, 1], cmf_xy[0, 1]),
             '-k',
             lw=2.5 * rate,
             label=None)
    ax1.patch.set_facecolor("#F2F2F2")
    ax1.plot(gamut_xy[..., 0],
             gamut_xy[..., 1],
             c=K_BAR_COLOR,
             label="BT.709",
             lw=3 * rate)
    ax1.scatter(xyY[..., 0],
                xyY[..., 1],
                s=2 * rate,
                marker='o',
                c=color,
                edgecolors=None,
                linewidth=1 * rate,
                zorder=100)
    ax1.scatter(np.array([0.3127]),
                np.array([0.3290]),
                s=150 * rate,
                marker='x',
                c="#000000",
                edgecolors=None,
                linewidth=2.5 * rate,
                zorder=101,
                label="D65")
    plt.legend(loc='upper right')
    file_name = './figures/xy_chromaticity_{}.png'.format(title)
    plt.savefig(file_name, bbox_inches='tight')
示例#19
0
def aces_cct_eotf(x, plot=False):
    """
    Defines the *ACEScct* log decoding curve / electro-optical transfer
    function. 

    reference : http://j.mp/S-2016-001_

    Parameters
    ----------
    x : numeric or ndarray
        normalized code value. Interval is [0:1] .

    Returns
    -------
    numeric or ndarray
        Linear data y.

    Notes
    -----
    None

    Examples
    --------
    >>> max_val = aces_cct_oetf(65504)
    >>> x = np.linspace(0, 1, 1024)
    >>> y = aces_cct_eotf(x * max_val, plot=True)
    """
    y = np.select(
        (x <= 0.155251141552511, x < (np.log2(65504) + 9.72) / 17.52, x >=
         (np.log2(65504) + 9.72) / 17.52),
        ((x - 0.0729055341958355) / 10.5402377416545, 2
         **(x * 17.52 - 9.72), 65504))

    if plot:
        ax1 = pu.plot_1_graph(fontsize=20,
                              figsize=(10, 8),
                              graph_title="Title",
                              graph_title_size=None,
                              xlabel="X Axis Label",
                              ylabel="Y Axis Label",
                              axis_label_size=None,
                              legend_size=17,
                              xlim=None,
                              ylim=None,
                              xtick=None,
                              ytick=None,
                              xtick_size=None,
                              ytick_size=None,
                              linewidth=3)
        ax1.plot(x, y, label="ACEScct EOTF")
        plt.legend(loc='upper left')
        plt.show()

    return y
示例#20
0
def _plot_comparison_between_1000nits_and_108nits_primaries(
        x, color_idx, cs_name, min_value, max_value,
        ot_108_img, ot_1000_img,
        x_min_exposure, x_max_exposure):
    title_base = "OutputTrasform comparison {}_{}"
    title_str = title_base.format(cs_name, COLOR_NAME_LIST[color_idx])
    ax1 = pu.plot_1_graph(
        fontsize=20,
        figsize=(16, 10),
        graph_title=title_str,
        graph_title_size=None,
        xlabel="Linear (center is 18% gray)",
        ylabel='Luminance [nits]',
        axis_label_size=None,
        legend_size=20,
        xlim=None,
        ylim=(min_value, max_value),
        xtick=None,
        ytick=None,
        xtick_size=16, ytick_size=None,
        linewidth=3,
        minor_xtick_num=None,
        minor_ytick_num=None)
    ax1.set_xscale('log', basex=2.0)
    ax1.set_yscale('log', basey=10.0)
    y_600nits = np.ones_like(x) * 600
    x_val_num = x_max_exposure - x_min_exposure + 1
    x_val = [0.18 * (2 ** (x + x_min_exposure))
             for x in range(x_val_num) if x % 2 == 0]
    x_caption = [r"$0.18 \times 2^{{{}}}$".format(x + x_min_exposure)
                 for x in range(x_val_num) if x % 2 == 0]
    ax1.plot(x, ot_1000_img[color_idx, :, 0], '-', color=RGB_COLOUR_LIST[0],
             label="Output Transform BT2020 1000nits")
    ax1.plot(x, ot_1000_img[color_idx, :, 1], '-', color=RGB_COLOUR_LIST[1],
             label="Output Transform BT2020 1000nits")
    ax1.plot(x, ot_1000_img[color_idx, :, 2], '-', color=RGB_COLOUR_LIST[2],
             label="Output Transform BT2020 1000nits")

    ax1.plot(x, ot_108_img[color_idx, :, 0], '--', color=RGB_COLOUR_LIST[0],
             label="Output Transform P3D65 108nits")
    ax1.plot(x, ot_108_img[color_idx, :, 1], '--', color=RGB_COLOUR_LIST[1],
             label="Output Transform P3D65 108nits")
    ax1.plot(x, ot_108_img[color_idx, :, 2], '--', color=RGB_COLOUR_LIST[2],
             label="Output Transform P3D65 108nits")
    ax1.plot(x, y_600nits, '-', color="#606060",
             label="600nits", lw=1)

    plt.xticks(x_val, x_caption)
    plt.legend(loc='upper left')
    img_name_base = "comparison_108_vs_1000_primaries_{}_{}.png"
    img_name = img_name_base.format(cs_name, COLOR_NAME_LIST[color_idx])
    plt.savefig(img_name, bbox_inches='tight', pad_inches=0.1)
    plt.show()
示例#21
0
def tonemap_2dim_bezier(x, top_param, bottom_param, plot=False):
    """
    2次ベジェ曲線でトーンマップする

    Parameters
    ----------
    x : array_like
        target data.
    top_param : dictionary
        tonemapping parameters for top area.
    bottom_param : dictionary
        tonemapping parameters for bottom area.
    plot : boolean
        whether plotting or not.

    Note
    ----
    An example of ```top_param``` is bellow.
        {'x0': 0.5, 'y0': 0.5,
         'x1': 0.7, 'y1': 0.7,
         'x2': 1.0, 'y2': 0.7}
    An example of ```bottom_param``` is bellow.
        {'x0': 0.0, 'y0': 0.1,
        'x1': 0.1, 'y1': 0.1,
        'x2': 0.3, 'y2': 0.3}

    """

    temp = tonemap_2dim_bezier_bottom(x, plot=False, **bottom_param)
    y = tonemap_2dim_bezier_top(temp, plot=False, **top_param)

    if plot:
        ax1 = pu.plot_1_graph(fontsize=20,
                              figsize=(10, 8),
                              graph_title="Title",
                              graph_title_size=None,
                              xlabel="X Axis Label",
                              ylabel="Y Axis Label",
                              axis_label_size=None,
                              legend_size=17,
                              xlim=None,
                              ylim=None,
                              xtick=None,
                              ytick=None,
                              xtick_size=None,
                              ytick_size=None,
                              linewidth=3)
        ax1.plot(x, y, label='bezier')
        plt.legend(loc='upper left')
        plt.show()

    return y
示例#22
0
def plot_log_basic(name=tf.FLOG, reflection=False):
    if name == tf.FLOG:
        encode_func = tf.f_log_encoding
        decode_func = tf.f_log_decoding
    elif name == tf.NLOG:
        encode_func = tf.n_log_encoding
        decode_func = tf.n_log_decoding
    elif name == tf.DLOG:
        encode_func = tf.d_log_encoding
        decode_func = tf.d_log_decoding
    else:
        raise ValueError("not supported log name")

    x = np.linspace(0, 1, 1024)
    y = decode_func(x, out_reflection=reflection)

    ax1 = pu.plot_1_graph(linewidth=3)
    ax1.plot(x, y, label=name + " EOTF")
    plt.legend(loc='upper left')
    plt.show()

    x_max = decode_func(1.0, out_reflection=reflection)
    x = np.linspace(0, 1, 1024) * x_max
    y = encode_func(x, in_reflection=reflection)

    ax1 = pu.plot_1_graph(linewidth=3)
    ax1.plot(x, y, label=name + " OETF")
    plt.legend(loc='upper left')
    plt.show()

    y2 = decode_func(y, out_reflection=reflection)

    ax1 = pu.plot_1_graph(linewidth=3)
    ax1.plot(x, y2, label="Linear")
    plt.legend(loc='upper left')
    plt.show()

    print(np.max(np.abs(y2 - x)))
    print(y2)
示例#23
0
def plot_d65_and_calculated_d65():
    """
    計算で出した D65 と エクセルに値が書かれていた D65 で
    スペクトル分が違うのかプロットしてみる。
    """
    t = np.array([6500.0])
    wl_org, s_org = lit.get_d_illuminants_spectrum(t)
    wl_calc, s_calc = lit.get_d65_spectrum()
    s_org = s_org[0]
    ax1 = pu.plot_1_graph()
    ax1.plot(wl_org, s_org, '-o', label="org")
    ax1.plot(wl_calc, s_calc, '-o', label="calc")
    plt.legend(loc='upper left')
    plt.show()
示例#24
0
def plot_lab_leaf(sample_num=9):
    """
    chroma-lightness の leafをプロットする。
    RGBMYCの6パターンでプロットする。

    Parameters
    ----------
    sample_num : int
        sample number for each data.

    """

    rgb = rgbmyc_data_for_lab(sample_num)
    lab_709 = rgb_to_lab_d65(rgb=rgb, name="ITU-R BT.709")
    lab_2020 = rgb_to_lab_d65(rgb=rgb, name="ITU-R BT.2020")

    l_709 = lab_709[..., 0]
    l_2020 = lab_2020[..., 0]

    c_709 = get_chroma(lab_709)
    c_2020 = get_chroma(lab_2020)

    h_709 = get_hue(lab_709)
    h_2020 = get_hue(lab_2020)

    ax1 = pu.plot_1_graph(fontsize=20,
                          figsize=(10, 8),
                          graph_title="Title",
                          graph_title_size=None,
                          xlabel="Chroma",
                          ylabel="Lightness",
                          axis_label_size=None,
                          legend_size=17,
                          xlim=None,
                          ylim=None,
                          xtick=None,
                          ytick=None,
                          xtick_size=None, ytick_size=None,
                          linewidth=3)
    ax1.plot(c_709[0, ...], l_709[0, ...], '-o',
             c="#FF8080", label="BT.709" + " " + str(h_709[0, ...]))
    ax1.plot(c_2020[0, ...], l_2020[0, ...], '-o',
             c="#FF4040", label="BT.2020" + " " + str(h_2020[0, ...]))
    plt.legend(loc='upper right')
    plt.show()
示例#25
0
def plot_cmfs():
    cmfs_file = "./src_data/CMFs_CIE_S_014-1.csv"
    cmfs = np.loadtxt(cmfs_file, delimiter=',').T
    wl = cmfs[0].flatten()
    x = cmfs[1].flatten()
    y = cmfs[2].flatten()
    z = cmfs[3].flatten()

    ax1 = pu.plot_1_graph(fontsize=20,
                          figsize=(10, 8),
                          graph_title="CIE 1931 2-deg, XYZ CMFs",
                          xlabel="wavelength [nm]",
                          ylabel="tristimulus values")
    ax1.plot(wl, x, '-r', label='x')
    ax1.plot(wl, y, '-g', label='y')
    ax1.plot(wl, z, '-b', label='z')
    plt.legend(loc='upper left')
    plt.show()
示例#26
0
def get_bt2100_hlg_curve(x, debug=False):
    """
    参考:ITU-R Recommendation BT.2100-0
    """
    a = 0.17883277
    b = 0.28466892
    c = 0.55991073

    under = (x <= 0.5) * 4 * (x**2)
    over = (x > 0.5) * (np.exp((x - c) / a) + b)

    y = (under + over) / 12.0

    if debug:
        ax1 = pu.plot_1_graph()
        ax1.plot(x, y)
        plt.show()

    return y
示例#27
0
def plot_gray_scale_exr_0_1_3dlut_linear():
    sample_num = 1024
    x_m10_10 = np.linspace(-10, 10, sample_num)

    img = read_exr_data("./exp_min_0_max_1_out_3dlut_linear.exr")
    ax1 = pu.plot_1_graph(fontsize=20,
                          figsize=(16, 10),
                          graph_title="3DLUTの範囲:0~1。allocation: uniform",
                          xlabel="input value",
                          ylabel="output value",
                          xlim=[-0.5, 1.5],
                          linewitdh=3)
    # ax1.plot(x_0_1, img[0, 0:sample_num, 0].flatten(), label="0~1")
    # ax1.plot(x_m1_2, img[1, 0:sample_num, 0].flatten(), label="-1~2")
    ax1.plot(x_m10_10, img[2, 0:sample_num, 0].flatten(), '-o', label="-10~10")
    plt.legend(loc='upper left')
    fname = './figures/graph_0_1_3dlut_linear.png'
    plt.savefig(fname, bbox_inches='tight', pad_inches=0.1)
    plt.show()
示例#28
0
def plot_diff(a, b):
    """
    plot the difference between a and b.

    Parameters
    ----------
    a : ndarray
        data 1
    b : ndarray
        data 2

    Returns
    -------
    none.

    Notes
    -----
    none.

    Examples
    --------
    >>> a = np.linspace(0, 1, 1024)
    >>> b = np.arange(1024) / 1023
    >>> plot_diff(a, b)
    """
    ax1 = pu.plot_1_graph(fontsize=20,
                          figsize=(10, 8),
                          graph_title="Diff",
                          graph_title_size=None,
                          xlabel="Code Value",
                          ylabel="Difference (Linear)",
                          axis_label_size=None,
                          legend_size=17,
                          xlim=(0, 1024),
                          ylim=None,
                          xtick=[x * 128 for x in range(0, 1024 // 128 + 1)],
                          ytick=None,
                          xtick_size=None,
                          ytick_size=None,
                          linewidth=3)
    ax1.plot((a - b), '-o', label="diff")
    plt.legend(loc='upper left')
    plt.show()
示例#29
0
def d_illuminant_interpolation(plot=False):
    """
    # 概要
    D Illuminant の分光特性は 10nm 刻みなので、
    それを 5nm 刻みに線形補完する
    """
    # D Illuminant 算出 (10nm精度)
    # -----------------------------
    t = np.array([5000], dtype=np.float64)
    wl, s = lit.get_d_illuminants_spectrum(t)

    # Interpolation
    # -----------------------------
    # f_quadratic = interpolate.interp1d(wl, s, kind='quadratic')
    f_cubic = interpolate.interp1d(wl, s, kind='cubic')
    wl_new = np.arange(380, 785, 5, dtype=np.uint16)
    # s_quadratic = f_quadratic(wl_new)
    s_cubic = f_cubic(wl_new)

    if plot:
        ax1 = pu.plot_1_graph(fontsize=20,
                              figsize=(10, 8),
                              graph_title="cubic interpolation",
                              graph_title_size=None,
                              xlabel="Wavelength [nm]",
                              ylabel="Intensity",
                              axis_label_size=None,
                              legend_size=17,
                              xlim=None,
                              ylim=None,
                              xtick=None,
                              ytick=None,
                              xtick_size=None,
                              ytick_size=None,
                              linewidth=None)
        ax1.plot(wl, s, 'ro', linewidth=5, label="original")
        # ax1.plot(wl_new, s_quadratic, 'g-x', linewidth=2, label="quadratic")
        ax1.plot(wl_new, s_cubic, 'b-', linewidth=2, label="cubic")
        plt.legend(loc='lower right')
        plt.show()

    return wl_new, s_cubic
示例#30
0
def plot_ab_pane_of_lab(sample_num):
    """
    L*a*b*空間の a*b* 平面をプロットする。
    Hueの考え方がxyY空間と同じか確認するため。
    データは RGBMYC の6種類(RGBベース)。

    Parameters
    ----------
    sample_num : int
        sample number for each data.

    """

    rgb = rgbmyc_data_for_lab(sample_num)
    lab_709 = rgb_to_lab_d65(rgb=rgb, name="ITU-R BT.709")
    lab_2020 = rgb_to_lab_d65(rgb=rgb, name="ITU-R BT.2020")
    color_709 = ["#FF8080", "#80FF80", "#8080FF",
                 "#FF80FF", "#FFFF80", "#80FFFF"]
    color_2020 = ["#FF0000", "#00FF00", "#0000FF",
                  "#FF00FF", "#FFFF00", "#00FFFF"]

    ax1 = pu.plot_1_graph(fontsize=20,
                          figsize=(10, 8),
                          graph_title="Title",
                          graph_title_size=None,
                          xlabel="a*",
                          ylabel="b*",
                          axis_label_size=None,
                          legend_size=17,
                          xlim=None,
                          ylim=None,
                          xtick=None,
                          ytick=None,
                          xtick_size=None, ytick_size=None,
                          linewidth=3)
    for idx in range(rgb.shape[0]):
        ax1.plot(lab_709[idx, :, 1], lab_709[idx, :, 2], '-o',
                 c=color_709[idx], label="BT.709_" + str(idx))
        ax1.plot(lab_2020[idx, :, 1], lab_2020[idx, :, 2], '-o',
                 c=color_2020[idx], label="BT.2020_" + str(idx))
    plt.legend(loc='lower left')
    plt.show()