项目作者: GNtem2

项目描述 :
collection of matlab codes in Imaging Lab
高级语言: MATLAB
项目地址: git://github.com/GNtem2/matlab_journey.git
创建时间: 2020-01-12T23:54:49Z
项目社区:https://github.com/GNtem2/matlab_journey

开源协议:

下载


matlab_journey

This is a simple introduction to matlab for image analysis. The codes used here require installation of image processing toolbox, deep learning toolbox.

Volume: This part deals with calculation of volume of a binary mask containing ones and zeroes. The file Niti_vol.m also contains codes in R and fsl for performing the same task are also provided.

  1. %matlab
  2. ImN='test.nii'; %assign ImN
  3. info=niftiinfo(ImN);%check dimensions of ImN
  4. Roi=niftiread(ImN); %Roi is handle for image
  5. %nnz=number of nonzero elements
  6. Volume=nnz(Roi)*info.PixelDimensions(1)*info.PixelDimensions(2)*info.PixelDimensions(3)/1000
  7. %equivalent codes in fsl
  8. %fslstats 1000M_ica.nii -V
  9. %describe shape of volume
  10. Roi=Roi>0.5; %ensure binary mask
  11. s = regionprops3(Roi,"Centroid","PrincipalAxisLength","Orientation","Extent","Solidity");
  12. centers = s.Centroid; %note s is the output of regionprops3. Centroid is a subset of s.
  13. angles=s.Orientation;
  14. axislength=s.PrincipalAxisLength;
  15. ratio=s.Extent;
  16. solidity=s.Solidity;

TSNE: This part deals with calculation of centre of gravity of a binary image. The file tsne_image.m illustrates the use of random number to create 3D array and 3D plot with scatter3. T-stochastic neighbourhood embedding (tsne) is used to visualise the low dimensional representation of the imaging data. the outputs of tsne are illustrated with 4 subplots, each created from different distance measurements.

  1. %generate array of data
  2. a=randperm(10,10);
  3. a1= a+ s.Centroid(1);
  4. b=randperm(13,10); %10 number up to 13
  5. b1= b+ s.Centroid(1,2); %column 2 row 1
  6. c=randperm(16,10); %10 number up to 16
  7. c1= c+ s.Centroid(1,3); %column 3 row 1
  8. %create string array
  9. Vol=["small";"medium";"large";"large";"medium";"medium";"large";"large";"small";"medium"]
  10. Vol=categorical(Vol); %convert to categorical
  11. %combine data into array
  12. ArrayCentroid=[a1;b1;c1]'; %transpose to create 3 columns
  13. %add Volume data to array.
  14. %note that Vol is categorical vector and needs to be added as such
  15. ArrayCentroidTable=table(ArrayCentroid,categorical(Vol));
  16. % ArrayCentroid Var2
  17. % __________________________ ______
  18. %
  19. % 72.005 68.601 57.502 small
  20. % 71.005 70.601 69.502 medium
  21. % 66.005 75.601 63.502 large
  22. % 67.005 73.601 68.502 large
  23. % 64.005 72.601 70.502 medium
  24. % 65.005 65.601 64.502 medium
  25. % 63.005 69.601 66.502 large
  26. % 70.005 64.601 62.502 large
  27. % 68.005 71.601 58.502 small
  28. % 69.005 63.601 67.502 medium
  29. Y = tsne(ArrayCentroidTable.XYZdim,'Algorithm','exact','Distance','euclidean');
  30. subplot(2,2,1)
  31. gscatter(Y(:,1),Y(:,2),ArrayCentroidTable.Volume) %scater plot
  32. title('Euclidean')