コード例 #1
0
def composite_rgbmyc_color_bar(img):
    """
    RGBMYCのカラーバーを画面下部に追加

    Parameters
    ----------
    img : array_like
        image data. shape is must be (V_num, H_num, 3).

    """
    img_width = img.shape[1]
    img_height = img.shape[0]

    scale_step = 65
    color_list = [(1, 0, 0), (0, 1, 0), (0, 0, 1), (1, 0, 1), (1, 1, 0),
                  (0, 1, 1)]

    width = _get_center_grad_width(img) // 2
    height = int(img_height * H_COLOR_GRADATION_HEIGHT)

    # color bar 作成
    # ----------------------
    bar_height_list = cmn.equal_devision(height, 6)
    bar_img_list = []
    for color, bar_height in zip(color_list, bar_height_list):
        color_bar = tpg.gen_step_gradation(width=width,
                                           height=bar_height,
                                           step_num=scale_step,
                                           bit_depth=10,
                                           color=color,
                                           direction='h')
        bar_img_list.append(color_bar)
    color_bar = np.vstack(bar_img_list)

    h_st = _get_center_obj_h_start(img)
    h_ed = h_st + width
    v_st = img_height - 1 - height
    v_ed = v_st + height
    img[v_st:v_ed, h_st:h_ed] = color_bar

    # マーカーとテキスト
    # ----------------------------------------
    marker_vertex = (h_st, v_st - 1)
    _make_marker(img, marker_vertex, direction='down')
    marker_vertex = (h_ed - 1, v_st - 1)
    _make_marker(img, marker_vertex, direction='down')
    text_pos_h = (h_st + int(img_width * MARKER_TEXT_PADDING_H))
    text_height, font_size = _get_text_height_and_font_size(img_height)
    text_pos_v = v_st - text_height
    text = "RGBMYC Scale. Video Level ⇒ 0, 16, 32, 48, ..., 992, 1008, 1023"
    _add_text_info(img,
                   st_pos=(text_pos_h, text_pos_v),
                   font_size=font_size,
                   text=text,
                   font_color=(0.4, 0.4, 0.4))
コード例 #2
0
 def test_gen_step_gradation_h_1step(self):
     bit = 8
     color = (1.0, 1.0, 1.0)
     img = tpg.gen_step_gradation(width=256,
                                  height=50,
                                  step_num=257,
                                  bit_depth=bit,
                                  color=color,
                                  direction='h',
                                  debug=False)
     for c_idx in range(3):
         diff = img[0, 1:, c_idx] - img[0, 0:-1, c_idx]
         ref_val = int(round((2**(16 - bit)) * color[c_idx]))
         ok_((diff == ref_val).all())
コード例 #3
0
 def test_gen_step_gradation_v_1step(self):
     bit = 10
     color = (1.0, 1.0, 1.0)
     img = tpg.gen_step_gradation(width=50,
                                  height=1024,
                                  step_num=1025,
                                  bit_depth=bit,
                                  color=color,
                                  direction='v',
                                  debug=False)
     for c_idx in range(3):
         diff = img[1:, 0, c_idx] - img[0:-1, 0, c_idx]
         ref_val = int(round((2**(16 - bit)) * color[c_idx]))
         ok_((diff == ref_val).all())
コード例 #4
0
def composite_10bit_gray_scale(img):
    """
    10bit のグレースケールを 0~1023Lvで表示

    Parameters
    ----------
    img : array_like
        image data. shape is must be (V_num, H_num, 3).

    """
    global g_cuurent_pos_v
    img_width = img.shape[1]
    img_height = img.shape[0]
    module_st_v = g_cuurent_pos_v + int(img_height * EXTERNAL_PADDING_V)

    width = (img_height // 1080) * 1024
    height = int(img_height * H_FULL_GRADATION_HEIGHT)

    grad_10 = tpg.gen_step_gradation(width=width,
                                     height=height,
                                     step_num=1025,
                                     bit_depth=10,
                                     color=(1.0, 1.0, 1.0),
                                     direction='h')

    st_pos_h = _get_center_obj_h_start(img)
    st_pos_v = module_st_v
    ed_pos_h = st_pos_h + width
    ed_pos_v = st_pos_v + height
    img[st_pos_v:ed_pos_v, st_pos_h:ed_pos_h] = grad_10

    marker_vertex = (st_pos_h, st_pos_v - 1)
    _make_marker(img, marker_vertex, direction='down')
    marker_vertex = (ed_pos_h - 1, st_pos_v - 1)
    _make_marker(img, marker_vertex, direction='down')
    text_pos_h = (st_pos_h + int(img_width * MARKER_TEXT_PADDING_H))
    text_height, font_size = _get_text_height_and_font_size(img_height)
    text_pos_v = st_pos_v - text_height
    text = "10bit gray scale from 0 to 1023 level."
    _add_text_info(img,
                   st_pos=(text_pos_h, text_pos_v),
                   font_size=font_size,
                   text=text,
                   font_color=(0.4, 0.4, 0.4))

    # 現在のV座標を更新
    g_cuurent_pos_v = ed_pos_v
コード例 #5
0
 def test_gen_step_gradation_h_17div_8bit(self):
     bit = 8
     color = (1.0, 1.0, 1.0)
     step_num = 17
     step_val = (2**bit) / (step_num - 1)
     img = tpg.gen_step_gradation(width=256 + 16,
                                  height=50,
                                  step_num=step_num,
                                  bit_depth=bit,
                                  color=color,
                                  direction='h',
                                  debug=False)
     idx = [x * 16 + 8 for x in range(17)]
     img_step = img[:, idx[0:-1], :]
     for c_idx in range(3):
         diff = img_step[0, 1:, c_idx] - img_step[0, 0:-1, c_idx]
         ref_val = int(round((2**(16 - bit)) * step_val * color[c_idx]))
         ref_val_last = ((2**bit) - 1) * (2**(16 - bit)) * color[c_idx]
         ref_val_last = int(round(ref_val_last))
         ok_((diff == ref_val).all())
         ok_((img[:, idx[-1], c_idx] == ref_val_last).all())
コード例 #6
0
def composite_8_10bit_middle_gray_scale(img):
    """
    execute the composition processing for the horizontal 8/10bit gradation.

    Parameters
    ----------
    img : array_like
        image data. shape is must be (V_num, H_num, 3).

    Returns
    -------
    ndarray
        a image with 8/10bit horizontal gray scale.

    Notes
    -----
    -

    Examples
    --------
    >>> img = np.zeros((1080, 1920, 3), np.dtype=uint8)
    >>> composite_8_10bit_middle_gray_scale(img)
    """
    global g_cuurent_pos_v
    img_width = img.shape[1]
    img_height = img.shape[0]

    # 解像にに応じた横幅調整。ただし、後でトリミングする
    # ----------------------------------------------
    grad_width = _get_center_grad_width(img)
    grad_height = int(img_height * H_GRADATION_HEIGHT)

    # グラデーション作成。
    # --------------------------------------------------------------------
    grad_8 = tpg.gen_step_gradation(width=grad_width,
                                    height=grad_height,
                                    step_num=257,
                                    bit_depth=8,
                                    color=(1.0, 1.0, 1.0),
                                    direction='h')

    grad_10 = tpg.gen_step_gradation(width=grad_width,
                                     height=grad_height,
                                     step_num=1025,
                                     bit_depth=10,
                                     color=(1.0, 1.0, 1.0),
                                     direction='h')

    # 8bit 合成
    # ------------------------------------------------------------------
    st_pos_h = _get_center_obj_h_start(img)
    # st_pos_h = (img_width // 2) - (grad_width // 4)
    st_pos_v = int(img_height * HEAD_V_OFFSET)
    ed_pos_h = st_pos_h + (grad_width // 2)
    ed_pos_v = st_pos_v + grad_height
    grad_st_h = grad_width // 4
    grad_ed_h = grad_st_h + (grad_width // 2)
    img[st_pos_v:ed_pos_v, st_pos_h:ed_pos_h] = grad_8[:, grad_st_h:grad_ed_h]

    marker_vertex = (st_pos_h, st_pos_v - 1)
    _make_marker(img, marker_vertex, direction='down')
    marker_vertex = (ed_pos_h - 1, st_pos_v - 1)
    _make_marker(img, marker_vertex, direction='down')

    text_pos_h = (st_pos_h + int(img_width * MARKER_TEXT_PADDING_H))
    text_height, font_size = _get_text_height_and_font_size(img_height)
    text_pos_v = st_pos_v - text_height
    text = "8bit gray scale from 256 to 768 level."
    _add_text_info(img,
                   st_pos=(text_pos_h, text_pos_v),
                   font_size=font_size,
                   text=text,
                   font_color=(0.4, 0.4, 0.4))

    # 10bit 合成
    # ------------------------------------------------------------------
    pading_v = int(img_height * INTERNAL_PADDING_V)
    st_pos_v = st_pos_v + grad_height + pading_v
    ed_pos_v = st_pos_v + grad_height
    img[st_pos_v:ed_pos_v, st_pos_h:ed_pos_h] = grad_10[:, grad_st_h:grad_ed_h]

    marker_vertex = (st_pos_h, st_pos_v - 1)
    _make_marker(img, marker_vertex, direction='down')
    marker_vertex = (ed_pos_h - 1, st_pos_v - 1)
    _make_marker(img, marker_vertex, direction='down')
    text_pos_h = (st_pos_h + int(img_width * MARKER_TEXT_PADDING_H))
    text_height, font_size = _get_text_height_and_font_size(img_height)
    text_pos_v = st_pos_v - text_height
    text = "10bit gray scale from 256 to 768 level."
    _add_text_info(img,
                   st_pos=(text_pos_h, text_pos_v),
                   font_size=font_size,
                   text=text,
                   font_color=(0.4, 0.4, 0.4))

    # 現在のV座標を更新
    g_cuurent_pos_v = ed_pos_v
コード例 #7
0
def composite_hlg_vertical_gray_scale(img):
    """
    execute the composition processing for the virtical hlg gradation.

    Parameters
    ----------
    img : array_like
        image data. shape is must be (V_num, H_num, 3).

    Returns
    -------
    ndarray
        a image with pq gray scale.

    Notes
    -----
    -

    Examples
    --------
    >>> img = np.zeros((1080, 1920, 3), np.dtype=uint8)
    >>> composite_hlg_vertical_gray_scale(img)
    """
    # 基本情報作成
    # ------------------------------------------------------
    img_width = img.shape[1]
    img_height = img.shape[0]
    vertual_width = (img_width // 1920) * 1920
    scale_width = int(vertual_width * SIDE_V_GRADATION_WIDTH)
    scale_height = img_height - 2  # "-2" is for pixels of frame.
    text_width = int(vertual_width * SIDE_V_GRADATION_TEXT_WIDTH)
    text_height = img_height - 2  # "-2" is for pixels of frame.
    bit_depth = 10
    video_max = (2**bit_depth) - 1
    step_num = 65

    # HLGのグラデーション作成
    # ------------------------------------------------------
    scale = tpg.gen_step_gradation(width=scale_width,
                                   height=scale_height,
                                   step_num=step_num,
                                   color=(1.0, 1.0, 1.0),
                                   direction='v',
                                   bit_depth=bit_depth)
    h_st = img_width - 1 - scale_width
    h_ed = -1
    img[0 + 1:scale_height + 1, h_st:h_ed] = scale

    # ビデオレベルと明るさを表示
    # ------------------------------------------------------
    video_level = [
        x * (2**bit_depth) // (step_num - 1) for x in range(step_num)
    ]
    video_level[-1] -= 1  # 最終データは1多いので引いておく
    video_level_float = np.array(video_level) / video_max
    bright = colour.eotf(video_level_float,
                         'ITU-R BT.2100 HLG',
                         L_W=1000,
                         gamma=1.2)
    text_info = np.dstack((video_level, bright)).reshape((bright.shape[0], 2))
    font_size = int(text_height / step_num / 96 * 72)
    txt_img = gen_video_level_text_img(width=text_width,
                                       height=text_height,
                                       font_size=font_size,
                                       text_info=text_info)
    h_st = img_width - (text_width + scale_width)
    h_ed = h_st + text_width
    img[0 + 1:text_height + 1, h_st:h_ed, :] = txt_img

    # 説明用テキスト付与
    # ------------------------------------------------------
    text_pos_h\
        = (h_st - int(vertual_width * SIDE_V_GRADATION_DESC_TEXT_WIDTH_HLG))
    text_height, font_size = _get_text_height_and_font_size(img_height)
    text_pos_v = int(img_height * SIDE_V_GRADATION_DESC_TEXT_V_OFFSET)
    text = "HLG(SG=1.2) video level(10bit) and luminance(nits) ▶"
    _add_text_info(img,
                   st_pos=(text_pos_h, text_pos_v),
                   font_size=font_size,
                   text=text,
                   font_color=(0.4, 0.4, 0.4))