Categories
Misc

Error Converting Image to Luma channel

I’m trying to convert an RGB image into the luma channel, similar to how it is done in PIL, but I cannot find a good way to do this.

I have tried with tensorflow_io and the values are incorrect.

with tensorflow_io

img_file = tf.io.read_file(“./img/img.jpg”) img = tf.image.decode_jpeg(img_file, channels=3) luma = tfio.experimental.color.rgb_to_ycbcr(img)[:,:,0] luma.numpy() “”” Value: array([[ 22, 22, 22, …, 21, 21, 21], [ 22, 22, 22, …, 21, 21, 21], [ 22, 22, 22, …, 21, 21, 21], …, [159, 159, 156, …, 51, 48, 48], [158, 158, 158, …, 50, 46, 46], [226, 226, 227, …, 230, 231, 231]], dtype=uint8) “””

with PIL

im = Image.open(“./img/img.jpg”) im = im.convert(“L”) np.asarray(im) “”” Value: array([[ 8, 8, 8, …, 6, 6, 6], [ 8, 8, 8, …, 6, 6, 6], [ 8, 8, 8, …, 6, 6, 6], …, [168, 167, 165, …, 41, 38, 38], [167, 167, 167, …, 42, 37, 37], [246, 246, 247, …, 251, 253, 253]], dtype=uint8) “””

Am I doing something wrong here?

submitted by /u/potato-sword
[visit reddit] [comments]

Leave a Reply

Your email address will not be published. Required fields are marked *