WCHN / CTseg

Brain CT image segmentation, normalisation, skull-stripping and total brain/intracranial volume computation.
GNU General Public License v3.0
55 stars 17 forks source link

Some question about MATLAB Runtime R2020a for linux #16

Closed YingJGuo closed 2 years ago

YingJGuo commented 2 years ago

1、There were some errors while I was processing my .nii image (536512512) Failed 'CT Segmentation' Error using spm_gmm_lib > loop (line 398) At least one of Prop, LogProp or Dir must be provided

Error using spc_cli (line 141) Job failed. Error in spm_cli (line 141) Error in spm_standalone (line 157) image

2、The option "tc" can not set to False, but I just need the Skull-stripped image.

3、It took a lot of time (nearly 2 hours) to process an image (536512512).

JohnAshburner commented 2 years ago

I hadn't realised that there was a compiled version of SPM available, which included the MB toolbox. Having looked at the error message, it seems that it uses an old version of MB, because the spm_gmm_lib.m function, where the error occurs, was removed many months ago.

JohnAshburner commented 2 years ago

Regarding timings, I assume your image is 536 x 512 x 512 voxels, which is about eight times as big as most scans we deal with. This makes the computation time about eight times as long as for a typical scan. Down-sampling the image by a factor of two in all directions should speed things up.

YingJGuo commented 2 years ago

May I ask if there is a new version of SPM12+CTseg Compiler for Matlab runtime R2020a Linux? or any new solutions to run CTseg on linux ?

By the way, The way I tried was this: image Unfortunately failed.

YingJGuo commented 2 years ago

Regarding timings, I assume your image is 536 x 512 x 512 voxels, which is about eight times as big as most scans we deal with. This makes the computation time about eight times as long as for a typical scan. Down-sampling the image by a factor of two in all directions should speed things up.

thanks, I will try!

gllmflndn commented 2 years ago

Could you try again with this standalone version of SPM12 (r8247 (dev) + CTseg) requiring MATLAB Runtime R2021b?

YingJGuo commented 2 years ago

Could you try again with this standalone version of SPM12 (r8247 (dev) + CTseg) requiring MATLAB Runtime R2021b?

Thanks, I will try it later.

YingJGuo commented 2 years ago

In order to reduce the image size for processing requirements, I tried to cut 2 layers from Z axis. And it can works on my MATLAB on Windows now(I will also try the Linux later). However the skull-stripped image looks very strange. Is there something wrong I made ? image

brudfors commented 2 years ago

Hi @GuoCHance,

The changes you make to the image size need to be encoded also in the affine matrix, did you perhaps forget this step? Looks like this might be the case.

YingJGuo commented 2 years ago

I recently tried Down-sampling the image and it's now available to use CTSeg on my image. But it still doesn't work well. What does "need to be encoded also in the affine matrix" mean? I'm not sure about it. image

JohnAshburner commented 2 years ago

The matrix encodes a mapping from voxel indices to some real world space (see NIfTI-1 Data Format — Neuroimaging Informatics Technology Initiative (nih.gov)). Ideally, you should be able to use SPM's check-reg with the downsampled image and the original, and see them both in alignment.

This might need a bit more thought in the coding though. As an alternative, you could just put the voxel sizes in the matrix so that it encodes Nii.mat = [diag(vox) [0 0 0]'; 0 0 0 1] and then reorient the downsampled image manually via SPM's display button, so that the AC has a mm coordinate close to [0,0,0] and the orientation is approximately axial. If these are satisfied, then any registration done in SPM has a better chance of success.

YingJGuo commented 2 years ago

I found that a lot of blood vessels had been removed, even including GroundTruth. Is there any way to solve this problem? image

By the way, I found that the Skull-stripped image had the same pixels as the original image(Brain parts). I changed my code and I can see original image and dowmsampling image both in alignment in ITK-SNAP.So maybe I have already solved the "affine matrix" problem?

dcc2b56f521c70848f3f651b1a0bd14
brudfors commented 2 years ago

Hi @GuoCHance

Blood vessels might be removed because they are being absorbed by a non-brain atlas class (probably the soft tissue one). You could probably fix it by 'hacking' the part of CTseg that does the skullstripping:

https://github.com/WCHN/CTseg/blob/08161dc2d1dbfab8c4963808ca1626b4e6d77ccf/spm_CTseg.m#L288

Perhaps try some hole clossing or dilation on the brain mask.

Additionally, I added the following utility function to CTseg for modifying the voxel size of CT scans, ensuring that the affine matrix is correct:

https://github.com/WCHN/CTseg/blob/08161dc2d1dbfab8c4963808ca1626b4e6d77ccf/spm_CTseg_util.m#L14