how to follow a pix value by checking the neighbors 3x3 in x,y imread()

asked 2020-05-21 19:01:24 -0600

tshep gravatar image

i have a black image with blue lines i did this this to turn each blue pix into red pix

img=cv2.imread("bluelines.jpg")
for x in range (0, width+1)
      cv2.imshow("title",img) 
      for y in range (0,height+1)
             if img[x,y,0]>45:
                img[x,y,0]=0
                img[x,y,2]=255
                cv2.waitKey(1)
cv2.destroyAllWindows()

This worked very well u can see the pixels changing every thing is fine but i want to turn every blue line into red by following the line i mean by checking each neighbor

edit retag flag offensive close merge delete

Comments

careful, you're already out of bounds, it must be:

range (0, width)

(numpy will silently "wrap over" so you don't even get an error !)

and if you want to use a 3x3 neihbourhood, it must be:

range (1, width-1)   and range (1, height-1)
berak gravatar imageberak ( 2020-05-22 06:57:15 -0600 )edit

There are 2 syntax errors. You left out semi_colon in both range. This doesn't work for OpenCV4. I need to see to completed code. As I do not have blueline.jpg. As you can post image.\

import cv2
import numpy as np

width = 0
height = 0

img=cv2.imread("bluelines.jpg")
for x in range (0, width+1):
    cv2.imshow("title",img)  

    for y in range (0, height+1):
        if img[x,y,0]>45:
            img[x,y,0]=0
            img[x,y,2]=255

cv2.waitKey(0)
cv2.destroyAllWindows()
supra56 gravatar imagesupra56 ( 2020-05-23 07:16:29 -0600 )edit