title: Check the neighbour pixels of a connected component
body: <p>I'm using opencv to extract text from images like <a href="https://i.stack.imgur.com/1VY6x.jpg" rel="nofollow noreferrer">this</a>. Right now my goal is in trying to delete the most of the walls/windows/doors I can while leaving the text intact. This is what I came up with:</p>
  
  <pre><code>def process_image(path, out_path):
      image = Image.open(path)
  
      gray_image = cv2.cvtColor(np.asarray(image), cv2.COLOR_BGR2GRAY)
      ret,th = cv2.threshold(gray_image,127,255,cv2.THRESH_OTSU)
  
      kernel = np.ones((4,4),np.uint8)
      edges = cv2.dilate(th,kernel,iterations = 1)
      edges = cv2.erode(edges, kernel, iterations = 1)
  
  
      edges = cv2.bitwise_and(cv2.bitwise_not(th), edges)
      ret, labels = cv2.connectedComponents(edges, connectivity = 8)
  
      for label in range(ret):
          if  : #if connComp is adjacent to a wall
              edges[labels == label] = 0
  
  
  cv2.imwrite(out_path,edges)
  </code></pre>
  
  <p>I basically dilate the image so that all is left are the tickest walls, then I use this image as a filter to actually delete those walls. In the end I look for connected components and now I'd like to cycle on those and check wheter they "touch" the filter I just used (meaning a white pixel is next to a white pixel) and if they do I'd like to recolor the component black. This way I should be able to filter the image even more leaving the text untouched since it never touches a wall, problem is this is my first time using opencv and I'm not really sure how to implement the last bit of my idea. Any tip on how to do it?</p>