def convert_color_space_from_rgb(
        np_image: np.ndarray, dest_color_space: Optional[str]) -> np.ndarray:
    if dest_color_space is None or dest_color_space == "RGB":
        return np_image
    elif dest_color_space == "HSV":
        return colour.RGB_to_HSV(np_image)
    elif dest_color_space == "HSL":
        return colour.RGB_to_HSL(np_image)
    elif dest_color_space == "CMY":
        return colour.RGB_to_CMY(np_image)
    else:
        raise ValueError("Undefined color space.")
Beispiel #2
0
def find_most_saturated(im, x, y, search_size):
    if search_size < 1:
        r, g, b = im.getpixel((x, y))
        return (x, y, r, g, b)

    highest_s = -1.0
    highest = (-1, -1, 0, 0, 0)
    for xp in range(x - search_size, x + search_size + 1):
        for yp in range(y - search_size, y + search_size + 1):
            r, g, b = im.getpixel((xp, yp))
            rgb = np.array([r / 255.0, g / 255.0, b / 255.0])
            s = colour.RGB_to_HSV(rgb)[1]
            if s > highest_s:
                highest_s = s
                highest = (xp, yp, r, g, b)
    return highest
Beispiel #3
0
def color_convert_hsv(RGB_color):
    arr_RGB_color = np.array(RGB_color)
    list_rgb_color = arr_RGB_color.tolist()
    float_arr_RGB_color = arr_RGB_color / 255
    float_tp_RGB_color = tuple(float_arr_RGB_color)
    HSV_color = colour.RGB_to_HSV(float_tp_RGB_color)
    HSV_color2 = np.array([
        round(HSV_color[0] * 359, 3),
        round(HSV_color[1] * 100, 3) - 4,
        round(HSV_color[2] * 100, 3) + 8
    ])
    #     print("HSV 값 : ", HSV_color2)
    HSV_color2 = list(HSV_color2)
    HSV_color2[0] = round(HSV_color2[0], 2)
    HSV_color2[1] = round(HSV_color2[1], 2)
    HSV_color2[2] = round(HSV_color2[2], 2)
    return HSV_color2
Beispiel #4
0
imgInputPath = "outimg/FinalResult/BlendImage/"
enhancedImgInputpath = "outimg/FinalResult/EnhancedImage/"
imgOutputPath = "outimg/FinalResult/FinalSignalImage/"
imgFileName = sys.argv[1]
enhancedFileName = sys.argv[2]

#ブレンドした画像の読み込み
RGB, imgH, imgW = getImageRGBFromPath(imgInputPath + imgFileName + ".jpg")
inputRGB = np.copy(RGB)
maskRGB = np.copy(RGB)
analyzedRGB = np.copy(RGB)
enhancedRGB, w, h = getImageRGBFromPath(enhancedImgInputpath +
                                        enhancedFileName + ".jpg")

HSV = colour.RGB_to_HSV(enhancedRGB)

#低彩度値の画素を抽出
achromaticWhitePixelBool = np.where((HSV[:, 2] >= 0.86) & (HSV[:, 1] <= 0.27))
achromaticBlackPixelBool = np.where(HSV[:, 2] <= 0.25)

#対象領域の着色
maskRGB[achromaticWhitePixelBool] = np.array([1, 1, 0])
maskRGB[achromaticBlackPixelBool] = np.array([1, 0, 0])

#無彩色変換
analyzedRGB[achromaticWhitePixelBool] = HSV[achromaticWhitePixelBool,
                                            2].reshape(
                                                (-1,
                                                 1)) * np.transpose(Wtarget)
analyzedRGB[achromaticBlackPixelBool] = HSV[achromaticBlackPixelBool,
Beispiel #5
0
Showcases deprecated colour models computations.
"""

import numpy as np

import colour
from colour.utilities import message_box

message_box(('Deprecated Colour Models Computations\n'
             '\nDon\'t use that! Seriously...'))

RGB = np.array([0.49019608, 0.98039216, 0.25098039])
message_box(('Converting to "HSV" colourspace from given "RGB" colourspace '
             'values:\n'
             '\n\t{0}'.format(RGB)))
print(colour.RGB_to_HSV(RGB))

print('\n')

HSV = np.array([0.27867384, 0.74400000, 0.98039216])
message_box(('Converting to "RGB" colourspace from given "HSV" colourspace '
             'values:\n'
             '\n\t{0}'.format(HSV)))
print(colour.HSV_to_RGB(HSV))

print('\n')

message_box(('Converting to "HSL" colourspace from given "RGB" colourspace '
             'values:\n'
             '\n\t{0}'.format(RGB)))
print(colour.RGB_to_HSL(RGB))
Beispiel #6
0
    def initialize(self):
        # fig_size = plt.rcParams["figure.figsize"]
        # fig_size[0] = 14
        # fig_size[1] = 5
        # plt.rcParams["figure.figsize"] = fig_size
        f = open('gt.txt', 'r')
        cc = []
        for video_id in range(1, 101):
            print(video_id)

            image = cv2.cvtColor(
                Image.load(self.video_path + '/' + str(video_id) +
                           '/average10.jpg'), cv2.COLOR_BGR2RGB)
            image = image[:int(image.shape[0] / 2), :]
            w = image.shape[1] // 5
            h = image.shape[0] // 5
            image = cv2.resize(image, (w, h))
            hsvIm = np.array(image)
            for i in range(0, image.shape[0]):
                for j in range(0, image.shape[1]):
                    rgb = image[i][j] / 255.0
                    hsv = colour.RGB_to_HSV(rgb)
                    hsv = [
                        int(hsv[0] * 360),
                        int(hsv[1] * 255),
                        int(hsv[2] * 255)
                    ]
                    hsvIm[i][j] = hsv

            hBin = 360
            vBin = 255
            #hHist, hX = np.histogram([hsvIm[x][y][0] for x in range(0, h) for y in range(0, w) if hsvIm[x][y][1] < 125], hBin, (0, 360))
            hHist, hX = np.histogram(hsvIm[:, :, 0].flatten(), hBin, (0, 360))
            vHist, vX = np.histogram(hsvIm[:, :, 2].flatten(), vBin, (0, 255))

            nH = (np.sum(hHist[0:72]) + np.sum(hHist[288:])) / (h * w)
            nV = np.sum(vHist[124:]) / (h * w)

            print(nH, nV)

            if nV < 0.289:
                result = 'night'
            else:
                result = 'day'
            gt = f.readline()[:-1]
            print(result, gt)
            #result = gt
            cc.append((nH, nV, gt))

            # if nH < 0.654 and nH > 0.04:
            #     if nV > 0.126 and nV < 0.197:
            #         result = 'day'
            #     else:
            #         result = 'night'
            # else:
            #     if nV > 0.108:
            #         if nH < 0.57:
            #             result = 'day'
            #         else:
            #             result = 'night'
            #     else:
            #         result = 'night'

            # if (result != gt):
            #     fig, (ax1, ax2, ax3) = plt.subplots(1, 3)
            #     ax1.plot(hX[:-1], hHist, color='r')
            #     #ax1.plot(_[:-1], sHist, color='g')
            #     ax2.plot(vX[:-1], vHist, color='b')
            #     ax3.set_title(result)
            #     ax3.imshow(image)
            #     plt.show()
        dayList = [x for x in cc if (x[2] == 'day')]
        nightList = [x for x in cc if (x[2] == 'night')]
        plt.scatter([x[0] for x in dayList], [x[1] for x in dayList], c='r')
        plt.scatter([x[0] for x in nightList], [x[1] for x in nightList],
                    c='b')
        plt.show()
Beispiel #7
0
    path = "outimg/continuity_hue/Natural/" + imgName + "_" + str(it) + ".jpg"
    inputImg = cv2.imread(path, cv2.IMREAD_COLOR)

    #正規化と整形
    inputImg = cv2.cvtColor(inputImg, cv2.COLOR_BGR2RGB) / 255.
    rgb = np.reshape(inputImg, (inputImg.shape[0] * inputImg.shape[1], 3))

    #初期画像の保存
    if (it == 0):
        initialRGB = rgb

    #色空間の変換
    if COLOR_SPACE is "RGB":
        pixel = rgb
    elif COLOR_SPACE is "HSV":
        pixel = colour.RGB_to_HSV(rgb)
    elif COLOR_SPACE is "HSL":
        pixel = colour.RGB_to_HSL(rgb)

    aveGrads[it] = getAveGrad(pixel)
    entropys[it] = getEntropy(pixel)
    moment, cov = getColorMoment(pixel)
    moments[it] = moment
    colorDist[it] = getDistance(initialRGB, rgb)
    measures[it] = getImageMeasure(initialRGB, rgb)

    SatMeasures[it] = getSaturationMeasure(rgb)
    colorfulness[it] = getColourFulness(rgb)
    naturalness[it] = getNaturalness(rgb)
    contrast[it] = getContasrtMeasure(rgb)
    brightness[it] = getBrightnessMeasure(rgb)
Beispiel #8
0
def color_convert(cheek, file_name):
    img = cheek
    img = cv.cvtColor(img, cv.COLOR_BGR2RGB)
    #     plt.imshow(img)
    #     plt.show()

    sum = 0
    R = []
    G = []
    B = []
    for i in img:
        for j in i:
            R.append(j[0])
            G.append(j[1])
            B.append(j[2])

    R_sum = 0
    G_sum = 0
    B_sum = 0

    # 각 R, G, B의 합계 구하기
    for i in range(len(R)):
        R_sum += R[i]
        G_sum += G[i]
        B_sum += B[i]

    R_avg = int(round((R_sum / len(R)), 0))  # R값 평균
    G_avg = int(round((G_sum / len(G)), 0))  # G값 평균
    B_avg = int(round((B_sum / len(B)), 0))  # B값 평균
    RGB_color = [R_avg, G_avg, B_avg]

    # 평균 색만 그래프 그리기 위함 img_avg
    img_avg = img

    for i in img_avg:
        for j in i:
            j[0] = R_avg
            j[1] = G_avg
            j[2] = B_avg

    # 기존
    #     plt.imshow(img)
    #     plt.show()

    # 평균색
    #     plt.imshow(img_avg)
    #     plt.show()
    bgr_img_avg = cv.cvtColor(img_avg, cv.COLOR_RGB2BGR)

    # 저장
    #     cv.imwrite("../img/"+file_name+"_9.jpg", bgr_img_avg)

    arr_RGB_color = np.array(RGB_color)
    float_arr_RGB_color = arr_RGB_color / 255
    float_tp_RGB_color = tuple(float_arr_RGB_color)
    HSV_color = colour.RGB_to_HSV(float_tp_RGB_color)
    HSV_color2 = np.array([
        round(HSV_color[0] * 359, 3),
        round(HSV_color[1] * 100, 3) - 4,
        round(HSV_color[2] * 100, 3) + 8
    ])
    HSV_color2 = list(HSV_color2)
    HSV_color2[0] = round(HSV_color2[0], 2)
    HSV_color2[1] = round(HSV_color2[1], 2)
    HSV_color2[2] = round(HSV_color2[2], 2)
    return HSV_color2