How can I interpolate binary 2D matrices?

조회 수: 9 (최근 30일)
Shyam Sunder Polaconda
Shyam Sunder Polaconda 2020년 7월 13일
편집: Matt J 2020년 7월 13일
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?

채택된 답변

Matt J
Matt J 2020년 7월 13일
편집: Matt J 2020년 7월 13일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by