Archive

Archive for November, 2008

Localize AIR/Flex applications

November 29th, 2008

The very first thing to do is to create a locale file using copylocale utility. e.g.
copylocale en_US zh_CN

More detail can be found in http://www.herrodius.com/blog/123 and here is a copy from there:
- open a command line (run as administrator in Vista!)
- go to the “bin” folder in your Flex SDK installation folder
- run the copylocale.exe tool for each locale, this will copy the localized framework files from one locale to another (copylocale en_US nl_BE)
- check FLEX_HOME\frameworks\locale to see if the folder for your new locale has been created

Author: Xu Cui Categories: adobe air Tags:

Data binding using pure actionscript

November 26th, 2008

[update]
To call a function when a property of an object changes, use the following code
BindingUtils.bindSetter(callThisFunction, aObject, "prop");
Note, callThisFunction is a setter (need one argument and return void)


In MXML it’s easy to bind data using {}. Sometimes you may prefer to use actionscript as it is more efficient. How to achieve data binding in actionscript? The ultimate question is, how do you know when data changes? Here I only focus on complex data (i.e. custom Object. e.g. a Person Object which has two variable, name and age) instead of simple ones (String, int, etc). For complex data, there are two types of changes:

  1. Reference change
    This is caused by new operator. (e.g. p = new Person('Mike',32);)
  2. Property change
    This is caused by directly changing the properties (e.g. p.name = 'John' or p.age = 20;). The reference of the object is not changed.

We apparently want to detect both changes. First, we need to use [Bindable] metatag for the Person class. Otherwise, we won’t be able to detect property change.

package
{
	[Bindable] // necessary if you want to detect changes when individual properties are changed but the reference not changed
	public class Person
	{
		public var name:String = '';
		public var age:int = 0;

		public function Person(name:String=null, age:int=undefined):void
		{
			this.name = name;
			this.age = age;
		}
	}
}

Then we create our custom component using actionscript only. This custom component, we call DisplayPersonComponent, is to display name and age in TextInput. It also has a member variable person:Person.

package
{
	import mx.binding.utils.BindingUtils;
	import mx.binding.utils.ChangeWatcher;
	import mx.containers.VBox;
	import mx.controls.TextInput;	

	public class DisplayPersonComponent extends VBox
	{
		[Bindable]
		public var person:Person;

		public var nti:TextInput; // to display name
		public var ati:TextInput; // to display age		

		public function DisplayPersonComponent()
		{
			super();

			nti = new TextInput();
			ati = new TextInput();

			this.addChild(nti);
			this.addChild(ati);

			ChangeWatcher.watch(this, "person", onReferenceChange);
		}
		private function setupBinding():void
		{
			BindingUtils.bindProperty(nti, 'text', person, 'name');
			BindingUtils.bindProperty(ati, 'text', person, 'age');
		}
		private function onReferenceChange(event:Event):void
		{
			setupBinding();
		}
	}
}

For comparison, let’s create the same component using mxml (which is much shorter) and call it DisplayPersonComponentMX.

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml">
	<mx:Script>
		<![CDATA[
			[Bindable]
			public var person:Person;
		]]>
	</mx:Script>
	<mx:TextInput id="nti" text="{person.name}" />
	<mx:TextInput id="ati" text="{person.age}" />
</mx:VBox>

Finally, let’s test it with an application.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:local="*">
<mx:Script>
	<![CDATA[
		[Bindable]
		private var aperson:Person = new Person();
	]]>
</mx:Script>

	<mx:Panel title="Component written in actionscript" width="300" height="100">
		<local:DisplayPersonComponent person="{this.aperson}" />
	</mx:Panel>

	<mx:Panel title="Component written in mxml" width="300" height="100">
		<local:DisplayPersonComponentMX person="{this.aperson}" />
	</mx:Panel>

	<mx:Button label="change person" click="aperson = new Person(Math.random().toString(), Math.random()*50);" />
	<mx:Button label="change person's individual property" click="aperson.name = Math.random().toString(); aperson.age = Math.random()*50;" />
</mx:Application>

Author: Xu Cui Categories: adobe air Tags:

两个奇怪的成语:卧槽泥马,马勒戈壁

November 25th, 2008

卧槽泥马:

  ⑴形容识人不明.表示明明其能力不足.但上位者因为种种原因或糊涂.任其肆意妄为.
  ⑵形容虚有其表,窃居名位者.表示即使给某人相应的地位.但其能力不足是无法改变的.(等同于烂泥扶不上墙.沐猴而冠)
  ⑶形容模仿不到家,反而不伦不类.

  典故:出自《战国策.楚策四》
  伯乐多良马.其有邻亚犁.曾与人言.”我亦善识马.有一骏马.伯乐不及.”人皆疑.欲观之.亚犁恐.乃以草泥置一卧马于槽中.众人视之笑其蠢.皆曰:”此何良驹.卧槽泥马尔.”

  下面给出三个词义的例句:
  1、红鸟这厮也能当上十二骑士,卧槽泥马啊;
  2、阿斗烂泥扶不上墙,即使上将潘凤在身边也不能稳坐江山,卧槽泥马呀;
  3、不会做就别做,PS个老虎照片也敢拿出来,真是卧槽泥马。

  此外,象棋中有一类残局叫做“泥马残局”,其中也有以“卧槽泥马”为名的杀法。此类残局来源于“泥马渡康王”的传奇故事,摘录如下。
  夹江卧槽泥马渡康王 ……
    
  典出《战国策.楚策四》?翻烂了《战国策》也只有找到这段和马有关:
  “汗明见春申君,候问三月,而后得见。谈卒,春申君大悦之。……汗明曰:“君亦闻骥乎?夫骥之齿至矣,服盐车而上太行。蹄申膝折,尾湛溃,漉汁洒地,白汗交流,中阪迁延,负辕不能上。伯乐遭之,下车攀而哭之,解衣以之。骥于是而喷,仰而鸣,声达于天,若出金石声者,何也?彼见伯乐之知己也。……”

另外,我想“卧槽泥马”都是成语,那“马勒戈壁”必定也是成语了,经过我多日的收集资料和研究,终于应正了我的想法。如下资料:

马勒戈壁:

  词义:比喻天下太平,不再用兵。现形容思想麻痹。
  词音:mǎ le ge bi
  出处:《尚书.武成》:“王来自商,至于丰,乃偃武修文,归马于戈壁之阳,放牛于桃林之野,示天下弗服。”
  使用举例:其时天下太平已久,真个是马勒戈壁,刀枪入库;五谷丰登,万民乐业。★清.钱彩《说岳全传》第一回。

玛勒格碧

名词解释: 惊奇的发现他也是意大利的俚语!可见中国的文化影响有多深!如下资料: 
  
玛勒格碧
  开放分类: 文化、艺术、意大利
  玛勒~格碧
  Melle Gebi
  (1462.5.15—1543.3.6,佛罗伦萨〔今意大利境内〕)
  原名玛勒。怡丝。格碧Melle d’14 Gebi。
  意大利木雕师、雕塑家、建筑师。1491–1692年,他为佛罗伦萨圣玛利亚教堂和韦基奥(Vecchio)宫作了大量雕饰。1506年设计圣玛利亚。德尔。菲奥里(Sta. Maria del Fiore)教堂圆顶下的鼓形座,因遭米开朗基罗的反对而未实现。他还设计了巴托利尼(Bartolini)府邸和圣斯皮里托(S. Spirito)教堂的钟塔。
  
  在意大利 ,玛勒格碧的东西被称作 “玛勒格碧的”
  当今的某电视台新大楼也是汲取了他的设计灵感,宏伟辉煌,令人们每次看到都在心底默念其名字:玛勒格碧,以此来纪念这位伟大的建筑师。
  后来人们为了纪念这位伟大的雕塑家,就以她的名字来问候对方“你玛勒格碧呀!”。
  而当人们心情不好时,也会在心里说一声“玛勒格碧”来缓解。

来源 Wenxuecity

Author: Xu Cui Categories: fun Tags:

brain images: Change data type of brain image

November 24th, 2008

An image file can be saved in different formats such as uint8 or int16, etc, based on different number of bytes used for each voxel. How to convert between them? Here is one solution using SPM functions (no need SPM’s interface). Assume img1.img is the original image with datatype int16, img2.img is the file you want to create with datatype uint8.

V=spm_vol('img1.img');
disp(V.dim); %you will find the last element is 4
V2=V;
V2.fname='img2.img';
V2.dim(4)=2;
M=spm_read_vols(V);
spm_write_vol(V2, M);

Explanation:
Variable V.dim is a 1×4 vector. The first three are number of voxels (or dimensions) along x,y and z direction. The last element (4th) is the number of bytes used for each voxel and it is this variable we want to change.

I myself find the following 3 SPM functions are extremely useful and use them a lot:

V=spm_vol('img1.img'); % read header information of an image file
M=spm_read_vols(V); % read the data (voxel intensity) from an image. The result is a 3D matrix with each point corresponding to a point in brain.
spm_write_vol(V2, M); % write data to an image file.

Check out here to see how to convert images with different formats (e.g. ANALYZE, Nifti, DICOM etc)

Author: Xu Cui Categories: brain Tags:

Brain AC-PC line

November 21st, 2008

AC: anterior commissure
PC: posterior commissure

The Anterior Commissure (precommissure) is a bundle of white fibers, connecting the two cerebral hemispheres across the middle line, and placed in front of the columns of the fornix. On a sagittal section, it is oval in shape, having a long vertical diameter that measures about 5 mm. (ref: wiki)

The posterior commissure is a rounded band of white fibers crossing the middle line on the dorsal aspect of the upper end of the cerebral aqueduct. (ref: wiki)

Test yourself: Find AC and PC here.

Author: Xu Cui Categories: brain Tags:

Talk by Frans de Waal

November 21st, 2008

Today I listened to Frans de Waal’s talk on empathy in primates. It’s quite interesting. He wrote several popular books including “Chimpanzee Politics”.

Links:
Frans de Waal

Author: Xu Cui Categories: brain Tags:

View 200+ AIR/Flex samples (Tour de Flex)

November 21st, 2008


http://flex.org/tour

Especially checkout two applications:
1. Badger

2. Transparent video window

Author: Xu Cui Categories: adobe air Tags:

Writing tips

November 20th, 2008
  1. The knowledge of brain-function mapping is accumulated …
    The Knowledge of brain-function mapping is accumulated … (get rid of the in front of knowledge)
  2. Don’t start a sentence with it, this. Instead, specify what it is.
  3. Don’t start a paragraph with “at the same time”. At the same time of what?!
  4. When writing a grant/fellowship, use their language (e.g. if they say ’specific plans’, you should not say ’specific aims’
  5. Use ‘brain disorder’ instead of ‘mental disorder’ (well, this should depend on the context)
  6. The overarching goal of this study is to develop …
  7. Success in the enterprise will provide important theoretical and clinical insights and will launch future interdisciplinary basic, clinical, translational pediatric neuroscience research.
Author: Xu Cui Categories: writing Tags:

Analyze NIRS data with NIRS-SPM

November 18th, 2008

being updated for v01_r14 …

NIRS-SPM is a SPM5 and MATLAB-based software package for statistical analysis of near-infrared spectroscopy (NIRS) signals, developed at the Bio Imaging Signal Processing (BISP) lab. at KAIST in Korea.

prepare files needed by NIRS-SPM

  1. NIRS data (in csv format or nii format. For Hitachi ETG4000, you need “File out” the measurement data, not the Hb data, into csv format)
  2. (optional) Structural image (e.g. xu.img). I use SPM2 to do normalization and segmentation (below), but you can choose whatever tool you prefer.
    1. normalize the image (use template T1.mnc) and get two files, wxu.img and xu_sn.img. This step takes 2 min.
    2. segment the image (not the normalized image) into gray and white volumes and get 3 files (xu_seg1.img, xu_seg2.img and xu_seg3.img). They are gray, white, and CSF volumes. The first two images will be used in NIRS-SPM. This step takes ~6 min.
  3. (optional) Coordinate file (a plain text file, e.g. RealCoordinate.txt), from probe positioning system
    This file contains 3 columns, with each row a 3-D coordinate of a point measured with 3D digitizer. The total number of rows is the sum of landmarker points (nasion, inion, etc)  plus the number of optodes. You will have to specify the two numbers in NIRS-SPM.

    • If you don’t have 3d digitizer at all but you know the positions of each optodes in your structural image (e.g. you used vitamin E marker), you can simply find the positions using SPM’s display functionality and put into the file.
    • If you don’t have MRI image at all, you can use a standard brain image. You need to check how well the registration is visually.
    • If you don’t have MRI image, and you didn’t measure optode positions with 3D digitizer, but you take a picture of the subject, you can use a standard brain, and “guess” the optode coordinate with the picture.
    • If you don’t have MRI image, or 3D digitizer measurement, or a picture, then you can use a standard brain, and guess, and cross your finger.
  4. The event onset timing and duration (in seconds). For example, [12 34 55 67] etc.

NIRS-SPM system requirement:

  1. MatLab (with graphic display)
  2. SPM5 (note: not SPM2)

steps:

  1. (optional) Login scuttlebutt (even you are on scuttlebutt computer)
    ssh fmri@scuttlebutt -Y
  2. Start matlab with graphic support and spm5 in path
    e.g.
    ml7spm5 -jvm &
  3. add NIRS-SPM folder into MatLab path
    addpath('/net/cibsrdata/Volumes/SPNLData05/quarry/cuixu/NIRS/NIRS_SPM_v01_r14');
    (You need to replace NIRS-SPM path to your own path)
  4. Enter sample_data directory (optional)
    cd /net/cibsrdata/Volumes/SPNLData05/quarry/cuixu/NIRS/sample_data
  5. run NIRS-SPM and the main window pops up
    nirs_spm
  6. Click “Convert” button, data conversion window pops up
  7. Select Hitachi ETG-4000
    Select the csv file, conversion begins automatically. It will take ~20s
    Click “Save .mat file” button, and save the file as “converted_NIRS.mat”
    Close data conversion window.
  8. (optional) Display NIRS data.
    Click “Display NIRS Time Series” button in the main window. NIRS_TimeSeries_Viewer window pops up.
    Click “Specify NIRS(.mat) file” button and select “converted_NIRS.mat”. Time series of channel 1 is displayed.
    Click “Specify model parameter” button and input the vector of onsets and duration
    Close NIRS_TimeSeries_Viewer window
  9. Select “With MRI” and Click “Spatial registration” button, two windows pops up.
    Select “T1_MRimage/uniform.img” as T1 image
    Select “wuniform.img” as normalized T1 image
    Then a SPM big window pops up and the subject’s T1 is shown.
    Find point (-70 34 36) and click + (you will see the point is added into “Indicator Locations” window)
    Repeat for other points (-82 -31 36), (-1 85 -15 nasion), (-8 -86 -58 inion)
    In “Indicator Locations” window, enter 4 and 16 for “Indicator #” and “Optode #”
    Click “Select Real Coordinate File” button and select file “RealCoordinate_txt_format.txt”. The locations will be displayed.
    Click “Get Optode Pos. in MRI” button and select “T1_MRimage/uniform_sn.mat” file. Also select the gray and white file (”T1_MRimage/c1uniform.img” and “T1_MRimage/c2uniform.img”)
    After ~30s the coordinates in MRI is calculated.
    Click “View Channel Pos” button you will see the positions of channels
    Click Save button and save the position as “channel_position.mat”
  10. Click “Specify 1st Level” button and “NIRS_Specification” window pops up
    Select nirs data file “converted_NIRS.mat”
    Create directory “spm” and Select it
    Select “Oxy-Hb”.
    Click “Specification” and specify the following parameters
    “hrf (with time and dispersion derivatives”
    number of conditions: 1
    name for condition 1: right finger tapping
    vector of onsets: [42:51:501]*9.75
    duration: 21*9.75
    high-pass filter: 60
    low-pass filter: Gaussian
    Gaussian FWHM: 4
    Correct for serial correlations? none
    Then a big SPM window pops up with design matrix
    Close the windows except for the main window
  11. Click “Estimate” button in the main window, NIRS_Estimation window pops up
    Select “Individual Analysis”
    Select “SPM_indiv_HbO.mat” as SPM.mat
    Click “Estimation” button. It will take 7 min. File “V_indiv_HbO.mat” is saved.
  12. Click “Result NIRS” and NIRS_Results_Viewer window pops up
    Select SPM_indiv_HbO.mat
    Select channel_positoin.mat
    Click “Contrast”, SPM contrast manager window pops up
    Click “Define new contrast”. name: finger, type: t, contrast 1 0 0 0, click OK, click “Done”
    After ~20s T map is shown. Click “View the thresholded T-statistic” and try different p-values.
  13. Click “Result fMRI” and select SPM.mat in fMRI_result folder
    (can’t get this to work now)

files required:

  1. NIRS_data_finger_tapping.nir
  2. RealCoordinates_txt_format.txt
  3. uniform.img : subject’s structural image
  4. wuniform.img : subject’s structural image after normalization
  5. uniform_sn.mat : the mat file produced by SPM during structural image normalization
  6. c1uniform.img : gray volume of segmentation
  7. c2uniform.img : white volume of segmentation
  8. SPM.mat (for fMRI and NIRS comparison)
  9. spmT_0001.img (for fMRI and NIRS comparison)

inside the files:

  1. .nir file is simply a text file. Row is time and column is channel.
  2. .csv file is also text file exported from Hitachi ETG4000
  3. RealCoordinates.txt is a text file with each row a point coordinate.
  4. converted_NIRS, or nirs data after conversion is a mat file with a single variable nirs_data. nirs_data is a struct. An example is:
              oxyData: [5384x24 double]
              dxyData: [5384x24 double]
                   fs: 9.7500
           timeLength: 14
                  nch: 24
             lightNum: 2
        rawdataLength: 5384
  5. channel_position.mat, or the channel’s position after calculation is a mat file with a single variable, preproc_info. An example is:
           wT1_info: [1x1 struct]
        rend_ch_pos: {1x6 cell}
    

    wT1_info is the volume information of the normalized brain (you can get this info by spm_vol). rend_ch_pos is a cellarray. Each element contains a different view of the brain. Try
    figure;imagesc(preproc_info.rend_ch_pos{4}.ren)
    hold on;plot(preproc_info.rend_ch_pos{4}.rchn,preproc_info.rend_ch_pos{4}.cchn,'o')
    You will see how the channel positions are displayed.

  6. SPM_indiv_HbO.mat, containing estimation parameters and info
  7. V_indiv_HbO.mat, a matlab mat file containing variable V_nirs, which is a sparse matrix.

related links:

Author: Xu Cui Categories: brain, matlab, nirs Tags:

regular expression in actionscript

November 16th, 2008

lazy quantifier: Add a question mark (?) after any quantifier to change it to what is known as a lazy quantifier. For example, the following regular expression, which uses the lazy *? quantifier, matches <p> followed by the minimum number of characters possible (lazy), followed by </p>:

/<p>.*?<\/p>/
Author: Xu Cui Categories: adobe air Tags: