Pages

3.5.12

Custom Colors for Matlab Plots


This is a(nother) simple function I wrote for matlab, it can also be downloaded from my file exchange at mathworks:
http://www.mathworks.com/matlabcentral/fileexchange/36514-custom-colors-for-plots

In plot graphs, often it's needed to use a several colors that can be easily differentiated on a first look on the graphic. With this function you can call easily (by name or by code) a selection of 15 colors.
It's very simple and there are more elegant ways to do it, but I think it's a very functional solution.


function ccol=CustomColors(ct1)
%This is a function to create some easy to differentiate colors, very
%useful when plotting many things in the same graphic
%The RGB coordinates and names where taken from the following page:
%http://web.njit.edu/~kevin/rgb.txt.html
%
%Examples:
%for ccc=1:15
%plot(ccc*ones(1,10),'Linewidth',4,'Color', CustomColors(ccc))
%end
%
%plot(ones(1,10),'Linewidth',4,'Color', CustomColors('Coral'))
%plot(ones(1,10),'Linewidth',4,'Color', CustomColors('DeepSkyBlue4'))
%
%Copyright: Andres Gonzalez. 2012.

CColors={
    [   [0,0.407843137254902,0.545098039215686] ];% DeepSkyBlue4
    [   [0.545098039215686,0.270588235294118,0.0745098039215686]    ];% SaddleBrown
    [   [0,0.803921568627451,0] ];% green3
    [   [0,0.498039215686275,1] ];% SlateBlue
    [   [0.956862745098039,0.643137254901961,0.376470588235294] ];% SandyBrown
    [   [0.419607843137255,0.556862745098039,0.137254901960784] ];% OliveDrab
    [   [0.800000000000000,0.196078431372549,0.600000000000000] ];% Violet,Red
    [   [0.556862745098039,0.419607843137255,0.137254901960784] ];% Sienna
    [   [0.803921568627451,0.678431372549020,0] ];% gold3
    [   [0.545098039215686,0,0.545098039215686] ];% magenta4
    [   [1,0.498039215686275,0] ];% coral
    [   [1,0.843137254901961,0] ];% gold1
    [   [0.600000000000000,0.196078431372549,0.800000000000000] ];% DarkOrchid
    [   [0.941176470588235,0.501960784313726,0.501960784313726] ];% LightCoral
    [   [0.635294117647059,0.803921568627451,0.352941176470588] ];% DarkOliveGreen3
   
    };
NColors={
    'DeepSkyBlue4';
    'SaddleBrown';
    'Green3';
    'SlateBlue';
    'SandyBrown';
    'OliveDrab';
    'VioletRed';
    'Sienna';
    'Gold3';
    'Magenta';
    'Coral';
    'Gold1';
    'DarkOrchid';
    'LightCoral';
    'DarkOliveGreen3';
    };

switch class(ct1)
    case 'double'
        if ct1<1
            ct1=1
            disp(sprintf('Color index must be between 1 and %d, taking closest value [%d]',length(CColors),ct1))
        elseif ct1>length(CColors)
            ct1=length(CColors)
            disp(sprintf('Color index must be between 1 and %d, taking closest value [%d]',length(CColors),ct1))
        end
       
       
       
    case 'char'
        ctfound=0
        for ct2=1:length(NColors)
            if (strcmp(NColors{ct2},ct1))
                ctfound=ct2
            end
        end
        if ctfound==0
            disp(sprintf('Color not found taking default value [%d]',1))
        else
            ct1=ctfound
        end
       
    otherwise
        disp(sprintf('Color not valid taking default value [%d]',1))
       
       
end





ccol=CColors{ct1}
end






17.4.12

Save Workspace to Struct

This was a nice function that I created today, and it allows to save all the variables from the "base" workspace to a single struct, in order to have them all nicely packed in case you want to create mat file with them and later reload it without having so much worry of overwriting the variables in the other workspace. I gratefully accept suggestions for better options.
And now it's also available at the Matlab Central (if you want to rate it, which is always welcome):  http://www.mathworks.com/matlabcentral/fileexchange/36257-save-workspace-to-struct

%This Script saves all the variables from the current workspace into a
%single structure array.
%Created by Andres Gonzalez. 2012

function WStruct=ws2struct()

WSVARS = evalin('base', 'who');
for wscon=1:size(WSVARS,1)
    thisvar=evalin('base', WSVARS{wscon});
    eval(strcat('THEWORKSPACE.(WSVARS{wscon})=thisvar;'))
end

WStruct=THEWORKSPACE;

27.2.12

Brain Registration with ANTS Toolkit

In most neuro imaging research it is needed to study specific areas of the brain instead of the wholevolume. For me, as many other researchers, it is very difficult or impossible to locate by hand some specific brain areas. And it is not desired to do conclusions over an area that is not correctly located, because this conclusions will end up corresponding to some other part of the brain. So, is very important to use a good tool for registration. The following papers explain why ANTs is one of the best tools for Brain Registration: 
http://www.mindboggle.info/papers/evaluation_NeuroImage2010/Evaluation_Klein_NeuroImage2010.pdf
http://www.mindboggle.info/papers/evaluation_NeuroImage2009/Evaluation_Klein_NeuroImage2009.pdf
There are no “best parameters”for every registration, it mostly depends on the resolution of the images and the moving and fix spaces as well as many other characteristics. However, I think that there should be some basic recommendations for running a correct corregister, because it would be a waste of time to try on with hundred possibilities for each parameter. As a new ANTs user I struggled a lot trying to find out which could be the best options to be used, because every paper I read would say that the best parameters were different depending each specific situation. But still, for a new user is difficult to guess from zero the best options. So finally, after reading ANTs manual and with personal communication with Dr. Klein, I did a resume that I hope can help as a basis for other people that are learning about ANTs as well.  
The file ants.h that can be found on my web page contains my recommended parameters for doing brain registration from an atlas to a subject's space. It can be executed directly from the command line if you have ANTs installed in your computer. You can find there as well an explanation on how the parameters were chosen. 
Visit www.monicagiraldochica.com (go to 'My PhD Project' > Project Progress > Files)