Closed Kilong closed 4 months ago
Hi @Kilong ,
there is no ready-made implementation to read NifTI (nii files) in matRad at the moment. However, two things about that:
I think the best way would be to tap into the import functionality (which at the moment only implements nrrd). We would start with a file matRad_readNifTi, and in that file use the niftiread/niftiinfo functions of Matlab. Then matRad_readCube would need to be made aware of the file extension: https://github.com/e0404/matRad/blob/c3de378b7813611e619f7383f4498aedb618b0ce/IO/matRad_readCube.m#L31-L37 And then we could use the given import functionalities (e.g. matRad_importPatient) matRad_importPatient allows you to just provide a filename to the ct file and corresponding masks for structures. The structural data, in which format is it? DICOM RTStruct or what is the file format?
We could figure out a prototype for the NifTi reader, shouldn't be too difficult.
Thank you very much for your quick response and suggestions. I apologize for the confusion in my initial question; both my CT data and structural data are in the .nii.gz format. If you could provide a code such as matRad_readNifTi, I would be incredibly grateful. I will also try the methods you suggested to see if I can successfully import the data.
I have created a branch, feature/niftireader, to implement this (based on our current development branch dev_varRBErobOpt).
It adds a very basic / preliminary matRad_readNifTI function and also modifies matRad_importPatient
and the matRad_importWidget
to accept nifti as input (don't forget to run matRad_rc
first to add everything to the path).
So you can checkout above branch and try to run:
[ct,cst] = matRad_importPatient("pathToCt.nii.gz",{"Structure1.nii.gz","Structure2.nii.gz","..."})
Or run matRad_importWidget
and do it manually.
Both will create a ct
and a cst
file in your workspace. Note that there might be still multiple issues to adapt:
Let me know if this helps with your efforts and if weird stuff happens.
@amitantony would you be willing to spend some time refining the nifti-reader?
Thank you very much for your help and patient answers. However, after downloading the feature/niftireader branch and navigating to the corresponding folder, I found that matRad_rc is not running properly. Here is the detailed error message:
matRad_rc Error: File: MatRad_Config.m Line: 643 Column: 26 Cannot index a function with {} or . indexing. Error in matRad_rc (line 22) matRad_cfg = MatRad_Config.instance();
Strange, which version of Matlab are you using?
Yeah it seems like a Matlab version issue. Older Matlab versions do not support to directly index the result of a function call.
I pushed an update to the branch:
https://github.com/e0404/matRad/blob/cd2dfa73ef2b63475a157faff04203998b3db24b/MatRad_Config.m#L643-L644
This was the oneliner props = {metaclass(obj).PropertyList.Name};
before, which seems to not work in older versions.
I would in general recommend to update Matlab to a more recent version.
Yes, your guess is correct,.
I worked a bit more on this on the feature/niftireader branch.
matRad_importWidget
should now be able to successfully import NiftimatRad_exportWidget
should now be able to export NiftiSo far I tested to export one of the standard phantoms, check the orientation in MITK (was correct), then reimported itin matRad and checked the orientation again (was correct).
Let me know if it works with your files.
Thank you for your sincere help. I tried it, but I may have encountered a problem with my own data, which is that I found that the metadata information of my RT structural and CT data is different, and their transformation matrix may not be the same. I would like to ask if I should change the transformation matrix of the two files to be the same?
Hmm, remotely that's difficult to access. are your binary masks translated/shifted after import relative to the CT? Or are they rotated or mirrored? Or are they in the wrong scale?
Depending on what is the case, this could also be solved with some simple post-processing in Matlab after import.
Thank you for your help, I have successfully imported the nii into MatRad.
Perfect, glad we could help. I will finish the import/export functionality on the feature/niftireader branch and then close this Issue as soon as the the readers are merged onto the dev branch.
Hello, I am a beginner with MatRad and I'm encountering issues while attempting to perform dose verification using CT data in .nii.gz format along with RT structural data. Currently, I only have access to data in the .nii.gz format. Is there a way to directly load .nii.gz data into MatRad? After reviewing some examples, I noticed that when importing data, only the
load
function is used to import .mat files. Can I load the image data from .nii.gz files as the ct cube, and define the rest of the meta information myself? Also, can RT structural data be imported in a similar manner? If you have conducted similar experiments before and can provide some code or guidance, I would be extremely grateful.