eXTReMe Tracker
Sep 122016

There is good news for those who use neuroimaging tools such as AFNI, FSL and FreeSurfer on their Windows machines. The limitation is that they can only be run on Windows 10 with anniversary update. Does it use a Virtual Machine? No. It runs “natively” on Windows 10, so you can save, print, resize or hide any interface just like a Windows program.

Freeview running in Windows 10

Freesurfer on Windows 10

Before I get into how to install FreeSurfer, I must thank the author at K-Lab for the post on “How to run FSL on Windows 10“. That post describes how to install BASH on Windows 10 in the first few steps. Sadly it is not available for Windows 7/8. It uses Ubuntu 14.04 LTS which will be supported by Canonical until 2019. We hope by then Windows would incorporate the Ubuntu 16.04 LTS as the default distribution.

I’ll repeat a few things (steps 1-5) that Lin4Neuro wrote on how to get BASH and X-server on Windows 10.

  1. Install Linux BASH shell on Windows 10:
    There is detailed tutorial with screenshots on how to do this at the following site.
    How to Install and Use the Linux Bash Shell on Windows 10
  2. Install the updates:
    Before adding any tools, you should first download and install the updates for Ubuntu. Run the following commands at the terminal

    sudo apt-get update
    sudo apt-get upgrade
  3. Install the X server:
    Installing BASH will allow you to run applications on a command line but in order to run any GUIs for neuroimaging tools you require a X-server for windows. The most popular software for this is Xming. You can download and install it with default settings.
    Xming X server for Windows
  4. Running X server:
    Run Xming by searching it from start menu. When it is loaded you should see this when you go to show hidden icons button at the bottom right corner of your desktop.
  5. In order for X server to work with BASH run the following command at the terminal
    echo "export DISPLAY=localhost:0.0" >> ~/.bashrc

    This will add the environment variable for display to the .bashrc file.

  6. Downloading Freesurfer:
    You can obtain your copy of Freesurfer from their web page. I would recommend getting the nightly build as I was having some trouble running the stable version v5.30, especially some of the graphical windows. If you want to try the stable version download the 64-bit centos6 stable v5.3.0 freesurfer. I would encourage getting the v6.0 nightly build even though it is not the official release. You can go back and reinstall the stable version 6.0 once it is released.To download your choice of FreeSurfer type this command at the terminal:
    For stable release v5.3.0


    For nightly build

    wget ftp://surfer.nmr.mgh.harvard.edu/pub/dist/freesurfer/dev/freesurfer-Linux-centos6_x86_64-dev.tar.gz

    Hint: You can copy the link with your mouse and when you right-click at the terminal, it will be automatically pasted so you don’t have to type it in manually.
    This is a large file (~4.6GB) so it may take some time to download it based on your network speed.

  7.  Extract the zipped file to install it. It is customary to install it at /usr/local/ so let’s extract it to that directory.
    sudo tar -xzf freesurfer-Linux-centos6_x86_64-dev.tar.gz -C /usr/local/

    You will require your admin password (for Linux) to extract it to /usr/local. Again this step can take few minutes since it is extracting a file that’s several gigabytes in size. Once extracted, we’ll have to change permissions on that folder.

    sudo chmod -R 755 /usr/local/freesurfer

    This allows you to make changes to files in that folder.

  8. Obtain the FreeSurfer license:
    In order to run the FreeSurfer applications you need to register and obtain a license from their website.
    FreeSurfer Registration
    Once you have the license emailed to you, copy the contents between the lines that read “cut here” and create a license.txt file.

    sudo nano /usr/local/freesurfer/license.txt

    Paste the contents with right-click
    Press ctrl+X to exit
    Press y to accept and save it as license.txt
    Hit Enter

  9. Add FreeSurfer path to .bashrc:
    echo "export FREESURFER_HOME=/usr/local/freesurfer" >> ~/.bashrc
    echo "source $FREESURFER_HOME/SetUpFreeSurfer.sh" >> ~/.bashrc
  10. Dependencies: libjpeg.so.62
    Generally there is a libjpeg dependency that is required by FreeSurfer graphics. It doesn’t come with the basic Ubuntu installation but it can be installed using:

    sudo apt-get install libjpeg62
  11. Final check:
    Check that the Xming server is running and it says Xming Server:0.0 when you hover the mouse on the icon in the lower right hand corner.Type bash at the terminal. You should see the following:

    -------- freesurfer-Linux-centos6_x86_6.0 --------
    Setting up environment for FreeSurfer/FS-FAST (and FSL)
    FREESURFER_HOME   /usr/local/freesurfer
    FSFAST_HOME       /usr/local/freesurfer/fsfast
    SUBJECTS_DIR      /usr/local/freesurfer/subjects
    MNI_DIR           /usr/local/freesurfer/mni
  12. Test your installation:
    Check if everything works by going through some of the examples listed on the FreeSurfer website.
    FreeSurfer examples
    If everything has been installed correctly you should be able to run command line functions and open GUIs just like on a Mac or Linux machine.
    tksurfer_win10If you have any questions about the installation, please post a comment. If you have questions about FreeSurfer please visit the FreeSurfer user community mail archives.
Jan 062016

For the past several releases the option of opening something in terminal by right clicking on the desktop, a file or a folder has been missing in MATE environment of Linux mint. This has been set by default. However you can enable that functionality by installing a package called caja-open-terminal.

sudo apt-get install caja-open-terminal

After installing the package, you will have “Open in terminal” as one of the options in the context menu when you right click on icons or certain locations.

Jul 312015

If gnome-do fails to locate and launch terminal (or gnome-terminal), it is because of a small omission in the gnome-desktop.terminal file.

In terminal run:

locate gnome-desktop.terminal

Once you find that file, open it using nano or gedit with sudo.

sudo nano /usr/share/applications/gnome-terminal.desktop

Search for the line that says:


Add X-Cinnamon to the end of that line such that it reads.


That’s it. Once you log out and log back in, terminal will start appearing as one of the search results in gnome-do.

May 272015

In Linux Mint 16 and 17, there is a small bug in gnome-do. Well, techincally it is in a file called gnome-terminal.desktop

Searching for terminal in gnome-do in Cinnamon environment gives no results for gnome-terminal. The first entry is usually Printers. This is caused because of an omission in the gnome-terminal.desktop file.

Open terminal by searching through start menu:

locate gnome-terminal.desktop

You will usually find it at: /usr/share/applications/gnome-terminal.desktop

sudo nano /usr/share/applications/gnome-terminal.desktop

Find the line that says:


To that list add X-Cinnamon so it will read.


Save the file and log out. Once you login again, terminal should appear on top of Gnome-do search as soon as you type t.

May 042015

Found a 5-leaf clover in my garden this morning. Definitely a step up from a four leaf one.


Apr 232015
Dining Area Kitchen Kitchen Dining Area Porch Backyard Backyard From the backyard Porch Kitchen Living and Kitchen capecod012 Staircase Master Bedroom Guest Bedroom Guest Bedroom Front Landing Living Area Staircase Staircase Garage Garage Garage Garage Basement - Den and Bedroom Basement den Basement den Below the staircase Two car garage Some sectioned out places in yard From the edge From the edge Guest Bath Guest Bath Bath Bath Bath Master Bed Master Bed Master Bed Door Street View Street View Front Door
Dining Area
Dec 222014

The purpose is to to convert a 3-dimensional image file which contains X,Y and the dimensions containing RGB values to a 2D image file in grayscale. It can be done in linux command line using imagemagick.

convert <img_in> -set colorspace Gray -separate -average <img_out>

The resulting image is a 2D image generated by averaging the R,G,B arrays.

Dec 152014

Converting nifti files to dicom using nifti toolbox in matlab

clear; clc;
 [dicomfile, dicompath] = uigetfile('*.dcm','Select DICOM header for metadata');
 metadata = dicominfo(fullfile(dicompath, dicomfile));
 metadataISAS=metadata; metadataMPR=metadata; metadataFUS=metadata;
 metadataMPR.SeriesDescription = 'SAG_MPRAGE_T1_Recon'; metadataMPR.SeriesNumber = 1;
 metadataISAS.SeriesDescription = 'ISAS Hyperperfusion'; metadataISAS.SeriesNumber = 2;
 metadataFUS.SeriesDescription = 'MPRAGE ISAS Fusion'; metadataFUS.SeriesNumber = 3;
 isas = uigetfile('hyper*.nii','Select hyperpefusion file');
 structural = uigetfile('mprage*.nii','Select MPRAGE');
 isas = load_untouch_nii(isas); isas = isas.img; isas = int16(isas);
 structural = load_untouch_nii(structural); structural = structural.img;
 display('... Merging Hyperperfusion and MPRAGE');
 merged = structural;
 merged(isas>0) = max(max(max(structural)))+10;
 display('... Finished Merging')
 isasdir = fullfile(subjectdir,'isas');
 if exist(isasdir) ~= 7
     mkdir(fullfile(isasdir,'SPECT_ISAS')); spectdir = fullfile(isasdir,'SPECT_ISAS');
     mkdir(fullfile(isasdir,'structural')); structdir = fullfile(isasdir,'structural');
     mkdir(fullfile(isasdir,'fusion')); fusiondir = fullfile(isasdir,'fusion');
 % dicomwrite(reshape(x4,[170,256,1,256]), 'SPECT_ISAS.dcm', metadata, 'CreateMode', 'copy');
 display('... Creating DICOMS');
 for slicenum = 1:size(isas,1)
     cd(spectdir); metadataISAS.InstanceNumber = slicenum;
     dicomwrite(fliplr(rot90(squeeze(isas(slicenum,:,:)))), sprintf('SPECT_ISAS_%03d.dcm',slicenum), metadataISAS, 'CreateMode', 'copy');
     cd(structdir); metadataMPR.InstanceNumber = slicenum;
     dicomwrite(fliplr(rot90(squeeze(structural(slicenum,:,:)))), sprintf('structural_%03d.dcm',slicenum), metadataMPR, 'CreateMode', 'copy');
     cd(fusiondir); metadataFUS.InstanceNumber = slicenum;
     dicomwrite(fliplr(rot90(squeeze(merged(slicenum,:,:)))), sprintf('FUSION_MPR_ISAS_%03d.dcm',slicenum), metadataFUS, 'CreateMode', 'copy');
     display(sprintf('... Creating slice %d',slicenum))
Oct 232014

To compute a transpose of an input file, i.e. converting columns to rows and rows to column using bash, you can accomplish that using awk and while loop.

cols=`cat $1 | head -1 | wc -w`;
for i in $(seq 1 $cols);
awk -v "n=$i" '{print $n}' $1 | tr '\n' ' ';  # variable column output
printf "\n";

This example uses a variable to output a specific column from the input.

awk -v "n=$variable" '{print $n} ' input.txt

Will pass the variable to n and the nth column gets printed from input file.

Sep 162014

Every once in a while as you are trying to make a .iso file from a DVD using Brasero, you might get an error saying that couldn’t retrieve the keys because of libdvdscc2.

An alternative to that is a command line tool called dvdbackup which first needs to be installed

sudo apt-get install dvdbackup

After installing that program, you can make backup of your entire dvd, unfortunately not an .iso. You can create an iso from the folder that gets generated once you backup the dvd using dvdbackup. To create a backup, open your terminal and run:

 dvdbackup -M -i /path/to/dvd/  -n Title_For_Backup -o /path/to/output/directory

To get help of dvdbackup you simply have to type in dvdbackup at the terminal.