kschan0214 / sepia

Matlab GUI pipeline application for quantitative susceptibility mapping (QSM)
MIT License
46 stars 10 forks source link

Error for EchoCombine OptimumWeight #46

Closed orie2409 closed 1 year ago

orie2409 commented 1 year ago

Hi there,

I appreciate your help with the following error:

Screenshot from 2022-10-26 14-51-10

My phase and magnitude images are the same shape. Here is the config I am running:

Screenshot from 2022-10-26 14-49-05

and here is my header.mat file:

Screenshot from 2022-10-26 14-55-08

Thanks in advance, Lindsay

kschan0214 commented 1 year ago

Hi Lindsay,

Inside the output directory there should a log file called 'run_sepia.logXXXXXXXX' which contains all the output messages shown on the command window. Can you also upload that file here? I'll see if I can reproduce the error using similar setup.

Kwok

orie2409 commented 1 year ago

Hi, here is the file.I can also upload the magnitude and phase image if that would be helpful? run_sepia.zip

kschan0214 commented 1 year ago

Thanks for sending the file across. I successfully reproduced the error.

The error occurs when the input data have an odd number matrix size (in this case the z-dim is 13). In SEPIA, all dimensions with odd number are zero padded but there is a bug that didn't remove the zero pads in some of the variables after the phase unwrapping step, creating mismatches in matrix size between images. This bug will be fixed in the next update of SEPIA.

A quick fix without updating SEPIA would be zeropaded the z-dimension of your data to an even number (e.g. 14) and remove the zeropad after the processing. This can be done by, e.g.,

Before running SEPIA

Add zeropad to odd dimension in both magnitude and phase images

% to use utility functions in SEPIA
sepia_addpath

% input
magn_filename   = '~/Sepia_part-mag.nii.gz';      % modified **fullpath to your data**
phase_filename  = '~/Sepia_part-phase.nii.gz';    % modified **fullpath to your data**
% output
magn_zeropad_filename   = '~/Sepia_part-mag_zeropad.nii.gz';      % modified **new fullpath to your data**
phase_zeropad_filename  = '~/Sepia_part-phase_zeropad.nii.gz';    % modified **new fullpath to your data**

% get NIFTI header
nii = load_untouch_nii(magn_filename);
% zero pad odd dimension
nii.img = zeropad_odd_dimension(nii.img,'pre');
% update NIFTI header
nii.hdr.dime.dim(2:5) = size(nii.img);
% export NIFTI
save_untouch_nii(nii,magn_zeropad_filename);

% get NIFTI header
nii = load_untouch_nii(phase_filename);
% zero pad odd dimension
nii.img = zeropad_odd_dimension(nii.img,'pre');
% update NIFTI header
nii.hdr.dime.dim(2:5) = size(nii.img);
% export NIFTI
save_untouch_nii(nii,phase_zeropad_filename);

Then use the zero padded images for SEPIA.

After running SEPIA

Remove zeropad from all SEPIA output

% to use utility function in SEPIA
sepia_addpath;

magn_filename    = '~/Sepia_part-mag.nii.gz';      % modified **fullpath to your original data**
sepia_output_dir = '~/output/';     % modified **fullpath to your SEPIA output directory**

% get NIFTI header from original data
nii = load_untouch_nii(magn_filename);
nii.hdr.dime.datatype = 16;

% get all SEPIA output files in NIFTI format
file_list = dir(fullfile(sepia_output_dir,'*.nii.gz'));

for k = 1:length(file_list)
    % load NIFTI into Matlab
    input   = load_nii_img_only(fullfile(file_list(k).folder,file_list(k).name));
    % remove zeropad
    output  = zeropad_odd_dimension(input,'post',size(nii.img));

    dims = size(output);

    % update NIFTI
    nii.hdr.dime.dim(2:4) = dims(1:3);
    nii.img = output;
    % export NIFTI
    save_untouch_nii(nii,fullfile(file_list(k).folder,file_list(k).name));
end

Other suggestions

I also noticed that you have a thin imaging slab (13 mm). In this case, BET (used in SEPIA to produce brain mask) is likely to fail and can render an incorrect susceptibility map at the end. Therefore, I would recommend first to produce a signal mask outside of the SEPIA environment (e.g., using ITK-snap), then provide this mask file as an input of SEPIA.

(When SHARP/VSHARP/RESHARP is selected for background field removal you may also turn off the "Remove residual B1 field" option)

Hope this could be helpful and please let me know whether the above solution works for you.

orie2409 commented 1 year ago

Thanks so much for your help, it's now working for me. Thanks for your fast response and additional suggestions!