title: Efficient Matlab way of reducing 2D segments?
body: <p>I need to write a function to simplify a set of segments. In particular:</p>
  
  <p>Given the set of 2D segments (x and y coordinates)</p>
  
  <ul>
  <li>Keep only one replica in case of overlapping (or almost overlapping) segments</li>
  <li>For each kept part keep count of how many overlaps were present on it.</li>
  </ul>
  
  <p>So the input would be a big set of segments (with many overlaps)
  And the output would be non overlapping segments with counts for each one of them.</p>
  
  <p>An example input is shown in this matlab plot
  <a href="https://i.stack.imgur.com/Bycsf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Bycsf.png" alt="example"></a></p>
  
  <p>As you can see some lines look thicker cause there are multiple overlaps.
  As a result I would need just the skeleton with no overlaps, but I would need the information of the overlaps as a number for each output segment.</p>
  
  <p>I am not an expert working with segments and geometrical problems.
  What would be the most efficient way of solving such problem? I am using Matlab, but a code example in any high level language would help. Thanks!</p>
  
  <p>EDIT
  As requested here is also a sample dataset, you can get it from this google drive link
  <a href="https://drive.google.com/open?id=1r2hkG7gI0qhzfP-Mmn8HzIil1o47Z2nA" rel="nofollow noreferrer">https://drive.google.com/open?id=1r2hkG7gI0qhzfP-Mmn8HzIil1o47Z2nA</a></p>
  
  <p>The input is a csv with 276 cable segments
  The output is a csv with 58 cable segments (the reduced segments) + an extra column containing the number of overlapping cables for each segment kept.</p>
  
  <p>The input could contain many more segments. The idea is that the reduction should eliminate cables that are parallel and overlapping with each other, with a certain tolerance.
  For example if 2 cables are parallel but far away they should be kept both.</p>
  
  <p>I don't care about the tolerances it's fine if the output is different, I just need an idea on how to solve this problem efficiently cause the code should run fast even with many many segments as input.</p>