MCPcopy Create free account
hub / github.com/VisionXLab/OF-Diff / bgr2ycbcr

Function bgr2ycbcr

ldm/modules/image_degradation/utils_image.py:573–594  ·  view source on GitHub ↗

bgr version of rgb2ycbcr only_y: only return Y channel Input: uint8, [0, 255] float, [0, 1]

(img, only_y=True)

Source from the content-addressed store, hash-verified

571
572
573def bgr2ycbcr(img, only_y=True):
574 '''bgr version of rgb2ycbcr
575 only_y: only return Y channel
576 Input:
577 uint8, [0, 255]
578 float, [0, 1]
579 '''
580 in_img_type = img.dtype
581 img.astype(np.float32)
582 if in_img_type != np.uint8:
583 img *= 255.
584 # convert
585 if only_y:
586 rlt = np.dot(img, [24.966, 128.553, 65.481]) / 255.0 + 16.0
587 else:
588 rlt = np.matmul(img, [[24.966, 112.0, -18.214], [128.553, -74.203, -93.786],
589 [65.481, -37.797, 112.0]]) / 255.0 + [16, 128, 128]
590 if in_img_type == np.uint8:
591 rlt = rlt.round()
592 else:
593 rlt /= 255.
594 return rlt.astype(in_img_type)
595
596
597def channel_convert(in_c, tar_type, img_list):

Callers 1

channel_convertFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected