title: Interpolating Between Two Planes in 3d space
body: <p>I'm developing a tool that lets you circle/enclose things on a 3d "volume." I want to save time by labelling "slices" 1 and 3, and "filling in" slice 2 from that information.</p>
  
  <p>Two easy solutions are to: </p>
  
  <pre><code>1. slice2 = slice1 AND slice3 (gets the overlap between the two)
  2. slice2 = slice2 OR  slice3 (true for any pixel true in either image)
  </code></pre>
  
  <p>These are <i> ok </i> and fast, but I would prefer to do something more intelligent by making the shape some sort of average/ interpolation between the two. 
  You can imagine it as trying to find the cliff face that connects a plane at see level and some plateau in the air.</p>
  
  <p>Example: Fill in slices 2-4 from this 3d matrix. (Created using <code>montage</code>)
  <img src="https://i.stack.imgur.com/oCl1w.png" alt="slices one through five"></p>
  
  <p>Feel free to come up with totally new ideas. I'm going to put my thoughts so far below.</p>
  
  <p>Some stuff I've thought about that might help you, the answerer, but that I haven't been able to use successfully. <br>
  - You can do a bwperim on each image. <br>
  - You can try to "average" the images (or a weighted average).<br></p>
  
  <p>The best I've got so far:</p>
  
  <p>Add the images.
  Gives you overlap and two perimeters: <br>
  -an inner perimeter (inside of which will definitely be 1) <br>
  -and an outer perimeter (inside of which is questionable). <br>
  You can also mask the area that is >0 AND &lt;2, which is a mask of this questionable area. <br>
  Run a <code>bwdist</code> on the two-perimeter image and mask that:</p>
  
  <p><img src="https://i.stack.imgur.com/ngOyK.png" alt="masked bwdist image"></p>
  
  <p>Not sure how to go from here, though. A line that took the "maximum" contour along that area would work, but I'm not sure how to do that robustly.</p>
  
  <p>Any ideas on fixing my idea or any other ideas are welcome!</p>
  
  <p>Thanks.</p>