def test_rgb_lch_roundtrip(self): rgb = img_as_float(self.img_rgb) lab = rgb2lab(rgb) lch = lab2lch(lab) lab2 = lch2lab(lch) rgb2 = lab2rgb(lab2) assert_array_almost_equal(rgb, rgb2)
def test_rgb_lch_roundtrip(self): rgb = img_as_float(self.img_rgb) lab = rgb2lab(rgb) lch = lab2lch(lab) lab2 = lch2lab(lch) rgb2 = lab2rgb(lab2) assert_array_almost_equal(rgb, rgb2)
def change_hue(img, hue): lab_img = rgb2lab(img) lch_img = lab2lch(lab_img) lch_img[:, :, 2] = hue lab_img = lch2lab(lch_img) rgb_img = lab2rgb(lab_img) return rgb_img
def test_lab_lch_roundtrip_dtypes(dtype): rgb = img_as_float(data.colorwheel()).astype(dtype=dtype, copy=False) lab = rgb2lab(rgb) float_dtype = _supported_float_type(dtype) assert lab.dtype == float_dtype lab2 = lch2lab(lab2lch(lab)) decimal = 4 if float_dtype == np.float32 else 7 assert_array_almost_equal(lab2, lab, decimal=decimal)
def test_lab_lch_roundtrip(self, channel_axis): rgb = img_as_float(self.img_rgb) rgb = np.moveaxis(rgb, source=-1, destination=channel_axis) lab = rgb2lab(rgb, channel_axis=channel_axis) lab2 = lch2lab( lab2lch(lab, channel_axis=channel_axis), channel_axis=channel_axis, ) assert_array_almost_equal(lab2, lab)
def lch2rgb(lch): """Convert LCH to RGB colorspace (via LAB) Input and output are in (bands, cols, rows) order """ # reshape for skimage (bands, cols, rows) -> (cols, rows, bands) slch = np.swapaxes(lch, 0, 2) # convert colorspace rgb = lab2rgb(lch2lab(slch)) # return in (bands, cols, rows) order return np.swapaxes(rgb, 2, 0)
def change_color_lch(batch_id, pal_lab, pal_name): file_path = './samples/img/' result_path = './samples/result_lch/' file_list = os.listdir(file_path) pal_lch = lab2lch(pal_lab) for _, name in enumerate(file_list): img_ori = plt.imread(file_path + name) img_lab = rgb2lab(img_ori) img_lch = lab2lch(img_lab) counter_lch = [0, 0, 0, 0, 0, 0, 0] for i in range(len(img_lch)): for j in range(len(img_lch[i])): point_ori = img_lch[i][j][2] total_diff_last = 11 # lot((1-0)^2 + (1-0)^2) +1 for k in range(5): point_pal = pal_lch[k][2] total_diff = abs(point_ori - point_pal) # 180 도 이상 처리 예각으로 대체 if total_diff > 5: total_diff = 10 - total_diff counter_lch[6] += 1 if total_diff < total_diff_last: point_ori_tmp = point_pal total_diff_last = total_diff counter_fin = k if img_lch[i][j][1] <= 0.2 and img_lch[i][j][ 0] >= 9.8: # 채도 3 이하 명도 98 이상 패스(흰색) counter_lch[5] += 1 # elif total_diff_last >= 1.2: #1.41 # counter_hsv[6] += 1 else: counter_lch[counter_fin] += 1 img_lch[i][j][2] = point_ori_tmp sum_total = counter_lch[0] + counter_lch[1] + counter_lch[ 2] + counter_lch[3] + counter_lch[4] + counter_lch[5] print( f'[{pal_name}의 {name[0:-4]} 적용 내역] 팔레트1:{counter_lch[0]:,}회, 팔레트2:{counter_lch[1]:,}회, ' f'팔레트3:{counter_lch[2]:,}회, 팔레트4:{counter_lch[3]:,}회, 팔레트5:{counter_lch[4]:,}회, ' f'흰색 패스:{counter_lch[5]:,}회, 팔레트 변환 :{sum_total-counter_lch[5]:,}회' f'({sum_total-counter_lch[5]-counter_lch[6]:,}회), 총 변환 :{sum_total:,}회' ) img_trans = lch2lab(img_lch) img_trans = lab2rgb(img_trans, illuminant='D55') plt.imsave( os.path.join(result_path, f'{batch_id}_{pal_name}_{name[0:-4]}.png'), img_trans)
def preserve_color_cielch(content, stylized, image_name): # extract info and convert to CIE-LCh for each image rgbContent = io.imread(content) labContent = color.lab2lch( color.xyz2lab(color.rgb2xyz(numpy.asarray(rgbContent)))) labContentArray = numpy.array(labContent) rgbStyle = io.imread(stylized) labStyle = color.lab2lch( color.xyz2lab(color.rgb2xyz(numpy.asarray(rgbStyle)))) labStyleArray = numpy.array(labStyle) # color transfer for i in range(len(labContentArray)): for j in range(len(labContentArray[0])): labContentArray[i][j][0] = labStyleArray[i][j][0] labContentArray = color.xyz2rgb( color.lab2xyz(color.lch2lab(labContentArray))) viewer = ImageViewer(labContentArray) viewer.show()
def test_lab_lch_roundtrip(self): rgb = img_as_float(self.img_rgb) lab = rgb2lab(rgb) lab2 = lch2lab(lab2lch(lab)) assert_array_almost_equal(lab2, lab)
REEXP_FOLDER_SCALE = r'\S*scale-(\d+)pc' # ERROR:root:error: Image size (... pixels) exceeds limit of ... pixels, # could be decompression bomb DOS attack. # SEE: https://gitlab.mister-muffin.de/josch/img2pdf/issues/42 Image.MAX_IMAGE_PIXELS = None #: maximal image size for visualisations, larger images will be downscaled MAX_IMAGE_SIZE = 5000 #: define pair of forward and backward color space conversion CONVERT_RGB = { 'rgb': (lambda img: img, lambda img: img), 'hsv': (rgb2hsv, hsv2rgb), 'lab': (rgb2lab, lab2rgb), 'luv': (rgb2luv, luv2rgb), 'hed': (rgb2hed, hed2rgb), 'lch': (lambda img: lab2lch(rgb2lab(img)), lambda img: lab2rgb(lch2lab(img))), } def detect_binary_blocks(vec_bin): """ detect the binary object by beginning, end and length in !d signal :param list(bool) vec_bin: binary vector with 1 for an object :return tuple(list(int),list(int),list(int)): >>> vec = np.array([1] * 15 + [0] * 5 + [1] * 20) >>> detect_binary_blocks(vec) ([0, 20], [15, 39], [14, 19]) """ begins, ends, lengths = [], [], []
return color.xyz2lab(tmp_xyz) def hsb2lab(shb_pic): tmp_rgb = color.hsv2rgb(hsv) tmp_xyz = color.rgb2xyz(tmp_rgb) return color.xyz2lab(tmp_xyz) def hsi2lab(shi_pic): tmp_rgb = color.hsv2rgb(hsv) tmp_xyz = color.rgb2xyz(tmp_rgb) return color.xyz2lab(tmp_xyz) show_lch2lab = color.lch2lab(lch) print("show_lch2lab") print_pic(show_lch2lab) show_rgb2lab = color.rgb2lab(Rgb) print("show_rgb2lab") print_pic(show_rgb2lab) show_hsv2lab = hsv2lab(hsv) print("show_hsv2lab") print_pic(show_hsv2lab) show_hsb2lab = hsb2lab(hsb) print("show_hsb2lab") print_pic(show_hsb2lab)
def test_lab_lch_roundtrip(self): rgb = img_as_float(self.img_rgb) lab = rgb2lab(rgb) lab2 = lch2lab(lab2lch(lab)) assert_array_almost_equal(lab2, lab)
def lch2rgb(lch): lab = color.lch2lab(lch) return color.lab2rgb(lab)
def surface(s, t): LCH = np.stack((L(s, t, grid=False), C(s, t, grid=False), H(s, t, grid=False)), axis=-1) return color.lch2lab(LCH)
def curve(t): LCH = np.stack((L(t), C(t), H(t)), axis=-1) return color.lch2lab(LCH)
def lch2rgb(lch): return color.lab2rgb(color.lch2lab(lch.astype(float))) * 255