Picture in rgb mode convert to L mode, Problem with soft picture edges

Hi there,
I’am working on an Object Detection with my own Data. Now I have the Problem than my pictures of the masks are in RGB mode but I need to convert them to L Mode. I have done thins with .convert(‘L’). But now I have a Problem with my edges. If you look at this picture

the edges are not yellow. Do you have an idea how to convert it correctly? Before converting the picture was just black and yellow.
Thanks for help.

This issue doesn’t seem to be directly related to PyTorch, so you might get faster and better answers on e.g. StackOverflow.

That being said, I guess that that original image might also contain these artifacts.
If the input image was just a binary image encoded as an RGB image, you could apply some smoothing and binarization to try to get rid of these noisy edges.

Thanks for answer. I think I found the problem:
I set the colors of the picture in python, there all Pixels have the correct color. But if I save the picture as a jpg to download, the colors get wrong. Do you know how to fix this issue?

JPEG uses an internal encoding, which might create these artifacts. I don’t know which software or platform you are using, but you might be able to increase the quality level.
If that’s not possible, try to download these pictures in another format.