0

So I have this original image:

Original

Then I have it's YDbDR conversion:

enter image description here

it's separated by red, blue and green channels which I know aren't equivalent to YDbDr, but should give a good general gauge on whether the channels have been converted correctly. As you can see Db and Dr equivalently are heavily pixelated when they shouldn't be.

Here's the code:

def RGB_to_YDbDr(obs_RGB):
    r = obs_RGB[:, 0]
    g = obs_RGB[:, 1]
    b = obs_RGB[:, 2]

    y = 0.299 * r + 0.587 * g + 0.114 * b
    db = -0.450 * r + -0.883 * g + 1.333 * b
    dr = -1.333 * r + 1.116 * g + 0.217 * b

    return torch.stack([y, db, dr], -3)

I followed Kornia augmentation library's code for RGB to YCbCr to implement RGB to YDbDr. What did I do wrong? Why does Db and Dr look so pixelated? The input images are 100 x 100.

Note: I tried kornia.color.rgb_to_ycbcr and got this: enter image description here
Also seems very heavily pixelated

Gooby
  • 621
  • 2
  • 11
  • 32

1 Answers1

3

enter image description here

Look closely. Your source image is compressed already. What you see is the "chroma subsampling" that is done by image compression. You see blocks of color distortion.

That is exactly what you see in your color (chroma) planes.

Nooo this has nothing to do with plotting or anything. Your source image is compressed. You can only fix that if you have an uncompressed source image, or one that isn't so severely compressed.

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
  • so the compression is done by a simulator. I unfortunately don't have the ability to get the original image unless I do some monkey patching I presume. – Gooby Jun 21 '22 at 14:57
  • you could ask it to make larger pictures, and if you need them to be 100x100, shrink them yourself and save with better compression. – Christoph Rackwitz Jun 21 '22 at 14:59
  • unfortunately I need the image to be 100x100. Perhaps I could use your suggestion if there was a better image compression algorithm than what the simulator is using. Can you suggest one? – Gooby Jun 21 '22 at 15:01
  • uh.... I don't understand why you have that question. just use JPEG, but with better quality factor. or use png. or use plain bitmaps. – Christoph Rackwitz Jun 21 '22 at 15:05
  • the reason I ask is because the simulator doesn't generate the images as image files, it generates it as numpy arrays. – Gooby Jun 21 '22 at 15:07