Problem with using SCT-GUI from Matlab

Dear all,

We have been using SCT for a while now, and due to our structure of folders(and because I feel more comfortable around it), we used to run the SCT from MATLAB.

We have had no problem whatsoever with this since now. We wanted to call sct_label_utils -i T1.nii -create-viewer 3 -o c3label.nii.gz but this line uses GUI and, when it’s called, gives us the following error

Spinal Cord Toolbox (4.3)

/home/extop/sct_4.3/spinalcordtoolbox/gui/widgets.py:12: MatplotlibDeprecationWarning: 
The matplotlib.backends.backend_qt4agg backend was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
  from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl, xcb.

I didn’t have the last version and i expected(hoped) it to be an “old_Version” problem but after successfully downloading and installing the latest version, the problem persists.

After playing a little with the code, we managed to overcome the first troubles. In the widgets.py file, lines 12 and 13, we changed

from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar

to

from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar

because my limited knowledge does not understand the point of importing it from qt4agg or directly from qt5agg.

Nevertheless, the output from the order is now

Spinal Cord Toolbox (4.3)

qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl, xcb.

After not succeeding, I deleted all the changes done in the SCT scripts and brought them back to their original forms.

Probably this is a MATLAB problem. And I definitely need a bash/shell class

peace,

Aran

@Aran, Thank you for reporting on your experience. Indeed, you are not the only one wrapping SCT (and Linux binaries in general) within Matlab, due to convenience and habits with Matlab (I also used to do that when I was a grad student 15y ago :stuck_out_tongue:). However, this is highly inefficient, because it creates a large overhead on the available CPU and RAM, and in some cases incompatibilities with the display (such as the one you report here with pyQt). For these reasons, it is highly discouraged to wrapped Python/Binaries pipelines in Matlab.

Alternatives include:

  • shell scripts (see the many examples we provide)
  • Python scripts (where you could directly call the APIs) --> requires knowledge in Python
  • Dedicated pipeline technologies such as Nextflow.

Personally, I find that the easiest and most intuitive approach is to use Shell scripts. If you would like to create pipelines to process large datasets across subjects, SCT features the script sct_run_batch, which can loop across subjects, write QC reports, log files, etc. This is an extremely convenient approach. Example file and procedure is shown in the spine-generic project., and if you have further questions I’d be happy to help you with this.

Also note that if you have custom Matlab scripts, you can always do the other way around and call them from your shell script, with:

matlab -nodesktop < script.m

More info here.

Dear,

I was expecting an answer like this, although not the one that I wanted haha

I guess it’s about time to leave Matlab behind.
Will be in touch!

thanks for everything!

1 Like