Visual Neuroscience Lab
  • Home
  • Neurodesktop
  • Behavioral
  • Labmeeting
  • DICOM to GLM
  • MRI
  • People
  • Other Topics
  • Archive
  1. MRI: from DICOM to GLM Analysis
  2. 04 - Removing Noise Scan
  • Home
  • Neurodesktop
  • MRI: from DICOM to GLM Analysis
    • 01 - DICOM to BIDS
    • 02 - T1w for PBn
    • 03 - Defacing
    • 04 - Removing Noise Scan
    • 05 - fmriprep
    • 06 - first level GLM
    • Troubleshooting
  • MRI
    • Retinotopic Mapping
    • 3D printing a brain
    • 7T anatomical analysis on neurodesk
    • MRI BIDS and OSF
    • fMRIprep analysis
    • Old MRI setup
    • Update to the MRI lab setup
    • Physiological noise correction
  • Behavioral
    • Vision tests
    • BIDS for behavioral studies
    • Custom-built chin rests
  • People
    • Stipends and prizes for master students
    • Coffee time
    • Participant compensation
    • Things to do if you are leaving the lab
    • Scientific writing in practice
    • Interns
    • Pflichtpraktikum
  • Other Topics
    • Calculating a priori sample size using G Power
    • Gamma correction
    • Contribute to the website
    • Lab Members Only!!!
  • Labmeeting
  • Archive

On this page

  • 1 Check for denoising scan in nifti file
    • 1.1 Open freeview
    • 1.2 Load a functional volume
    • 1.3 Check for Denoising Scan
  • 2 Remove Denoising from the data
  • 3 Confirm successful removal
  • 4 Repeat the process for your fmap!
  • 5 Next steps
  1. MRI: from DICOM to GLM Analysis
  2. 04 - Removing Noise Scan

04 - Removing Noise Scan

MRI
Preprocessing
Neurodesk
Step by step description of how to remove the denoising scan from your data
Author

MG

Published

March 8, 2025

For this step, you need to already have nifti files! If you currently only have DICOM files, please convert them to nifti’s first!

Depending on the sequence used in the scanner session, you might have data that were acquired with a denoising sequence. This is sometimes done, since it doesn´t take much time in the scanner, but you have the ability to denoise the data if it turns out to be necessary.

But by default, we don´t use this denoising information. Additionally, some applications (like fmriprep) cannot process data with this additional information!

Thus, before running our default pipeline with fmriprep, we have to remove this information from our scans!

1 Check for denoising scan in nifti file

1.1 Open freeview

You can check if the denoising sequence was used in for your data, by checking the functional scans in freeview. For this, you first have to source freesurfer and then open freeview:

  1. Open a terminal (Monitor Icon at the bottom left on neurodesk) Open Terminal

  2. Type ml freesurfer and press enter

  3. Type freeview and press enter (from time to time, it can take a while until freeview opens, be patient! It is also possible, that some messages about runtime are printed in the terminal, but that is nothing to worry about!) Opening freeview

\(\to\) When freeview opened successfully, it should look like this: Freeview Opened

1.2 Load a functional volume

Now you have to look at a functional scan to see if there is a denoising scan at the end.

For this, select File > Load Volume (top left corner in freeview): File > Load Volume

A new window opens, asking you to Select volume file. Either type in the path(s) to your/a functional scan manually, or start by clicking on the folder symbol Click on Folder Symbol

Navigate to your func directory in your BIDS, select one of the nifti files of one of the runs and press Open afterwards Select functional nifti file of a run in your bids directory

Now, with the field Select volume file specified with the path(s) to the nifti file, you can click OpenOpen Volume

When the volume loaded, it should see some kind of data and something that looks like a brain: First Frame of Functional Scan

1.3 Check for Denoising Scan

To check if a denoising scan is included in you data, use the slider next to Frames (left side, roughly in the middle), to navigate to the last frame. If a denoising sequence was used during data acquisition in the scanner, this frame looks “empty”. Toggle between the last and second to last frame, to visualize the difference even more Denoising Included in your Scan

If you confirmed the denoising being present in one of your functional runs, they will probably be there for all your runs. It might be good to check every run anyway.

2 Remove Denoising from the data

You confirmed denoising information being present in your data in the last section. To run fmriprep, we have to remove this information. To achieve this:

  1. Open a terminal Open Terminal

  2. Type ml freesurfer and press enter

  3. Type ml fsl and press enter

  4. Set your working directory to the directory with your functional data (i.e. the func directory in your BIDS-structure). For this, type cd followed by a space and then the path to the directory (type it in, or copy/paste approach described here). In the example below, the complete line is cd /home/jovyan/Website/bids/sub-999/ses-1/func Set Working Directory

The additional paths on the left of your cursor indicate, that the change of working directory was successfull:WD Changed Successfully

  1. Now we have to remove the last frame from each nifti file, since the last frame is the denoising. For this, copy paste the following code:
for nii_file in *_bold.nii.gz; do
    img_size=$(mri_info --dim "$nii_file" | grep -E '^[0-9]' | awk '{print $NF}')
    
    last_dim=$((img_size - 1))
    fslroi "$nii_file" "$nii_file" 0 -1 0 -1 0 -1 0 "$last_dim"
    echo "Processed: $nii_file with last dimension: $last_dim"
    
done

Information: this code basically searches for all files in your working directory that end on _bold.nii.gz, gets the information about how many frames it includes using mri_info and then removes the last frame (which we confirmed to be the denoising scan prior)

When you copy/paste into the terminal, the line breaks and indentation probably will look different, but this is no problem (see image below). Press enter to execute the pasted code. Code to remove noise scans

This process can take a while, especially in the beginning. Don´t get stressed out, when nothing happens for a while and only info statements get printed, be patient! Waiting

After some time, you will get the information, that the first nifti is processed. This will be repeated for all files in your working directory that end in _bold.nii.gz. Since the working directory is set to our func directory, the functional scans of all runs and potential functional localizer runs will be processed automatically: Remove Noise from all nii.gz files

3 Confirm successful removal

To confirm that the noise scan was removed from your functional scans, start freeview, load a functional scan and finally check the last frame. The original “empty” frame should now be removed and final scan should picture “normal” data.Noise Scan removed

4 Repeat the process for your fmap!

If your functional data were aquired with a denoising sequence and thus contained noise scans, your fmap will probably include noise scans as well! To remove the noise scans from the fmap, the same procedure has to be done, but this time with the fmap file(s):

  1. Open Freeview

  2. Open fmap

  3. Check if noise scan is included

  4. Open a terminal and source freesurfer & fsl (see Steps 1-3 here)

  5. Set your working directory (this time to your fmap directory!; adapt Step 4)

  6. Run the following Code:

for nii_file in *_epi.nii.gz; do
    img_size=$(mri_info --dim "$nii_file" | grep -E '^[0-9]' | awk '{print $NF}')
    
    last_dim=$((img_size - 1))
    fslroi "$nii_file" "$nii_file" 0 -1 0 -1 0 -1 0 "$last_dim"
    echo "Processed: $nii_file with last dimension: $last_dim"
    
done

Information: This basically does the same as the Code for removing the noise scan for the functional data (See Step 5 above), but this time, it doesn´t perform the task for files ending in _bold.nii.gz, but for files ending in _epi.nii.gz

  1. Wait until the all files are processed

  2. Check if the removal was successful

5 Next steps

Congratulations, you successfully removed the noise scans from your functional and fmap and you are one step closer to analyzing your data!

To continue in your journey to your Analysis, please return to the Overview-Page to check what to do next.

Alternatively, here is a list of potential next steps to continue with

  1. Defacing

  2. run fmriprep

Back to top