title: How can I fill the black background of the image with mirroring?
body: <p><img src="https://i.stack.imgur.com/zUruv.png" alt="enter image description here" /></p>
  <p>I have above image. It is warped using homography.</p>
  <p>i want to fill the black background of the image with mirroring like this.
  <img src="https://i.stack.imgur.com/wCTBG.png" alt="enter image description here" /></p>
  <p>If I use cv2.warpPerspective's BorderMode for homography conversion,
  I get second image.</p>
  <p>But I need a way to fill the black background without using cv2.warpPerspective's BorderMode.</p>
  <p>can you help me?</p>
  <p>i tried below code</p>
  <pre><code>def image_mirroring(canvas) :
  
      mirrored_canvas = canvas.copy()
  
      left = 0
      right = 0
      top = 0
      bottom = 0
  
      width_start = 0
      width_end = 0
      height_start = 0
      height_end = 0
  
      for row in range(canvas.shape[0]) :
          for column in range(canvas.shape[1]) :
              if (canvas[row][column] != np.array([0, 0, 0])).any() and left == 0 :
                  width_start = column
                  left = 1
              if (canvas[row][column] == np.array([0, 0, 0])).all() and left == 1 :
                  width_end = column
                  left = 2
  
          left = 0
          width = width_end - width_start + 1
  
          if width &lt; 2 :
              continue
  
          for column in range(canvas.shape[1]) :
              if (canvas[row][column] != np.array([0, 0, 0])).any() and left == 0 :
                  for i in range(width) :
                      if column-i &gt;= 0 :
                          mirrored_canvas[row][column-i] = canvas[row][column+(i)]
                  left = 1
              elif (canvas[row][column] != np.array([0, 0, 0])).any() and right == 0 :
                  for i in range(width) :
                      if column+width+i &lt; canvas.shape[1] :
                          mirrored_canvas[row][column+width+i] = canvas[row][column+width-i]
                  right = 1
  
          left = 0
          right = 0
          
          width = 0
          width_start = 0
          width_end = 0
  
      for column in range(canvas.shape[1]) :
          for row in range(canvas.shape[0]) :
              if (canvas[row][column] != np.array([0, 0, 0])).any() and top == 0 :
                  height_start = row
                  top = 1
              if (canvas[row][column] == np.array([0, 0, 0])).all() and top == 1 :
                  height_end = row
                  top = 2
  
          top = 0
          height = height_end - height_start + 1
  
          if height &lt; 2 :
              continue
  
          for row in range(canvas.shape[0]) :
              if (canvas[row][column] != np.array([0, 0, 0])).any() and top == 0 :
                  for i in range(height) :
                      if row-i &gt;= 0 :
                          mirrored_canvas[row-i][column] = canvas[row+(i)][column]
                  top = 1
              elif (canvas[row][column] != np.array([0, 0, 0])).any() and bottom == 0 :
                  for i in range(height) :
                      if row+height+i &lt; canvas.shape[0] :
                          mirrored_canvas[row+height+i][column] = canvas[row+height-(i)][column]
                  bottom = 1
  
          top = 0
          right = 0
  
          height = 0
          height_start = 0
          height_end = 0
  
      return mirrored_canvas
  
  </code></pre>