Okay I fixed it, turns out I was adding breakpoints to files in the incorrect folder!
However I’ve run into two new problems:
My matlab module takes two directory paths as inputs. At the moment I am defining them as ‘strings’ within the .xml file. However when I’m reading them in the matlab function with inputParams.stringName I only receive an escape character instead of the full string, which I defined as something like “C:/Users/slicer-module-test/”
Even though my matlab module does not take an image as input, it outputs 2 images. These images are generated by some matlab function which are processing .mha files saved in a separate directory.
However, I can’t seem to correctly read the output volumes in my matlab module function.
I’m using cli_imageread(inputParams.outputvol1)
to read the file, but this returns an error because inputParams.outputvol1 refers to a nonexistent the path to a vtkMRMLScalarVolumeNode.nrrd file. Is this because it is an empty scalar volume node that I create in Slicer before running module?
My full code is:
startup %this adds relevant directories to my path
num_files = inputParams.num_files; %input integer
data_dir = inputParams.data_dir; %input directory string
config_fname = inputParams.config_fname; %input directory string
combinedVol = cli_imageread(inputParams.combinedVol); %output volume1 (I get an error here)
US_dist = cli_imageread(inputParams.US_dist); %output volume2
[combinedVol.pixelData, US_dist.pixelData] = someImageProcessing(num_files, data_dir, config_fname);
I can’t quite figure out what I am doing wrong here, but I guess it has something to do with the fact that both inputParams.combinedVol and inputParams.US_dist do not contain any data… yet
What escape character do you get? Can you pass a simple string that does not contain spaces, slashes, and quotes?
You need to create image files by the names that Slicer provides. If you must create .mha file then change the module descriptor xml file so that Slicer generates a file with .mha extension.
One issue for sure is that you use inputParams.combinedVol and inputParams.US_dist both as input and output volumes. If they are output volumes then don’t call cli_imageread on them because they don’t exist (you have to create them).
I don’t know how you create .mha image from scratch (I’m sure there are .mha writer matlab scripts). I would recommend using the .nrrd reader and writer scripts that are bundled with the MatlabBridge. They are tested to work well with Slicer. Here are examples of how to create .nrrd image file from scratch:
Note that AnatomicalOrientation = RAI in a metaimage file means that coordinates are defined in LPS coordinate coordinate system. Slicer uses LPS coordinate system for files but otherwise uses RAS coordinates.
Indeed, you need to pay attention to Matlab’s unconventional 1-based array indexing. The nrrd reader/writer class bundled with MatlabBridge extension takes care of this as shown here.