Esempio n. 1
0
    def getContasrtMeasure(self, rgb):
        lum = colour.RGB_to_HSL(rgb)[:, 2]

        #正規化
        lum = (lum - np.min(lum)) / (np.max(lum) - np.min(lum))

        return np.var(lum)
Esempio n. 2
0
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.")
Esempio n. 3
0
    def getBrightnessMeasure(self, rgb):
        Y = colour.RGB_to_YCbCr(rgb)[:, 0]
        lum = colour.RGB_to_HSL(rgb)[:, 2]

        return np.c_[np.mean(Y),
                     np.var(Y),
                     np.min(Y),
                     np.max(Y),
                     np.mean(lum),
                     np.var(lum),
                     np.min(lum),
                     np.max(lum)]
Esempio n. 4
0
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))

print('\n')

HSL = np.array([0.27867384, 0.94897959, 0.61568627])
message_box(('Converting to "RGB" colourspace from given "HSL" colourspace '
             'values:\n'
             '\n\t{0}'.format(HSL)))
print(colour.HSL_to_RGB(HSL))

print('\n')

message_box(('Converting to "CMY" colourspace from given "RGB" colourspace '
             'values:\n'
             '\n\t{0}'.format(RGB)))
print(colour.RGB_to_CMY(RGB))
Esempio n. 5
0
    def getSaturationMeasure(self, rgb):
        sat = colour.RGB_to_HSL(rgb)[:, 1]

        return np.c_[np.mean(sat), np.var(sat), np.min(sat), np.max(sat)]
Esempio n. 6
0
    def getSatDistance(self, rgb1, rgb2):
        sat1 = colour.RGB_to_HSL(rgb1)[:, 1]
        sat2 = colour.RGB_to_HSL(rgb2)[:, 1]

        return mean_squared_error(sat1, sat2)
Esempio n. 7
0
    #正規化と整形
    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)
    satDist[it] = getSatDistance(rgb, initialRGB)
    CFM[it] = ColorFidelityMetric(initialRGB, rgb)
Esempio n. 8
0
def rgb_to_l(r, g, b):
    RGB = np.array([r, g, b])
    HSL = colour.RGB_to_HSL(RGB)
    return HSL