tomdoel / pulmonarytoolkit

Lung medical image analysis and visualisation software for Matlab.
GNU General Public License v3.0
84 stars 57 forks source link

Saving Output as different name? #41

Open vzhang0101 opened 4 years ago

vzhang0101 commented 4 years ago

Hi, I was trying to change the name of the output .csv to the accession number of the dicom image?

tomdoel commented 4 years ago

Hi. The CSV filename is set in a couple of places. You can modify the code to change this.

  1. The output folder where the csv is written is set in in External/mim/Framework/MimOutputFolder.m, in the function CreateNewOutputFolder(). It will try to use the PatientName or PatientId tag. You could modify the code there to use the accession number. That will change the output folder name but not change the name of the csv file itself.

  2. The main part of by the output filename is set by the Plugin that is actually saving the csv file.

For example, lobal analysis runs Plugins/Analysis/PTKSaveLobarAnalysisResults.m and if you look at the file you'll see it calls the method dataset.SaveTableAsCSV() The third argument is the initial part of the filename, in this case LobarResults. So you could modify this to use the accession number instead.

To get hold of the Accession Number inside a plugin, call you can check the the MetaHeader property of any PTKDicomImage. If you don't have an image variable available in the plugin, you can fetch an "image template" from the dataset (an image template is just an empty image which contains all the image metadata).

For example, something like the following code could be used inside a RunPlugin() method to fetch the accession number (if it exists), and you could use this to set the filename above. Please note that this will throw an error if the accession number does not exist:

image_template = dataset.GetTemplateImage(PTKContext.LungROI);
accession_number = image_template.MetaHeader.AccessionNumber;