Home > functions > leadfield > curry > vb_analyze2curry.m

vb_analyze2curry

PURPOSE ^

Convert analyzefile to Curry image file

SYNOPSIS ^

function vb_analyze2curry(analyzefile,outfile_pref,flag,flip_flag)

DESCRIPTION ^

 Convert analyzefile to Curry image file
 vb_analyze2curry(analyzefile,outfile_pref)
 vb_analyze2curry(analyzefile,outfile_pref,flag,flip_flag)

 AnalyzeデータをCurry用に変換
 ・入力:Analyzeスライス画像
   analyzefile
 ・出力:Curry用ファイル
   out_pref: 出力ファイル名
 ヘッダファイル [outfile_pref].imd と、
 画像データ     [outfile_pref].img が作成される。
 --- Optional input
 flag: 
 'header'を指定すると、imdファイルのみ作成する。

 flip_flag
  if flip_flag == 1, X-dir is flipped

 ・座標系
 スライスの向きはSagital
 [Curry] 
 X:Right(1)->Left(256)
 Y:Front(1)->Back(256)
 Z:Bottom(1)->Top(256)

 [Analyze Left-hand coordinate]
 X: Right(1)  -> Left(191) 
 Y: Back(1)   -> Front(256)
 Z: Bottom(1) -> Top(256) 
    B(x,:,:) : Sagital slice


 2004-01-31 Taku Yoshioka
 2007-06-20 M.Sato
 2009-12-21 rhayashi supported NIfTI format

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function vb_analyze2curry(analyzefile,outfile_pref,flag,flip_flag)
0002 % Convert analyzefile to Curry image file
0003 % vb_analyze2curry(analyzefile,outfile_pref)
0004 % vb_analyze2curry(analyzefile,outfile_pref,flag,flip_flag)
0005 %
0006 % AnalyzeデータをCurry用に変換
0007 % ・入力:Analyzeスライス画像
0008 %   analyzefile
0009 % ・出力:Curry用ファイル
0010 %   out_pref: 出力ファイル名
0011 % ヘッダファイル [outfile_pref].imd と、
0012 % 画像データ     [outfile_pref].img が作成される。
0013 % --- Optional input
0014 % flag:
0015 % 'header'を指定すると、imdファイルのみ作成する。
0016 %
0017 % flip_flag
0018 %  if flip_flag == 1, X-dir is flipped
0019 %
0020 % ・座標系
0021 % スライスの向きはSagital
0022 % [Curry]
0023 % X:Right(1)->Left(256)
0024 % Y:Front(1)->Back(256)
0025 % Z:Bottom(1)->Top(256)
0026 %
0027 % [Analyze Left-hand coordinate]
0028 % X: Right(1)  -> Left(191)
0029 % Y: Back(1)   -> Front(256)
0030 % Z: Bottom(1) -> Top(256)
0031 %    B(x,:,:) : Sagital slice
0032 %
0033 %
0034 % 2004-01-31 Taku Yoshioka
0035 % 2007-06-20 M.Sato
0036 % 2009-12-21 rhayashi supported NIfTI format
0037 %
0038 % Copyright (C) 2011, ATR All Rights Reserved.
0039 % License : New BSD License(see VBMEG_LICENSE.txt)
0040 
0041 if ~exist('flip_flag','var'), flip_flag = 0; end;
0042 
0043 % load data and reorient to LAS
0044 [B, Vdim, Vsize] = vb_load_analyze_to_left(analyzefile);
0045 
0046 v_max = max([B(:)]);
0047 %
0048 % ヘッダファイル作成
0049 %
0050 fprintf('--- Create header file\n');
0051 
0052 %    SLICE_DISTANCE    = 1.000000
0053 %    SLICE_NR    = 179
0054 %    SLICE_VALID    = 179
0055 %    SLICE_NR1ST    = 1
0056 %    RAW_IMAGE_FORMAT    = 2
0057 %    RAW_NUMBER_OF_BITS    = 16
0058 %    RAW_MOST_SIGN_BIT    = 15
0059 %    RAW_OFFSET    = 0
0060 %    RAW_PIXEL_SIZE_X    = 1
0061 %    RAW_PIXEL_SIZE_Y    = 1
0062 %    RAW_SIZE_X    = 256
0063 %    RAW_SIZE_Y    = 256
0064 %    SLICE_ORDER    = 1
0065 
0066 fp = fopen([outfile_pref '.imd'],'w');
0067 fprintf(fp,'IMAGE_KEYWORDS START\n');
0068 fprintf(fp,'\tSLICE_DISTANCE\t= %f\n',Vsize(1));
0069 fprintf(fp,'\tSLICE_NR\t= %d\n',Vdim(1));
0070 fprintf(fp,'\tSLICE_VALID\t= %d\n',Vdim(1));
0071 fprintf(fp,'\tSLICE_NR1ST\t= 1\n');
0072 fprintf(fp,'\tRAW_IMAGE_FORMAT\t= 2\n');
0073 fprintf(fp,'\tRAW_NUMBER_OF_BITS\t= 16\n');
0074 fprintf(fp,'\tRAW_MOST_SIGN_BIT\t= 15\n');
0075 fprintf(fp,'\tRAW_OFFSET\t= 0\n');
0076 fprintf(fp,'\tRAW_PIXEL_SIZE_X\t= %d\n',Vsize(2));
0077 fprintf(fp,'\tRAW_PIXEL_SIZE_Y\t= %d\n',Vsize(3));
0078 fprintf(fp,'\tRAW_SIZE_X\t= %d\n',Vdim(2));
0079 fprintf(fp,'\tRAW_SIZE_Y\t= %d\n',Vdim(3));
0080 fprintf(fp,'\tSLICE_ORDER\t= 1\n');
0081 fprintf(fp,'IMAGE_KEYWORDS END');
0082 fclose(fp);
0083 
0084 %
0085 % DICOMイメージを読み込み、まとめてファイルに保存
0086 %
0087 if nargin >= 3 & strcmp(flag,'header')
0088   return;
0089 else
0090   fprintf(['--- Save image data (' outfile_pref '.img)\n']);
0091 
0092   Z = 65535/v_max;
0093   fp = fopen([outfile_pref '.img'],'w');
0094   
0095   img = zeros(Vdim(2),Vdim(3));
0096   
0097 %  向きと順序が異なる時の修正
0098 %  for n=Vdim(1):-1:1   % X flip
0099 %    img = flipud(img); % Y flip
0100 %    img = fliplr(img); % Z flip
0101 %    img = img';        % Y<->Z
0102 
0103   % 画像データの書き込み
0104   if flip_flag == 0,
0105       xlist = 1:Vdim(1);    % X : no flip
0106   else
0107       xlist = Vdim(1):-1:1; % X flip
0108   end
0109   
0110   for n=xlist
0111     img = squeeze(B(n,:,:));
0112     img = flipud(img); % Y flip
0113     img = fliplr(img); % Z flip
0114       fwrite(fp, img(:).*Z ,'uint16');
0115   end
0116   
0117 
0118   fclose(fp);
0119 end
0120

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005