1

I'm working on a grayscale .tif file:

piece from original picture

I convert it to BGR and try to draw some colorful stuff on it. If I save the result as .png, it's all still in shades of gray, including the drawn elements. If I save it as .jpg, colors of them are okay, but the rest of image is a lot brighter than it was, which I definitely don't want to happen.

same piece from jpg result picture

simplified example of what I'm trying to do:

def draw_lines(image_path):
    image = cv2.cvtColor(cv2.imdecode(np.fromfile(image_path, dtype=np.uint8), cv2.IMREAD_UNCHANGED), cv2.COLOR_GRAY2BGR)

    cv2.line(image, (0,10), (image.shape[1], 1000), (0, 255, 0), 10)

    cv2.imwrite("result.jpg", image)
Aristu
  • 761
  • 3
  • 17
  • 30
Pen Guin
  • 11
  • 1

1 Answers1

0

I'm not exactly sure why, but apparently the problem was caused by usage of flag cv2.IMREAD_UNCHANGED After changing this line to image = cv2.imdecode(np.fromfile(image_path, dtype=np.uint8), cv2.IMREAD_COLOR) everything works fine, no matter which extension

Pen Guin
  • 11
  • 1