2014/05/26 Hiroyuki AKAMA
Sections and Orientations of the brain:
An example of anatomical or structural scan with the voxel size of 2-2-2 mm.
Let's load today's dataset, which is a simple 3D array.
>> load('brainimg.mat');
%A data in the variable named 'brainimg' is now loaded in the work space of MATLAB.
>>brainimg
%Let's see the 3D array representing a (standard) brain image...
>> size(brainimg)
Axial, Transverse, Horizontal
Coronal Sagittal
Superior Superior
Inferior
Inferior
Left Right
Posterior Anterior
Left Right
Anterior Posterior
ans =
53 63 23
%This is a 3D array with the size of 53 by 63 by 23.
>>size(brainimg,1)*size(brainimg,2)*size(brainimg,3) ans =
76797
%The total number of voxels in this volume is 76797.
%A coarse brain scan with the spatial resolution of 3 by 3 by 6 mm. The spatial resolution is very low but the file size is relatively small.
>> imagesc(brainimg(:,:,15))
%One axial (transverse, horizontal) slice Left
Right
Posterior(Caudal)<--->Anterior(Rostral)
>> imagesc(permute(brainimg(:,30,:), [1 3 2]))
%A coronal slice (=x-z plane). Note that the slice number 30 (in the middle, as a 'y' Lateral
Medial
Lateral
value) can be specified by a permutation order of [1 3 2] and that the integer 2 for 'y' value is at the end of this list. The image is toppled over sideways.
%imagesc(transpose(permute(brainimg(:,30,:), [1 3 2])))
>>imagesc(flipud(transpose(permute(brainimg(:,30,:), [1 3 2]))))
Superior (Dorsal)
Inferior (Ventral)
Left<--->Right
%flipud() flips array up to down.
>>colormap(gray)
%If you want to use the grey scale, here you are.
>> imagesc(flipud(transpose(permute(brainimg(26,:,:), [2 3 1]))))
% A sagittal slice (=a y-z plane) near the midline (we have 53 sagittal slices in total). Note that the slice number 26 (as the first element, an 'x' value) can be specified by a permutation order of [2 3 1] and that the integer 1 for 'x' value is at the end of this list. Using the flipud function, the image is not upside down.
Superior (Dorsal)
Posterior (Caudal)<--->Anterior (Rostral) Inferior (Ventral)
cf. flipping array...
>> tmp=rand(4,5) tmp =
0.8147 0.6324 0.9575 0.9572 0.4218 0.9058 0.0975 0.9649 0.4854 0.9157 0.1270 0.2785 0.1576 0.8003 0.7922 0.9134 0.5469 0.9706 0.1419 0.9595
>> flipud(tmp) %flip array top to bottom. ans =
0.9134 0.5469 0.9706 0.1419 0.9595 0.1270 0.2785 0.1576 0.8003 0.7922 0.9058 0.0975 0.9649 0.4854 0.9157 0.8147 0.6324 0.9575 0.9572 0.4218
>> fliplr(tmp) %flip array left to right. ans =
0.4218 0.9572 0.9575 0.6324 0.8147 0.9157 0.4854 0.9649 0.0975 0.9058 0.7922 0.8003 0.1576 0.2785 0.1270 0.9595 0.1419 0.9706 0.5469 0.9134
>>coronal_img=imagesc(flipud(transpose(permute(brainimg(:,35,:), [1 3 2]))));
>>flipped_coronal_img=imagesc(fliplr(flipud(transpose(permute(brainimg(:,35,:), [1 3 2])))));
% You can make a mirror-reversed image using the function of fliplr().
>>saveas(coronal_img,'z:¥¥coronal_img.jpg','jpg')
>>saveas(flipped_coronal_img,'z:¥¥flipped_coronal_img.jpg','jpg') Superior Superior
Inferior Inferior
Left<--->Right Right<--->Left A coronal slice and its flipped coronal slice. Left-Right versus Right-Left.
There are two kinds of ways to define Left and Right: Neurological Left-Right versus Radiological Left-Right.
Neurological: Left and Right for a subject, so thought from behind him/her. Radiological: Left and Right for an observer looking toward the face of a subject.
How to make your own Matlab function for display a slice of brain from a 3D array.
You might want to an 'm' file (file extension: m), which is a text file and whose name is identical to that of the function you want to implement there.
For example, let's create your function imagesc_coronal(<3D array>,<slice number>) as ' imagesc_coronal.m'.
function img= imagesc_coronal(threeDarray, slicenum)
%function <returned value>=<function name(file name)>(arguments)
%threeDarray and slicenum are temporary arguments.
imagesc(flipud(transpose(permute(threeDarray(:,slicenum,:), [1 3 2]))));
If you locate this m file in a directory to which you added the path so that Matlab can automatically search for it (you have to run beforehand addpath(<directory name>)), you can use the function executing for example,
>>imagesc_coronal(brainimg, 40)
to get the image of a coronal slice as follows.
But if you misuse it, error messages will appear.
>>imagesc_coronal(brainimg, 70)
??? インデックスが行列の次元を超えています。
エラー ==> imagesc_coronal at 2
imagesc(flipud(transpose(permute(threeDarray(:,slicenum,:), [1 3 2]))));
>> imagesc_coronal(brainimg, 20, 1)
??? エラー ==> imagesc_coronal 入力引数が多すぎます
However, it happens that the function mistakenly works well under some inappropriate parameter settings, for example, in the case of assigning a 2D array to the first argument.
>> imagesc_coronal(randn(30,30), 25)
So it would be better to expect some possible wrong uses and answers to them as error messages you customize by yourself.
function img = imagesc_coronal(threeDarray, slicenum) if(size(size(threeDarray),2)~=3)
error('imagesc_coronal.m:The first argument should be a three dimensional array.');
end
if(slicenum>size(threeDarray,2))
error('imagesc_coronal.m:The slice number you assigned is too large.'); end
imagesc(flipud(transpose(permute(threeDarray(:,slicenum,:), [1 3 2]))));
>> imagesc_coronal(randn(30,30), 25)
??? エラー ==> imagesc_coronal at 8
imagesc_coronal.m:The first argument should be a three dimensional array.
>> imagesc_coronal(brainimg, 70)
??? エラー ==> imagesc_coronal at 12
imagesc_coronal.m:The slice number you assigned is too large.
Another example:
function img = imagesc_coronal_lr(threeDarray, slicenum) if(size(size(threeDarray),2)~=3)
error('imagesc_coronal_lr.m:The first argument should be a three dimensional array.');
end
if(slicenum>size(threeDarray,2))
error('imagesc_coronal_lr.m:The slice number you assigned is too large.'); end
image_source=flipud(transpose(permute(threeDarray(:,slicenum,:), [1 3 2])));
subplot(1,2,1)
%The first row first column image number 1. imagesc(image_source);
axis image
title(strcat('Coronal slice: ', num2str(slicenum)))
subplot(1,2,2)
%The first row second column image number 2. imagesc(fliplr(image_source));
axis image
title(strcat('Mirror-reveres coronal slice: ', num2str(slicenum)))
%run imagesc_coronal_lr(brainimg, 36)