Spinalcordtoolbox: Image is cropped on QC report for sct_label_utils

Created on 8 Dec 2020  ·  3Comments  ·  Source: spinalcordtoolbox/spinalcordtoolbox

When generating QC report for function sct_label_utils, the image is cropped (while it should not):

Screen Shot 2020-12-08 at 5 48 43 PM

here is the original image, indicating that it has indeed been cropped by the QC report:
Screen Shot 2020-12-08 at 5 48 30 PM

To reproduce:
data (internal): duke/temp/sebeda/test1_30_sub/files_test_qc
syntax:
~
sct_qc -i sub-1002358_T1w_RPI_r_gradcorr.nii.gz -s sub-1002358_T1w_RPI_r_gradcorr_labels-manual.nii.gz -p sct_label_utils -qc qc
~

SCT version: git-jca/3044-ants-sampling-770e37f8b25f3283ede65eb171501f55bf5416e5

bug HIGH sct_qc

All 3 comments

I have access to duke now. I'm going to take a look at this shortly. :slightly_smiling_face:

I was able to reproduce the error, and I have a rough idea where the problem is.

The problem is present inside reports/slice.py : Sagittal.single(). (This is the function that gets called to produce the image matrix.) Specifically, this line:

https://github.com/neuropoly/spinalcordtoolbox/blob/997c82ebaa2aa3c0502b9fc3d8f753d0efbc08a7/spinalcordtoolbox/reports/slice.py#L284

When I run the command in this issue and set a breakpoint here, index = {list: 208} [104, 104, 104, 104 ...]. In other words, index is used to take 208 rows of data, each from slice 104. But, the image data matrix is actually of size 256x256, so index is missing 48 rows.

To quickly test this theory, if I manually change index to be index = {list: 256} [104, 104, 104, 104 ...], then continue with the rest of the script, the expected image is produced:

Screenshot from 2020-12-20 13-09-28

My next step is to inspect the get_center_spit function to figure out why the 48 rows are missing in the first place. :sweat_smile:

Ah! The data files ('sub-1002358_T1w_RPI_r_gradcorr.nii.gz', 'sub-1002358_T1w_RPI_r_gradcorr_labels-manual.nii.gz') are of size [208, 256, 256].

These images get re-oriented from RPI to SAL (i.e. [208, 256, 256] -> [256, 256, 208]) here:

https://github.com/neuropoly/spinalcordtoolbox/blob/997c82ebaa2aa3c0502b9fc3d8f753d0efbc08a7/spinalcordtoolbox/reports/slice.py#L48

Then, inside get_center_spit:

https://github.com/neuropoly/spinalcordtoolbox/blob/997c82ebaa2aa3c0502b9fc3d8f753d0efbc08a7/spinalcordtoolbox/reports/slice.py#L386-L388

image.data.shape[2] refers to the RL dimension (208). But, the function is supposed to be returning index = [int] * n_SI:

https://github.com/neuropoly/spinalcordtoolbox/blob/997c82ebaa2aa3c0502b9fc3d8f753d0efbc08a7/spinalcordtoolbox/reports/slice.py#L370-L380

Since we assume SAL orientation, to index the SI dimension properly, I think the fix is as simple as this:

```diff
# If mask only has one label (e.g., in sct_detect_pmj), return the repmat of the R-L index (assuming SAL orient)
elif np.argwhere(image.data).shape[0] == 1:
- return [np.argwhere(image.data)[0][2]] * image.data.shape[2]
+ return [np.argwhere(image.data)[0][2]] * image.data.shape[0]

Was this page helpful?
0 / 5 - 0 ratings