Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Unable to detect black pixels ?

I am reading a picture to color in red all its black pictures:

import numpy as np
import cv2

second=cv2.imread('second.png')

for i in range(second.shape[0]):
   for j in range(second.shape[1]):
       if second[i,j,0]!=0 and second[i,j,1]!=0 and second[i,j,2]!=0:
           second[i,j,0]=0
           second[i,j,1]=0
           second[i,j,2]=255
cv2.imwrite('result.png',second)

Here is the image second.png:

enter image description here

Here is the colored image result.png: enter image description here

Why not all the yellow rose is not colored in red ? Note when I print those pixels that are not colored (in red in result.png) in second.png I see they are not black. Why this ?

Unable to detect black pixels ?

I am reading a picture to color in red all its black pictures:pixels (the background only is black):

import numpy as np
import cv2

second=cv2.imread('second.png')

for i in range(second.shape[0]):
   for j in range(second.shape[1]):
       if second[i,j,0]!=0 and second[i,j,1]!=0 and second[i,j,2]!=0:
           second[i,j,0]=0
           second[i,j,1]=0
           second[i,j,2]=255
cv2.imwrite('result.png',second)

Here is the image second.png:

enter image description here

Here is the colored image result.png: enter image description here

Why not all the yellow rose is not colored in red ? Note when I print those pixels that are not colored (in red in result.png) in second.png I see they are not black. Why this ?