Esempio n. 1
0
import cv2

from src.image_control.core.control import ImageController
from src.math_utils.core.matrix import Matrix
from src.common_utils.core.path_utils import INPUT_PATH, OUTPUT_PATH, get_root_path, path_join

if __name__ == '__main__':
    # 获取图像
    SRC_IMG = path_join("reinhard", "sea", "day.png")
    REF_IMG = path_join("reinhard", "sea", "night.png")
    root_path = get_root_path()
    src_ic = ImageController(file=path_join(root_path, INPUT_PATH, SRC_IMG))
    ref_ic = ImageController(file=path_join(root_path, INPUT_PATH, REF_IMG))
    a = Matrix.conv2(src_ic.cvt_GRAY(), Matrix.SOBEL_KERNEL_X)
    cv2.imshow("conv2", a)
    cv2.waitKey()
    cv2.destroyAllWindows()
Esempio n. 2
0
    thread = UpdateSuperPixelThread(low, hi, threads_num)
    thread.start()
    threads.append(thread)

    # 多线程等待结束
    for t in threads:
        t.join()

    src_img.as_unit().cvt_GRAY()
    ref_img.as_unit().cvt_BGR()
    return res_img.as_unit().cvt_BGR()


if __name__ == '__main__':
    root_path = pu.get_root_path()
    src_img = ImageController(pu.path_join(root_path, pu.INPUT_PATH, SRC_IMG),
                              clr="GRAY")
    ref_img = ImageController(pu.path_join(root_path, pu.INPUT_PATH, REF_IMG))

    res_img = gray_trans_superpixel(src_img, ref_img)

    iu.print_imgs(src_img, ref_img, res_img)
    iu.save_img(
        res_img.ndarray,
        pu.path_join(
            root_path, pu.OUTPUT_PATH, f"gray_trans/superpixel/coast/res_img"
            f"_{w[0][0]}"
            f"_{w[1][0]}"
            f"_{ SRC_SUPERPIXEL_NUM }"
            f"_{ REF_SUPERPIXEL_NUM }.png"))
Esempio n. 3
0
import sys
import os

PROJECT_NAME = "ColorTrans"

cur_path = os.path.abspath(os.path.dirname(__file__))
root_path = cur_path[:cur_path.find(PROJECT_NAME + os.path.sep) +
                     len(PROJECT_NAME + os.path.sep)]
sys.path.append(os.path.join(root_path))

from src.algorithm.gray_trans.gray_trans import gray_trans
from src.image_control.core.control import ImageController
from src.common_utils.core import path_utils as pu
from src.common_utils.core import image_utils as iu

if __name__ == '__main__':
    SRC_IMG = "gray_trans/src_img.png"
    REF_IMG = "gray_trans/ref_img.png"
    root_path = pu.get_root_path()
    src_img = ImageController(pu.path_join(root_path, pu.INPUT_PATH, SRC_IMG),
                              clr="GRAY")
    ref_img = ImageController(pu.path_join(root_path, pu.INPUT_PATH, REF_IMG))

    res_img = gray_trans(src_img, ref_img)

    iu.print_imgs(src_img.ndarray, ref_img.ndarray, res_img.ndarray)
    # iu.save_img(res_img.ndarray, pu.path_join(root_path, pu.OUTPUT_PATH, "gray_trans/res_img.png"))
Esempio n. 4
0
import src.common_utils.core.image_utils as iu
import src.common_utils.core.path_utils as pu
from src.image_control.core.control import ImageController
import cv2

if __name__ == "__main__":
    root_path = pu.get_root_path()

    # Test Resize
    # input_filename = pu.path_join("reinhard", "flowers", "red_flower_275_183.jpeg")
    input_filename = pu.path_join("gray_trans", "src_img.png")
    input_path = pu.path_join(root_path, pu.INPUT_PATH, input_filename)
    ic = ImageController(input_path, clr="GRAY")
    slic = ic.superpixel.seeds(200, 15)
    mask_slic = slic.getLabelContourMask()  # 获取Mask,超像素边缘Mask==1
    label_slic = slic.getLabels()  # 获取超像素标签
    number_slic = slic.getNumberOfSuperpixels()  # 获取超像素数目
    mask_inv_slic = cv2.bitwise_not(mask_slic)
    img_slic = cv2.bitwise_and(ic.ndarray, ic.ndarray, mask=mask_inv_slic)  # 在原图上绘制超像素边界
    cv2.imshow("img_slic", img_slic)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

    # iu.print_imgs(ic.copy(),
    #               ic.cvt_LAB().copy(),
    #               ic.cvt_HSV().copy(),
    #               ic.cvt_HLS().copy(),
    #               ic.cvt_BGR().copy(),
    #               ic.cvt_RGB().copy(),
    #               ic.cvt("GRAY"))
    # ic.resize(output_path, True, 64, 64)
Esempio n. 5
0
    thread = UpdateThread(low, h_src, threads_num)
    thread.start()
    threads.append(thread)

    # 多线程等待结束
    for t in threads:
        t.join()

    src_img.as_unit().cvt_GRAY()
    ref_img.as_unit().cvt_BGR()
    return res_img.as_unit().cvt_BGR()


if __name__ == '__main__':
    root_path = pu.get_root_path()
    src_img = ImageController(pu.path_join(root_path, pu.INPUT_PATH, SRC_IMG),
                              clr="GRAY")
    ref_img = ImageController(pu.path_join(root_path, pu.INPUT_PATH, REF_IMG))

    res_img = gray_trans(src_img, ref_img)

    iu.print_imgs(src_img.ndarray, ref_img.ndarray, res_img.ndarray)

    iu.save_img(
        res_img.ndarray,
        pu.path_join(
            root_path, pu.OUTPUT_PATH,
            f"gray_trans/coast/res_img_{ WINDOW_SIZE }_{ SWATCHES_NUM }.png"))

    # out1 = ImageController(pu.path_join(root_path, pu.OUTPUT_PATH, "gray_trans/trees/res_img_5_1000.png"))
    # out2 = ImageController(pu.path_join(root_path, pu.OUTPUT_PATH, "gray_trans/trees/res_img_10_1000.png"))
Esempio n. 6
0
    # res_vec[::, 0] = res_vec_corr[::, 0] / res_vec_corr[::, 3]
    # res_vec[::, 1] = res_vec_corr[::, 1] / res_vec_corr[::, 3]
    # res_vec[::, 2] = res_vec_corr[::, 2] / res_vec_corr[::, 3]
    res_vec = res_vec_corr[::, 0:3]
    res_mat = res_vec.reshape(src_img.ndarray.shape)

    res = ImageController(matrix=res_mat, clr="RGB").as_unit()
    src_img.cvt_BGR()
    ref_img.cvt_BGR()
    return res.cvt_BGR()


if __name__ == '__main__':
    # 获取图像
    root_path = get_root_path()
    src_ic = ImageController(file=path_join(root_path, INPUT_PATH, SRC_IMG))
    ref_ic = ImageController(file=path_join(root_path, INPUT_PATH, REF_IMG))
    output_path = path_join(root_path, OUTPUT_PATH, "test", "scene4",
                            "12am_10pm_rgb.jpg")

    # cv2.imshow("src", src_ic.ndarray)
    # cv2.waitKey()
    # cv2.imshow("ref", ref_ic.ndarray)
    # cv2.waitKey()
    res_img = rgb_trans(src_ic, ref_ic)
    # cv2.imshow("res", res_img.ndarray)
    # cv2.waitKey()
    # cv2.destroyAllWindows()

    iu.save_img(res_img.ndarray, output_path)
Esempio n. 7
0
    img[..., 1] *= ref_std[1] / src_std[1]
    img[..., 2] *= ref_std[2] / src_std[2]

    img[np.isnan(img)] = 0

    # 加上目标图像均值
    img[..., 0] += ref_m[0]
    img[..., 1] += ref_m[1]
    img[..., 2] += ref_m[2]

    # 保存图像
    src.as_unit()
    res = ImageController(matrix=img, clr="LAB")
    return res.as_unit().cvt_BGR()


if __name__ == "__main__":
    # 获取图像
    SRC_IMG = path_join("test", "scene4", "10pm.jpg")
    REF_IMG = path_join("test", "scene4", "3pm.jpg")
    OUTPUT_IMG = path_join("test", "scene4", "3pm_10pm_reinhard.jpg")
    root_path = get_root_path()
    src_ic = ImageController(file=path_join(root_path, INPUT_PATH, SRC_IMG))
    ref_ic = ImageController(file=path_join(root_path, INPUT_PATH, REF_IMG))

    # reinhard
    cv2.imwrite(path_join(root_path, OUTPUT_PATH, OUTPUT_IMG),
                reinhard(src_ic, ref_ic).ndarray)
    # cv2.waitKey()
    # cv2.destroyAllWindows()