How can I interpolation values within a 3D matrix by ignoring zeros?

I have a 3-D matrix, many values of which are zero but some of which have non-zero values in them.
I'd like to fill in the zeros by 'interpolating' or filling in based on the non-zero values. I don't want the zeros to go into the calculation of the interpolation, only the non-zero values, and these values should replace the non-zero values.

답변 (2개)

Kelly Kearney
Kelly Kearney 2013년 11월 7일
편집: Kelly Kearney 2013년 11월 7일
I use this function a lot: inpaint_nans3. If x is your 3D matrix:
x(x == 0) = NaN;
newx = inpaint_nans3(x);
If you have the Image Processing Toolbox, use roifill(). Create your binaryImage like this:
binaryImage = image3D == 0;
Then fill
filledImage = roifill(image3d, binaryImage);

댓글 수: 2

This solution produces an error. Maybe the function does not handle 3D matrices?
>> filledImage = roifill(image3D, binaryImage); Error using roifill Expected input number 1, I, to be two-dimensional.
Error in roifill>ParseInputs (line 242) validateattributes(I, {'uint8', 'uint16', 'int16', 'single', 'double'}, ...
Error in roifill (line 78) [xdata,ydata,I,xi,yi,mask,newFig,placement_cancelled] = ParseInputs(varargin{:});
The documentation didn't say that it was limited to 3D images, but maybe it is. In that case there's no built in method and you'll have to write your own.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Interpolation에 대해 자세히 알아보기

태그

질문:

2013년 11월 7일

편집:

2013년 11월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by