Interpolating along the 2-D image slices

佐手、 提交于 2019-12-01 17:17:56

Here is an adapted example from the MATLAB documentation on how to visualize volumetric data (similar to yours) using isosurfaces:

%# load MRI dataset: 27 slices of 128x128 images
load mri
D = squeeze(D);       %# 27 2D-images

%# view slices as countours
contourslice(D,[],[],1:size(D,3))
colormap(map), view(3), axis tight

%# apply isosurface
figure
%#D = smooth3(D);
p = patch( isosurface(D,5) );
isonormals(D, p);
set(p, 'FaceColor',[1,.75,.65], 'EdgeColor','none')
daspect([1 1 .5]), view(3), axis tight, axis vis3d
camlight, lighting gouraud

%# add isocaps
patch(isocaps(D,5), 'FaceColor','interp', 'EdgeColor','none');
colormap(map)

MATLAB has a function interp3 that can be used for interpolation, assuming that the data is uniformly discretised.

Check out the documentation.

Hope this helps.

EDIT: The MATLAB function interp3 works as follows:

vi = interp3(x, y, z, v, xi, yi, zi);

I assume that your "stack" of slices defines the arrays x, y, z, v as 3D arrays, where x, y are the coordinates of the pixels in the plane, z is the "height" of each slice and v is the actual image slices, maybe as "intensity" values for the pixels.

If you want to interpolate new image slices at intermediate z values you could specify these levels in the zi array. The arrays xi, yi would again represent the coordinates of the pixels in the plane.

I created a function to interpolate along image slices. Below is the code:

    function res = interp_along_slices( vol, scale )
    % Interpolation along the image slices

    % Get the size of the volume
      [r c p] = size(vol);

    % Pre-allocate the array:
    % the third dimension is scale times the p
      vol_interp = zeros(r,c,scale*p);

    % interpolate along the image slices 
      for inr = 1:r;
          for jnr = 1:c;
              xi = vol(inr,jnr,:);
              vol_interp(inr,jnr,:) = interp(xi, scale); 
          end;
      end;

      res = vol_interp;

    end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!