0

as you can see in the code, I have a completely white image. Then I assign the color green to certain pixels, while iterating over the image. However, in the result image, there are pixels with shades of green and not just one green color. This is the code:

height, width = drawImage1.shape

# creating a blank white image
drawImage2 = np.zeros((height,width,3), np.uint8)
drawImage2[:] = (255,255,255)

for x in range(height):
    for y in range(width):
        if(drawImage1[x,y] == 0):
            drawImage2[x,y] = [0,255,0]

cv2.imwrite('alignmentResult.jpg', drawImage2)

enter image description here Here you see a zoomed-in screenshot from windows photo viewer. I get the same result, with other photo programs.

Does anyone have an idea, how this is possible, since there is only one color specified. Maybe this is added just to make the image preview more smooth for the human eye.

Thanks alot!

I have tried to use a binarized image (that is obviously fully black and white) and then converted in back to color. But I got the same result.

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
Nick
  • 1
  • 2
    It might be related either to compression added by jpg encoder during saving or image viewer program that apply some interpolation when zoomed in. Does changing file extension to png -> `cv2.imwrite('alignmentResult.png', drawImage2)` changes anything? – Piotr Siekański Jun 07 '23 at 09:59
  • The jpg file type was the issue. Thank you very much!! With png it works perfectly fine :) – Nick Jun 07 '23 at 10:04

0 Answers0