1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755
| %
% This script is intended to perform the full process
% of creating a rat-template based on the Paxonos atlas.
% Hence, it will also serve as a documentation of exactly
% what has been done.
%
% It will
% 1. Read a list of corresponding points defined by Petra
% in the Paxonos atlas and in a T2-weighted image volume
% of the rat we have chosen as our model rat. It will
% then find the affine transform that minimises the sum
% of squared distances between the paxonos and the T2
% point lists. Optionally it might minimise a weighted
% sum of squares where the weighting is derived from the
% subjective rating Petra supplied for each point.
%
% 2. Reslice the T2-weighted volume into a volume determined
% by Petra based on the extent of the Paxonos Atlas. It
% was determined we use a bounding box of -7mm->7mm in the
% x-direction, -2mm->10mm in the y-direction and 6mm->-16mm
% in the z-direction.
% For practical reasons I later extended the bounding box
% in the x and y directions, and decreased it in the z-direction
% such that the resulting bounding box was -8mm->8mm,
% -12mm->1mm (Bregma system) and -15.6mm->6mm (Bregma system).
% We also decided to go for 0.2x0.2x0.2mm voxels.
%
% This gives us reasonable matrix-sizes of 80x63x108 voxels.
%
% Furthermore it was decided (for practical reasons) to swap
% the y- and z-axes such that the "new" y-axis goes tail->nose
% in the rat, and the new z-axis goes belly->back in the rat.
% This way the aspect of the different projections is much more
% like those in the human brain, facilitating the adaptation to
% SPM.
%
% Also, it was decided that we work on tenths of mm, rather than
% in mm. This enables us to retain the one-to-one relationship
% between voxels in MIP.mat and the co-ordinates of the atlas,
% thereby preventing any major rewrite of spm_mip_ui.m.
%
% The result of this is that co-ordinate reported by SPM as
% [37 -45 -56] is to be interpreted as the position
% [3.7 -5.6 -4.5] (VLGPC, whatever that is) in the Paxinos
% Atlas.
%
% Two image volumes will be created, one from a filtered
% version (.8x.8x.8mm) of the T2-volume, to use as a template, and
% one from the unfiltered version to use as a "canonical" rat.
% There is also a brainmask.img file used to mask the
% spatial normalisation that is based on the canonical brain
% after applying a series of image-processing primitives
% (connected component labelling, dilatation and erosion).
% The files are
% /usr/local/spm99/ratlas/templates/canonical_T2.img
% /usr/local/spm99/ratlas/templates/template_T2.img
% /usr/local/spm99/ratlas/templates/brainmask.img
%
% 3. Create a very crude interface that allows a user to
% create a list of co-ordinates corresponding to outer
% contour in one selected slice each in axial, saggital
% and coronal sections of the Paxinaos atlas. This is
% based in .jpeg files supplied by Petra.
% These conturs have been saved to
% /d1/data/Petra/Paxinos.mat
% The contours were plotted to a 364x400 figure window,
% converted to a .bmp format and subsequently to a .mat
% format to render it compatible with MIP.mat.
% A variable named mip96 has been saved to
% /usr/local/spm99/ratlas/MIP.mat
%
% 4. Make necessary changes to spm_* routines. In order to
% facilitate adapatations to future releases of SPM etc
% it was decided to make as few and as small changes as
% possible to existing SPM routines. It was however not
% possible to avoid altogether.
% In general, each change has been "labelled" with a
% comment containing the word "Paxinos", so it should
% be easy to locate all altered lines.
% The following is a list of routines that has been
% changed, and a short description of the changes.
%
% /usr/local/spm99/ratlas/spm_project.c
% i) New values for widths and center-points of
% the mips.
% ii) The determination of wether a cluster falls
% within the borders of a mip is now based on
% atlas-coordinates rather than mip coordinates.
% iii) New way of determining coordinates of x-direction
% in transversal view.
%
% /usr/local/spm99/ratlas/spm_mip_ui.m
% i) New values for widths and center-points of
% the mips.
%
% /usr/local/spm99/ratlas/spm_sn3d.m
% i) It uses the Rat brainmask as default.
% ii) It uses a filter kernel of .8x.8x.8mm
% iii) It bases the calculation of FOV on transformed
% rather than original object coordinates.
%
% /usr/local/spm99/ratlas/spm_affsub3.m
% i) Disregards Bayesian prior based on human brains.
%
% /usr/local/spm99/ratlas/spm_defaults.m
% i) New value for sptl_Ornt that reflects zoom
% by a factor of 10, shift of y- and z-axes
% and the "non-central" nature of the Bregma.
% ii) New value for the bounding-box, reflecting
% the Paxinos atlas.
% iii) Spatial basis functions reflecting the aspect
% of the Rat brain.
%__________________________________________________________
% Jesper Andersson 23/1-02.
%
% As a part of facilitating the use of several rats
% conv_2_paxonos has been divided into several routines.
%
%
% When going through the data 14/6-02 the following
% observations were made.
%
% rat_plain_3:
% Worked fine. No outliers in the point distributions
% and a cursory check of normalised images vs the
% Paxinos atlas looked fine.
%
% rat_plain_4:
% Worked fine. No outliers in the point distributions
% and a cursory check of normalised images vs the
% Paxinos atlas looked fine.
%
% rat_plain_5 (aka spm_template):
% Worked fine. No outliers in the point distributions
% and a cursory check of normalised images vs the
% Paxinos atlas looked fine.
% %
% rat_plain_6:
% Both 'cpu' points were extreme outliers and disrupted
% the entire normalisation procedure. After removal of
% these it looked better, although the 'aci' points were
% now (not extreme) otliers. However, since these are unique
% in that they are the only points defining the mapping in
% the frontal bits I chose to leave them in.
%
% LFF4:
% Worked fine. No outliers in the point distributions
% and a cursory check of normalised images vs the
% Paxinos atlas looked fine.
%
%__________________________________________________________
% Jesper Andersson 14/6-02
%
% Here starts code pertaining to step 1 above.
%
%
% Start by reading .txt file.
%
%lecture des fichiers
txt_fname = '/d1/data/Petra/rat5/spm_template.txt';
ima_fname = '/d1/data/Petra/LFF4/s_0001.img';
hdr_fname = '/d1/data/Petra/LFF4/s_0001.hdr';
mat_fname = '/d1/data/Petra/LFF4/s_0001.mat';
crd = read_coordinates(txt_fname); %on recup les coordonnées ds un vecteur crd
%
% Remove cpu points for rat_plain_6.
%
%crd.spmc = [crd.spmc(1:23,:); crd.spmc(26:end,:)];
%crd.paxc = [crd.paxc(1:23,:); crd.paxc(26:end,:)];
%crd.qlty = crd.qlty([1:23 26:end]);
%j=1;
%for i=[1:23 26:length(crd.name)]
% crd.name{j} = crd.name{i};
% j = j+1;
%end
%
%
% Next create M matrix mapping between native and
% Paxinos space.
%
M = get_M(crd.spmc,crd.paxc,crd.qlty,crd.name);
%
% Save it as appurtenant .mat file.
%
save(mat_fname,'M');
%
% Create template (smooth) and canonical
% (non-smoothed) image volumes in
% Paxinos space.
%
make_tmplt_and_cnncl(ima_fname,mat_fname);
%
% Create (soft) average images for template
% and canonical brain. One of the images is
% quite different w.r.t. contrast compared
% to the others. Therefore I have choosen
% to perform a histogram-matching of all
% to the first (arbitratily chosen as
% rat_plain5).
%
%image canonique
cP = ['/d1/data/Petra/rat5/canonical_T2.img';...
'/d1/data/Petra/LFF4/canonical_T2.img';...
'/d1/data/Petra/rat3/canonical_T2.img';...
'/d1/data/Petra/rat4/canonical_T2.img';...
'/d1/data/Petra/rat6/canonical_T2.img'];
cP = spm_vol(cP);%on recup un vecteur de structures
cdata = spm_read_vols(cP);% cdata de la forme [ Y, XYZ], on aura en sortie(matrice 4D des données d'image)???
for i=1:length(cP)% pour chaque structure de cP
maxval(i) = max(max(max(cdata(:,:,:,i)))); %on prends le max sur cdata
cdata(:,:,:,i) = cdata(:,:,:,i) / maxval(i);% on normalise Cdata, dc la plus grande valeur pour chaque I sera 1
end
tmp = [];
%
for i=1:size(cdata,3)
tmp = [tmp cdata(:,:,i,1)];
end
nhist = hist(tmp(:),512); %retourne un vecteur de 10 cases à égal distance contenant les 512 éléments
hedata = zeros(size(cdata)); %matrice de zéros de la taille de Cdata
hedata(:,:,:,1) = cdata(:,:,:,1);
for i=2:5
tmp = [];
for j=1:size(cdata,3)
tmp = [tmp cdata(:,:,j,i)];
end
tmp = histeq(tmp,nhist);%contient les intensités modifiées ac les nhist degrés
for j=1:size(cdata,3)
hedata(:,:,j,i) = tmp(:,(j-1)*size(cdata,2)+1:j*size(cdata,2));%????
end
end
%
% And now create soft average
%
ssum = sum(hedata,4);%la somme des intensités
nn = sum(cdata>0,4); %la somme des voxels
s_ave = maxval(1)*ssum./nn; % la moyenne ??? pk multiplier par maxval(1)???
%
% Write this to template directory.
%
%on genère l'image canonique
oP.fname = '/d1/data/Petra/template/canonical_T2.img';
oP.dim = cP(1).dim;
oP.mat = cP(1).mat;
oP.pinfo = cP(1).pinfo;
oP.descrip = 'Canonical (5 rats) T2 Rat Brain in Paxonos Space';
oP = spm_write_vol(oP,s_ave);
%
% Do the same for the template
%
%template
tP = ['/d1/data/Petra/rat5/template_T2.img';...
'/d1/data/Petra/LFF4/template_T2.img';...
'/d1/data/Petra/rat3/template_T2.img';...
'/d1/data/Petra/rat4/template_T2.img';...
'/d1/data/Petra/rat6/template_T2.img'];
tP = spm_vol(tP);
tdata = spm_read_vols(tP);
for i=1:length(tP)
maxval(i) = max(max(max(tdata(:,:,:,i))));
tdata(:,:,:,i) = tdata(:,:,:,i) / maxval(i);
end
tmp = [];
for i=1:size(tdata,3)
tmp = [tmp tdata(:,:,i,1)];
end
nhist = hist(tmp(:),512);
hedata = zeros(size(tdata));
hedata(:,:,:,1) = tdata(:,:,:,1);
for i=2:5
tmp = [];
for j=1:size(tdata,3)
tmp = [tmp tdata(:,:,j,i)];
end
tmp = histeq(tmp,nhist);
for j=1:size(tdata,3)
hedata(:,:,j,i) = tmp(:,(j-1)*size(tdata,2)+1:j*size(tdata,2));
end
end
%
% And now create soft average
%
ssum = sum(hedata,4);
nn = sum(tdata>0,4);
s_ave = maxval(1)*ssum./nn;
%
% Write this to template directory.
%
oP.fname = '/d1/data/Petra/template/template_T2.img';
oP.dim = cP(1).dim;
oP.mat = cP(1).mat;
oP.pinfo = cP(1).pinfo;
oP.descrip = 'Template (5 rats) T2 Rat Brain in Paxonos Space';
oP = spm_write_vol(oP,s_ave);
%
% Now, lets try and create a decent brainmask.img
% for the template.
%
path('/home/jesper/matlab/PhaseMaps',path);
P = spm_vol('/d1/data/Petra/template/template_T2.img'); %vecteur de structures contenant les infos sur l'image
f = spm_read_vols(P); %
%
% Simple thresholding
%
msk = double(f>10.0e8);%seuillage
%
% Embed it in larger volume to allow
% for dilate and erode operations.
%
tmp = zeros(100,83,108);
tmp(11:90,11:73,:) = msk;
figure('Position',[050 050 800 800])
for i=1:100
subplot(10,10,i);
imagesc(tmp(:,:,i)>0.1);
axis('image'); axis off;
end
%
% Find largest connected component.
%%on cherche la plus grande composante connexe
[cctmp,crap] = flood_fill(zeros(size(tmp(:))),-tmp(:),size(tmp),...
zeros(size(tmp(:))),tmp(:),-0.5,round(size(tmp)./2));
%
% Smooth and threshold again.
%
spm_smooth(reshape(cctmp,size(tmp)),tmp,[4 4 4]);
cctmp = double(tmp(:) > 0.1);
%
% Next do a series of dilates followed by erodes
% to see if we can fill out the "holes" in the
% brain.
%
cctmp = dilate(cctmp,size(tmp));
cctmp = dilate(cctmp,size(tmp));
cctmp = dilate(cctmp,size(tmp));
cctmp = dilate(cctmp,size(tmp));
cctmp = erode(cctmp,size(tmp));
cctmp = erode(cctmp,size(tmp));
cctmp = erode(cctmp,size(tmp));
cctmp = erode(cctmp,size(tmp));
%
% Then dilate a little bit extra to make sure
% we have some margin around the brain.
%
cctmp = dilate(cctmp,size(tmp));
cctmp = dilate(cctmp,size(tmp));
%
% Smooth a little bit so that it is not
% all-or-nothing.
%
spm_smooth(reshape(cctmp,size(tmp)),tmp,[3 3 3]);
cctmp = tmp;
%
% Finally cut out relevant section
%
msk = cctmp(11:90,11:73,:);
oP.fname = '/d1/data/Petra/template/brainmask.img';
oP.dim = [dim P.dim(4)];
oP.mat = M2;
oP.pinfo = P.pinfo;
oP.descrip = 'T2 Rat Brain-mask in Paxonos Space';
oP = spm_write_vol(oP,msk);
%
% I have checked this brainmask, and it looks good.
% Jesper 14/6-02.
%
%
% Here I will shift the y- and z-axis such that
% the aspects of the different views are more
% like that of the human brain. This will mean
% that we can use the space in the SPM graphics
% window in a much more "economic way".
%
%
% Canonical
%
P = spm_vol('/d1/data/Petra/template/canonical_T2.img');
f = spm_read_vols(P);
of = zeros(size(f,1),size(f,3),size(f,2));
for i=1:size(f,1)
of(i,:,:) = squeeze(f(i,:,:))';
end
oP = P;
tmp = oP.dim(2);
oP.dim(2) = oP.dim(3);
oP.dim(3) = tmp;
tmp = oP.mat(2,4);
oP.mat(2,4) = oP.mat(3,4);
oP.mat(3,4) = tmp;
spm_write_vol(oP,of);
%
% Template
%
P = spm_vol('/d1/data/Petra/template/template_T2.img');
f = spm_read_vols(P);
of = zeros(size(f,1),size(f,3),size(f,2));
for i=1:size(f,1)
of(i,:,:) = squeeze(f(i,:,:))';
end
oP = P;
tmp = oP.dim(2);
oP.dim(2) = oP.dim(3);
oP.dim(3) = tmp;
tmp = oP.mat(2,4);
oP.mat(2,4) = oP.mat(3,4);
oP.mat(3,4) = tmp;
spm_write_vol(oP,of);
%
% Brainmask
%
P = spm_vol('/d1/data/Petra/template/brainmask.img');
f = spm_read_vols(P);
of = zeros(size(f,1),size(f,3),size(f,2));
for i=1:size(f,1)
of(i,:,:) = squeeze(f(i,:,:))';
end
oP = P;
tmp = oP.dim(2);
oP.dim(2) = oP.dim(3);
oP.dim(3) = tmp;
tmp = oP.mat(2,4);
oP.mat(2,4) = oP.mat(3,4);
oP.mat(3,4) = tmp;
spm_write_vol(oP,of);
%
% Here starts code pertaining to step 3,
% the creation of an "outer Paxinos contour".
%
axial = imread('/d1/data/Petra/rat_axial.jpg');
sagittal = imread('/d1/data/Petra/rat_sagittal.jpg');
coronal = imread('/d1/data/Petra/Petra.jpg');
%
% It seems that the "coronal" image has been created in a
% different way from the other two. Its matrix size is
% considerably larger, 9360x6800 compared to e.g. 494x715
% for the axial. We will therefor start out by down-sampling
% it.
%
coronal = coronal(1:5:end,1:5:end);
paxinos(1).ima = axial;
paxinos(1).slice = 'axial';
paxinos(1).bregma_level = -3.80;
paxinos(1).ia_level = 5.20;
paxinos(2).ima = sagittal;
paxinos(2).slice = 'sagittal';
paxinos(2).lateral_level = 0.40;
paxinos(3).ima = coronal;
paxinos(3).slice = 'coronal';
paxinos(3).bregma_level = -3.60;
paxinos(3).ia_level = 6.40;
clear axial sagittal coronal;
%
% What we need to do, for each image, is to create a train
% of polygons for the outer contour. This train should
% ideally be in "Paxonos co-ordinates", i.e. we need to
% establish an x and y scalefactor for each image, and
% also calibrate the zero-point.
%
figure('Position',[050 100 1.5*700 1.5*500])
imagesc(paxinos(1).ima); axis('image');
%
% First trace left y-axis from bottom to top.
%
[paxinos(1).lyax.x,paxinos(1).lyax.y] = ginput(12);
%
% Bottom x-axis from left to right.
%
[paxinos(1).bxax.x,paxinos(1).bxax.y] = ginput(17);
%
% And brain contour.
%
[paxinos(1).bc.x,paxinos(1).bc.y] = ginput;
save /d1/data/Petra/paxinos_cont.mat paxinos
%
% Find geometrical calibration (in LS sense)
% for axial slice.
%
X = [ones(17,1) paxinos(1).bxax.x];
y = [-8:8]';
b = pinv(X)*y;
paxinos(1).xb = b;
X = [ones(12,1) paxinos(1).lyax.y];
y = [-11:0]';
b = pinv(X)*y;
paxinos(1).yb = b;
paxinos(1).bc_calib.x = [ones(length(paxinos(1).bc.x),1) paxinos(1).bc.x] *...
paxinos(1).xb;
paxinos(1).bc_calib.y = [ones(length(paxinos(1).bc.y),1) paxinos(1).bc.y] *...
paxinos(1).yb;
%
% Sagittal
%
figure('Position',[050 100 5*220 5*160])
imagesc(paxinos(2).ima); axis('image');
%
% First trace left y-axis from bottom to top.
%
[paxinos(2).lyax.x,paxinos(2).lyax.y] = ginput(14);
%
% Bottom x-axis from left to right.
%
[paxinos(2).bxax.x,paxinos(2).bxax.y] = ginput(23);
%
% And brain contour.
%
[paxinos(2).bc.x,paxinos(2).bc.y] = ginput;
save /d1/data/Petra/paxinos_cont.mat paxinos
%
% Find geometrical calibration (in LS sense)
% for axial slice.
%
X = [ones(23,1) paxinos(2).bxax.x];
y = [6:-1:-16]';
b = pinv(X)*y;
paxinos(2).xb = b;
X = [ones(14,1) paxinos(2).lyax.y];
y = [-12:1]';
b = pinv(X)*y;
paxinos(2).yb = b;
paxinos(2).bc_calib.x = [ones(length(paxinos(2).bc.x),1) paxinos(2).bc.x] *...
paxinos(2).xb;
paxinos(2).bc_calib.y = [ones(length(paxinos(2).bc.y),1) paxinos(2).bc.y] *...
paxinos(2).yb;
%
% Coronal
%
figure('Position',[050 100 5*220 5*130])
imagesc(rot90(paxinos(3).ima)); axis('image');
%
% First trace left y-axis from bottom to top.
%
[paxinos(3).lyax.x,paxinos(3).lyax.y] = ginput(9);
[tmpx,tmpy] = ginput(8);
paxinos(3).lyax.x = [paxinos(3).lyax.x; tmpx];
paxinos(3).lyax.y = [paxinos(3).lyax.y; tmpy];
%
% Bottom x-axis from left to right.
%
[paxinos(3).bxax.x,paxinos(3).bxax.y] = ginput(12);
[tmpx,tmpy] = ginput(10);
paxinos(3).bxax.x = [paxinos(3).bxax.x; tmpx];
paxinos(3).bxax.y = [paxinos(3).bxax.y; tmpy];
%
% And brain contour.
%
[paxinos(3).bc.x,paxinos(3).bc.y] = ginput;
save /d1/data/Petra/paxinos_cont.mat paxinos
%
% Find geometrical calibration (in LS sense)
% for Coronal slice. There is a tiny bit of
% rotation on the scanned Coronal image, but
% I judge that as insignificant.
%
X = [ones(22,1) paxinos(3).bxax.x];
y = [6:-1:-15]';
b = pinv(X)*y;
paxinos(3).xb = b;
X = [ones(17,1) paxinos(3).lyax.y];
y = [-8:8]';
b = pinv(X)*y;
paxinos(3).yb = b;
paxinos(3).bc_calib.x = [ones(length(paxinos(3).bc.x),1) paxinos(3).bc.x] *...
paxinos(3).xb;
paxinos(3).bc_calib.y = [ones(length(paxinos(3).bc.y),1) paxinos(3).bc.y] *...
paxinos(3).yb;
save /d1/data/Petra/paxinos_cont.mat paxinos
%
% Now, lets try and create our own mip.mat
%
% It should be of size 400 wide and 364 high.
% Sagittal slice should be at coordinates (from upper left corner)
% ul=[6 26], lr=[225 155]
% Coronal
% ul=[6 180], lr=[225 340]
% Transversal
% ul=[236 26], lr[395 155]
figure('Position',[050 100 400 364])
%
% Sagittal
%
sag = axes('Position',[5/400 (364-25-130)/364 220/400 130/364]);
plot(paxinos(2).bc_calib.x,paxinos(2).bc_calib.y,'k','LineWidth',.5);
axis([-16 6 -12 1]);
set(sag,'XTickLabel',{}); set(sag,'YTickLabel',{});
set(sag,'XTick',[-14 -12 -10 -8 -6 -4 -2 2 4]); set(sag,'XGrid','On');
set(sag,'YTick',[-10 -8 -6 -4 -2]); set(sag,'YGrid','On');
hold on;
plot([-16 6],[0 0],'k','LineWidth',.5); plot([0 0],[-12 1],'k','LineWidth',.5);
hold off;
%
% Coronal
%
cor = axes('Position',[5/400 (364-25-130-24-160)/364 220/400 160/364]);
plot(paxinos(3).bc_calib.x,paxinos(3).bc_calib.y,'k','LineWidth',.5);
axis([-16 6 -8 8]);
set(cor,'XTickLabel',{}); set(cor,'YTickLabel',{});
set(cor,'XTick',[-14 -12 -10 -8 -6 -4 -2 2 4]); set(cor,'XGrid','On');
set(cor,'YTick',[-6 -4 -2 2 4 6]); set(cor,'YGrid','On');
hold on;
plot([-16 6],[0 0],'k','LineWidth',.5); plot([0 0],[-8 8],'k','LineWidth',.5);
hold off;
%
% Transversal
%
tra = axes('Position',[(5+220+10)/400 (364-25-130)/364 160/400 130/364]);
plot(paxinos(1).bc_calib.x,paxinos(1).bc_calib.y,'k','LineWidth',.5);
axis([-8 8 -12 1]);
set(tra,'XTickLabel',{}); set(tra,'YTickLabel',{});
set(tra,'XTick',[-6 -4 -2 2 4 6]); set(tra,'XGrid','On');
set(tra,'YTick',[-10 -8 -6 -4 -2]); set(tra,'YGrid','On');
hold on;
plot([-8 8],[0 0],'k','LineWidth',.5); plot([0 0],[-12 1],'k','LineWidth',.5);
hold off;
%
% Save this as .bmp file, read it back as image
% subsample it and write it back as .mat file.
%
set(gcf,'PaperPositionMode','auto');
saveas(gcf,'/d1/data/Petra/test','bmp');
ima = imread('/d1/data/Petra/test.bmp');
ima = double(~(ima(:,:,1)>0 | ima(:,:,2)>0 | ima(:,:,3)>0));
mip = zeros(364,400);
for i=1:364
for j=1:400
mip(i,j) = max(max(ima((i-1)*2+1:i*2,(j-1)*2+1:j*2)));
end
end
mip96 = rot90(mip,-1); % Compatible with MIP.mat
save /d1/data/Petra/MIP.mat mip96
%
% Now, determine suitable defaults for spatial normalisation
% (in spm_defaults) that would hopefully enable us to
% spatially normalise most scans without having to set
% origins and stuff manually for each rat.
% Notably, the zooming by a factor of 10 (remember, we
% work in tens of mm) and the swap of the y- and
% z-axes should be included in the defaults.
%
% Hence, the rotation (Pitch -pi/2 radians) and the
% zooms (10 10 -10) should be generally useful
% regardles of how the rat was positioned.
%
% In addition, the specific rat I have been working on
% was centered (in the up-down direction) in something
% which I suspect is the oesephagus. That is quite far
% away from the Bregma, so I will add an offset to
% compensate for that. This offset (115 tenths of mm)
% might be less general than the zooms and the rotation
% though (being specific to the positioning).
%
% Furthermore, in the nose-tail direction it has been
% centered on the "middle of the brain", which is a fair
% bit behind the Bregma. Hence I have added an offset
% also in that direction.
%
P = spm_vol('/d1/data/Petra/test.img');
f = spm_read_vols(P);
M = spm_matrix([0 -40 -115 -pi/2 0 0 10 10 -10]);
oP = P;
oP.mat = M*oP.mat;
spm_write_vol(oP,f);
%
% The numbers above look fine, and will be used
% in spm_defaults.m for rats.
% |
Partager