在Matlab中可视化3D体积图像数据,例如MRI图像

转载自Binlin Wu (2020). Visualize 3D volumetric image data such as MRI images in Matlab (https://www.mathworks.com/matlabcentral/fileexchange/32065-visualize-3d-volumetric-image-data-such-as-mri-images-in-matlab), MATLAB Central File Exchange. Retrieved November 14, 2020.


1.在mriplot.m中,使用MATLAB自带的医学体数据 mri.mat。如果要显示其他数据,可以将数据保存到矩阵D1中,或修改.m文件。
2.单击三个MRI图像中的任何一个,然后按“ ENTER”以在新的[x,y,z]位置更改切片。
在这里插入图片描述
3.按“ ESC”,然后按“ ENTER”退出。


具体代码如下:

%% mriplot.m

load mri.mat;
D1=double(squeeze(D));
DIM = size(D1);
[X,Y,Z]=meshgrid(1:DIM(2),1:DIM(1),1:DIM(3));
h1=subplot(2,2,1);imagesc(D1(:,:,round(DIM(3)/2)),[min(D1(:)) max(D1(:))]);colormap(gray);title('axial');colorbar;
xlabel('x');ylabel('y')
h2=subplot(2,2,2);imagesc(squeeze(D1(:,round(DIM(2)/2),:)),[min(D(:)) max(D(:))]);colormap(gray);title('sagittal');colorbar;
xlabel('z');ylabel('y')
h3=subplot(2,2,3);imagesc(squeeze(D1(round(DIM(1)/2),:,:)),[min(D(:)) max(D(:))]);colormap(gray);title('coronal');colorbar;
xlabel('z');ylabel('x')
subplot(2,2,4);slice(X,Y,Z,D1,64,64,14);colormap(gray);shading flat;title('3D Slices')
xlabel('x');ylabel('y');zlabel('z');


x=round(DIM(2)/2);y=round(DIM(1)/2);z=round(DIM(3)/2);
button = 0;

while(1)

    try
        [A,B,button]=ginput
    catch
        return
    end
    if length(A)==0
        A=14;B=64;button=0;
    end

    A=A(end);
    B=B(end);
    button=button(end);

    A=ceil(A-0.5);
    B=ceil(B-0.5);

    if button==27
        break;
    end
    if gca==h1
        x=A;
        y=B;
        if x<=0 || x>DIM(2) || y<=0 || y>DIM(1)
            continue
        end
        axes(h2);imagesc(squeeze(D1(:,x,:)),[min(D(:)) max(D1(:))]);colormap(gray);title('sagittal');colorbar;
        xlabel('z');ylabel('y')
        axes(h3);imagesc(squeeze(D1(y,:,:)),[min(D(:)) max(D1(:))]);colormap(gray);title('coronal');colorbar;
        xlabel('z');ylabel('x')
        subplot(2,2,4);slice(X,Y,Z,D1,x,y,z);colormap(gray);shading flat;title('3D Slices')
        xlabel('x');ylabel('y');zlabel('z');
    elseif gca==h2
        z=A;
        y=B;
        if z<=0 || z>DIM(3) || y<=0 || y>DIM(1)
            continue
        end        
        axes(h1);imagesc(D1(:,:,z),[min(D1(:)) max(D1(:))]);colormap(gray);title('axial');colorbar;
        xlabel('x');ylabel('y')
        axes(h3);imagesc(squeeze(D1(y,:,:)),[min(D1(:)) max(D1(:))]);colormap(gray);title('coronal');colorbar;
        xlabel('z');ylabel('x')
        subplot(2,2,4);slice(X,Y,Z,D1,x,y,z);colormap(gray);shading flat;title('3D Slices')
        xlabel('x');ylabel('y');zlabel('z');        
    elseif gca==h3
        z=A;
        x=B;
        if x<=0 || x>DIM(2) || z<=0 || z>DIM(3)
            continue
        end        
        axes(h1);imagesc(D1(:,:,z),[min(D1(:)) max(D1(:))]);colormap(gray);title('axial');colorbar;
        xlabel('x');ylabel('y')
        axes(h2);imagesc(squeeze(D1(:,x,:)),[min(D1(:)) max(D1(:))]);colormap(gray);title('sagittal');colorbar;
        xlabel('z');ylabel('y')
        subplot(2,2,4);slice(X,Y,Z,D1,x,y,z);colormap(gray);shading flat;title('3D Slices')
        xlabel('x');ylabel('y');zlabel('z');        
    end
end

转载自
Binlin Wu (2020). Visualize 3D volumetric image data such as MRI images in Matlab (https://www.mathworks.com/matlabcentral/fileexchange/32065-visualize-3d-volumetric-image-data-such-as-mri-images-in-matlab), MATLAB Central File Exchange. Retrieved November 14, 2020.

  • 1
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值