title: How to find table like structure in image
body: <p>I have different type of invoice files, I want to find table in each invoice file. In this table position is not constant. So I go for image processing. First I tried to convert my invoice into image, then I found contour based on table borders, Finally I can catch table position. 
  For the task I used below code.</p>
  
  <pre><code>with Image(page) as page_image:
      page_image.alpha_channel = False #eliminates transperancy
      img_buffer=np.asarray(bytearray(page_image.make_blob()), dtype=np.uint8)
      img = cv2.imdecode(img_buffer, cv2.IMREAD_UNCHANGED)
  
      ret, thresh = cv2.threshold(img, 127, 255, 0)
      im2, contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
      margin=[]
      for contour in contours:
          # get rectangle bounding contour
          [x, y, w, h] = cv2.boundingRect(contour)
          # Don't plot small false positives that aren't text
          if (w &gt;thresh1 and h&gt; thresh2):
                  margin.append([x, y, x + w, y + h])
      #data cleanup on margin to extract required position values.
  </code></pre>
  
  <p>In this code <code>thresh1</code>, <code>thresh2</code> i'll update based on the file.</p>
  
  <p>So using this code I can successfully read positions of tables in images, using this position i'll work on my invoice pdf file. For example </p>
  
  <p>Sample 1:</p>
  
  <p><a href="https://i.stack.imgur.com/NJXjD.png" rel="noreferrer"><img src="https://i.stack.imgur.com/NJXjD.png" alt="enter image description here"></a></p>
  
  <p>Sample 2:</p>
  
  <p><a href="https://i.stack.imgur.com/Ntbce.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Ntbce.png" alt="enter image description here"></a></p>
  
  <p>Sample 3:
  <a href="https://i.stack.imgur.com/SqpiK.png" rel="noreferrer"><img src="https://i.stack.imgur.com/SqpiK.png" alt="enter image description here"></a></p>
  
  <p>Output:</p>
  
  <p>Sample 1:</p>
  
  <p><a href="https://i.stack.imgur.com/MIaGH.png" rel="noreferrer"><img src="https://i.stack.imgur.com/MIaGH.png" alt="enter image description here"></a></p>
  
  <p>Sample 2:</p>
  
  <p><a href="https://i.stack.imgur.com/CXv8x.png" rel="noreferrer"><img src="https://i.stack.imgur.com/CXv8x.png" alt="enter image description here"></a></p>
  
  <p>Sample 3:</p>
  
  <p><a href="https://i.stack.imgur.com/d76gQ.png" rel="noreferrer"><img src="https://i.stack.imgur.com/d76gQ.png" alt="enter image description here"></a></p>
  
  <p>But, now I have a new format which doesn't have any borders but it's a table. How to solve this? Because my entire operation depends only on borders of the tables. But now I don't have a table borders. How can I achieve this? I don't have any idea to move out from this problem. My question is, Is there any way to find position based on table structure?. </p>
  
  <p>For example My problem input looks like below:</p>
  
  <p><a href="https://i.stack.imgur.com/Fw3Qa.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/Fw3Qa.jpg" alt="enter image description here"></a></p>
  
  <p>I would like to find its position like below:
  <a href="https://i.stack.imgur.com/5or8D.png" rel="noreferrer"><img src="https://i.stack.imgur.com/5or8D.png" alt="enter image description here"></a></p>
  
  <p>How can I solve this?
  It is really appreciable to give me an idea to solve the problem.</p>
  
  <p>Thanks in advance.</p>