How can I interpolate binary 2D matrices?

5 views (last 30 days)
I am not sure if this is entirely possible, but I am trying to do this:
For a 3d matrix with some number of layers in the z dimension,
The user should input the location of a region (marked by value of 1) in the first layer, and last layer, and the goal is to have matlab fill in the intermediate regions.
for example
layer1 = [1 1 1 1 1; ...
1 1 1 1 1; ...
1 1 1 1 1; ...
1 1 1 1 1; ...
1 1 1 1 1]
layer3 = [0 0 0 0 0; ...
0 0 0 0 0; ...
0 0 1 0 0; ...
0 0 0 0 0; ...
0 0 0 0 0]
the layer in between the 2 should be filled by matlab and have the following output
layer2 = [0 0 0 0 0; ...
0 1 1 1 0; ...
0 1 1 1 0; ...
0 1 1 1 0; ...
0 0 0 0 0; ...]
This would be a very very simple case. Ideally I am trying to make this work for a 3d matrix with dimensions probably ranging from 500*500*500 to 2000*2000*2000
Is there any function in matlab that would help in this process?

Accepted Answer

Matt J
Matt J on 13 Jul 2020
Edited: Matt J on 13 Jul 2020
If the final, filled in region is convex, it can be obtained as follows
layers=false(5,5,3)
layers(:,:,1)=1;
layers(3,3,3)=1;
T=regionprops3(double(layers),'ConvexImage','SubarrayIdx')
layers(T.SubarrayIdx{:})=T.ConvexImage{1}
layers(:,:,1) =
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
layers(:,:,2) =
0 0 0 0 0
0 1 1 1 0
0 1 1 1 0
0 1 1 1 0
0 0 0 0 0
layers(:,:,3) =
0 0 0 0 0
0 0 0 0 0
0 0 1 0 0
0 0 0 0 0
0 0 0 0 0

More Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!