📄 avw_img_read.html
字号:
0278 0279 avw.img = zeros(PixelDim,SliceDim,RowDim);0280 0281 n = 1;0282 x = 1:PixelDim;0283 <span class="keyword">for</span> y = 1:SliceDim,0284 <span class="keyword">for</span> z = 1:RowDim,0285 <span class="comment">% load Z row of X values into Y slice avw.img</span>0286 avw.img(x,y,z) = tmp(n:n+(PixelDim-1));0287 n = n + PixelDim;0288 <span class="keyword">end</span>0289 <span class="keyword">end</span>0290 0291 <span class="comment">% rearrange avw.hdr.dime.dim or avw.hdr.dime.pixdim</span>0292 avw.hdr.dime.dim(2:4) = int16([PixelDim,SliceDim,RowDim]);0293 avw.hdr.dime.pixdim(2:4) = single([PixelSz,SliceSz,RowSz]);0294 0295 0296 <span class="keyword">case</span> 2, <span class="comment">% sagittal unflipped</span>0297 0298 <span class="comment">% orient = 2: The primary orientation of the data on disk is in the sagittal</span>0299 <span class="comment">% plane relative to the object scanned. Most commonly, the fastest moving</span>0300 <span class="comment">% index through the voxels that are part of this sagittal image would span the</span>0301 <span class="comment">% posterior-anterior extent of the structure imaged, with the next fastest</span>0302 <span class="comment">% moving index spanning the inferior-superior extent of the structure. This</span>0303 <span class="comment">% 'orient' flag would indicate to Analyze that this data should be placed in</span>0304 <span class="comment">% the Y-Z plane of the 3D Analyze Coordinate System, with the X dimension</span>0305 <span class="comment">% being the slice direction.</span>0306 0307 <span class="comment">% For the 'sagittal unflipped' type, the voxels are stored with</span>0308 <span class="comment">% Pixels in 'y' axis (varies fastest) - from patient posterior to anterior</span>0309 <span class="comment">% Rows in 'z' axis - from patient inferior to superior</span>0310 <span class="comment">% Slices in 'x' axis - from patient right to left</span>0311 0312 fprintf(<span class="string">'...reading sagittal unflipped orientation\n'</span>);0313 0314 avw.img = zeros(SliceDim,PixelDim,RowDim);0315 0316 n = 1;0317 y = 1:PixelDim; <span class="comment">% posterior to anterior (fastest)</span>0318 0319 <span class="keyword">for</span> x = 1:SliceDim, <span class="comment">% right to left (slowest)</span>0320 <span class="keyword">for</span> z = 1:RowDim, <span class="comment">% inferior to superior</span>0321 0322 <span class="comment">% load Z row of Y values into X slice avw.img</span>0323 avw.img(x,y,z) = tmp(n:n+(PixelDim-1));0324 n = n + PixelDim;0325 <span class="keyword">end</span>0326 <span class="keyword">end</span>0327 0328 <span class="comment">% rearrange avw.hdr.dime.dim or avw.hdr.dime.pixdim</span>0329 avw.hdr.dime.dim(2:4) = int16([SliceDim,PixelDim,RowDim]);0330 avw.hdr.dime.pixdim(2:4) = single([SliceSz,PixelSz,RowSz]);0331 0332 0333 <span class="comment">%--------------------------------------------------------------------------------</span>0334 <span class="comment">% Orient values 3-5 have the second index reversed in order, essentially</span>0335 <span class="comment">% 'flipping' the images relative to what would most likely become the vertical</span>0336 <span class="comment">% axis of the displayed image.</span>0337 <span class="comment">%--------------------------------------------------------------------------------</span>0338 0339 <span class="keyword">case</span> 3, <span class="comment">% transverse/axial flipped</span>0340 0341 <span class="comment">% orient = 3: The primary orientation of the data on disk is in the</span>0342 <span class="comment">% transverse plane relative to the object scanned. Most commonly, the fastest</span>0343 <span class="comment">% moving index through the voxels that are part of this transverse image would</span>0344 <span class="comment">% span the right-left extent of the structure imaged, with the next fastest</span>0345 <span class="comment">% moving index spanning the *anterior-posterior* extent of the structure. This</span>0346 <span class="comment">% 'orient' flag would indicate to Analyze that this data should be placed in</span>0347 <span class="comment">% the X-Y plane of the 3D Analyze Coordinate System, with the Z dimension</span>0348 <span class="comment">% being the slice direction.</span>0349 0350 <span class="comment">% For the 'transverse flipped' type, the voxels are stored with</span>0351 <span class="comment">% Pixels in 'x' axis (varies fastest) - from patient right to Left</span>0352 <span class="comment">% Rows in 'y' axis - from patient anterior to Posterior *</span>0353 <span class="comment">% Slices in 'z' axis - from patient inferior to Superior</span>0354 0355 fprintf(<span class="string">'...reading axial flipped (+Y from Anterior to Posterior)\n'</span>);0356 0357 avw.img = zeros(PixelDim,RowDim,SliceDim);0358 0359 n = 1;0360 x = 1:PixelDim;0361 <span class="keyword">for</span> z = 1:SliceDim,0362 <span class="keyword">for</span> y = RowDim:-1:1, <span class="comment">% flip in Y, read A2P file into P2A 3D matrix</span>0363 0364 <span class="comment">% load a flipped Y row of X values into Z slice avw.img</span>0365 avw.img(x,y,z) = tmp(n:n+(PixelDim-1));0366 n = n + PixelDim;0367 <span class="keyword">end</span>0368 <span class="keyword">end</span>0369 0370 <span class="comment">% no need to rearrange avw.hdr.dime.dim or avw.hdr.dime.pixdim</span>0371 0372 0373 <span class="keyword">case</span> 4, <span class="comment">% coronal flipped</span>0374 0375 <span class="comment">% orient = 4: The primary orientation of the data on disk is in the coronal</span>0376 <span class="comment">% plane relative to the object scanned. Most commonly, the fastest moving</span>0377 <span class="comment">% index through the voxels that are part of this coronal image would span the</span>0378 <span class="comment">% right-left extent of the structure imaged, with the next fastest moving</span>0379 <span class="comment">% index spanning the *superior-inferior* extent of the structure. This 'orient'</span>0380 <span class="comment">% flag would indicate to Analyze that this data should be placed in the X-Z</span>0381 <span class="comment">% plane of the 3D Analyze Coordinate System, with the Y dimension being the</span>0382 <span class="comment">% slice direction.</span>0383 0384 <span class="comment">% For the 'coronal flipped' type, the voxels are stored with</span>0385 <span class="comment">% Pixels in 'x' axis (varies fastest) - from patient right to Left</span>0386 <span class="comment">% Rows in 'z' axis - from patient superior to Inferior*</span>0387 <span class="comment">% Slices in 'y' axis - from patient posterior to Anterior</span>0388 0389 fprintf(<span class="string">'...reading coronal flipped (+Z from Superior to Inferior)\n'</span>);0390 0391 avw.img = zeros(PixelDim,SliceDim,RowDim);0392 0393 n = 1;0394 x = 1:PixelDim;0395 <span class="keyword">for</span> y = 1:SliceDim,0396 <span class="keyword">for</span> z = RowDim:-1:1, <span class="comment">% flip in Z, read S2I file into I2S 3D matrix</span>0397 0398 <span class="comment">% load a flipped Z row of X values into Y slice avw.img</span>0399 avw.img(x,y,z) = tmp(n:n+(PixelDim-1));0400 n = n + PixelDim;0401 <span class="keyword">end</span>0402 <span class="keyword">end</span>0403 0404 <span class="comment">% rearrange avw.hdr.dime.dim or avw.hdr.dime.pixdim</span>0405 avw.hdr.dime.dim(2:4) = int16([PixelDim,SliceDim,RowDim]);0406 avw.hdr.dime.pixdim(2:4) = single([PixelSz,SliceSz,RowSz]);0407 0408 0409 <span class="keyword">case</span> 5, <span class="comment">% sagittal flipped</span>0410 0411 <span class="comment">% orient = 5: The primary orientation of the data on disk is in the sagittal</span>0412 <span class="comment">% plane relative to the object scanned. Most commonly, the fastest moving</span>0413 <span class="comment">% index through the voxels that are part of this sagittal image would span the</span>0414 <span class="comment">% posterior-anterior extent of the structure imaged, with the next fastest</span>0415 <span class="comment">% moving index spanning the *superior-inferior* extent of the structure. This</span>0416 <span class="comment">% 'orient' flag would indicate to Analyze that this data should be placed in</span>0417 <span class="comment">% the Y-Z plane of the 3D Analyze Coordinate System, with the X dimension</span>0418 <span class="comment">% being the slice direction.</span>0419 0420 <span class="comment">% For the 'sagittal flipped' type, the voxels are stored with</span>0421 <span class="comment">% Pixels in 'y' axis (varies fastest) - from patient posterior to Anterior</span>0422 <span class="comment">% Rows in 'z' axis - from patient superior to Inferior*</span>0423 <span class="comment">% Slices in 'x' axis - from patient right to Left</span>0424 0425 fprintf(<span class="string">'...reading sagittal flipped (+Z from Superior to Inferior)\n'</span>);0426 0427 avw.img = zeros(SliceDim,PixelDim,RowDim);0428 0429 n = 1;0430 y = 1:PixelDim;0431 0432 <span class="keyword">for</span> x = 1:SliceDim,0433 <span class="keyword">for</span> z = RowDim:-1:1, <span class="comment">% flip in Z, read S2I file into I2S 3D matrix</span>0434 0435 <span class="comment">% load a flipped Z row of Y values into X slice avw.img</span>0436 avw.img(x,y,z) = tmp(n:n+(PixelDim-1));0437 n = n + PixelDim;0438 <span class="keyword">end</span>0439 <span class="keyword">end</span>0440 0441 <span class="comment">% rearrange avw.hdr.dime.dim or avw.hdr.dime.pixdim</span>0442 avw.hdr.dime.dim(2:4) = int16([SliceDim,PixelDim,RowDim]);0443 avw.hdr.dime.pixdim(2:4) = single([SliceSz,PixelSz,RowSz]);0444 0445 <span class="keyword">otherwise</span>0446 0447 error(<span class="string">'unknown value in avw.hdr.hist.orient, try explicit IMGorient option.'</span>);0448 0449 <span class="keyword">end</span>0450 0451 t=toc; fprintf(<span class="string">'...done (%5.2f sec).\n\n'</span>,t);0452 0453 <span class="keyword">return</span>0454 0455 0456 0457 0458 <span class="comment">% This function attempts to read the orientation of the</span>0459 <span class="comment">% Analyze file according to the hdr.hist.orient field of the</span>0460 <span class="comment">% header. Unfortunately, this field is optional and not</span>0461 <span class="comment">% all programs will set it correctly, so there is no guarantee,</span>0462 <span class="comment">% that the data loaded will be correctly oriented. If necessary,</span>0463 <span class="comment">% experiment with the 'orient' option to read the .img</span>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -