leoliuf / MRiLab

A Numerical Magnetic Resonance Imaging (MRI) Simulation Platform
https://leoliuf.github.io/MRiLab/
BSD 2-Clause "Simplified" License
204 stars 63 forks source link

Running MriLab from MATLAB command window. #30

Closed harshank001 closed 5 years ago

harshank001 commented 5 years ago

I have multiple 3D digital phantoms and I want to simulate MR image volumes using those. However, in order to change the phantom to be used I have to load the new phantom using the GUI of MriLab and this process takes a lot of time given that I want to simulate using a lot of digital phantoms. Is it possible to run MriLab directly from MATLAB command window with prescribed digital phantom location, the pulse sequence to be used and the default attributes associated with the pulse sequence. Thanks.

leoliuf commented 5 years ago

I am also working on this. The problem here is the engine needs to interact with the GUI in order to perform some extended event (e.g. display execution time in the frontend). Of course, you can safely turn off these features to prevent GUI interaction during the simulation. The simulated signal needs to be reconstructed and displayed in the preview window which is required by default. You might want to find and modify relevant code to turn off this too.

A quick solution is to use the batch simulation mode (user guide 4.1). However, I noticed that the newer version of MATLAB (after 2015a) changed the graphical system so MATLAB took so much time and space to save the figure handle which isn't necessary. As of now, I would recommend you using the older version of MATLAB and using the batch simulation mode. This won't require you to do extra work in order to simulate a lot of scans.

Long story short, you can do a command line (see how I use the DoScanGPU in the main code) if you can turn off the GUI interaction during and after the signal simulation. However, there might be glitches.

harshank001 commented 5 years ago

Thanks Dr. Liu. I am currently using MATLAB 2015a for running MriLab. I have previously tried the batch simulation mode, however the time for simulation does not scale linearly with number of slices. For example, for simulating 1 slice (256*256) it takes about 3-4 minutes on my laptop's GPU (GTX 1050); for 2 slices 10-11 minutes; and around 2 hours for 6 slices. Due to this I have had to break each phantom into small volumes and simulate one-by-one. Do you have any idea why the time required does not scale linearly? I was actually expecting that once the phantom has been loaded and all other attributes prescribed, the time required per slice would be about the same.

leoliuf commented 5 years ago

The time increase is not linear. For example, comparing to 1 slice, simulating 2 slices computes both 2x spins and 2x TRs. You will likely expect around x^2 computation time.