Home > vbmeg > functions > common > morphology > vb_image_to_mask2.m

vb_image_to_mask2

PURPOSE ^

make mask-image by thresholding

SYNOPSIS ^

function B = vb_image_to_mask2(B, Bval, step, Vsize, plot_mode, zindx, Nfig)

DESCRIPTION ^

 make mask-image by thresholding
     B = vb_image_to_mask2(B)
     B = vb_image_to_mask2(B, Bval)
     B = vb_image_to_mask2(B, Bval, step)
     B = vb_image_to_mask2(B, Bval, step, Vsize)
 --- input
  B         : mri Image data
  step      : subsampling step size [mm]  Default: [1]
  Bval      : Threshold value for binary mask ,Default: [0.5]
   = scalar    : extract voxcel B > Bval
   = [BV1 BV2] : extract voxcel BV1 < B < BV2
 Vsize      : voxcel size [1 x 3] ,Default: [1 1 1]
 --- Optional input
  plot_mode : Plot slice image.(0-2 : No,  3 : Yes)
  zindx     : スライス画像表示の Z-座標リスト
  Nfig      : number of subplot
 --- output
  B         : masked image

 MRI構造画像からマスクパターンの作成

 M. Sato 2006-9-13

 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 B = vb_image_to_mask2(B, Bval, step, Vsize, plot_mode, zindx, Nfig)
0002 % make mask-image by thresholding
0003 %     B = vb_image_to_mask2(B)
0004 %     B = vb_image_to_mask2(B, Bval)
0005 %     B = vb_image_to_mask2(B, Bval, step)
0006 %     B = vb_image_to_mask2(B, Bval, step, Vsize)
0007 % --- input
0008 %  B         : mri Image data
0009 %  step      : subsampling step size [mm]  Default: [1]
0010 %  Bval      : Threshold value for binary mask ,Default: [0.5]
0011 %   = scalar    : extract voxcel B > Bval
0012 %   = [BV1 BV2] : extract voxcel BV1 < B < BV2
0013 % Vsize      : voxcel size [1 x 3] ,Default: [1 1 1]
0014 % --- Optional input
0015 %  plot_mode : Plot slice image.(0-2 : No,  3 : Yes)
0016 %  zindx     : スライス画像表示の Z-座標リスト
0017 %  Nfig      : number of subplot
0018 % --- output
0019 %  B         : masked image
0020 %
0021 % MRI構造画像からマスクパターンの作成
0022 %
0023 % M. Sato 2006-9-13
0024 %
0025 % Copyright (C) 2011, ATR All Rights Reserved.
0026 % License : New BSD License(see VBMEG_LICENSE.txt)
0027 
0028 if ~exist('step','var'), step = 1; end;
0029 if ~exist('Vsize','var'), Vsize = [1 1 1]; end;
0030 if ~exist('Bval','var'), Bval = 0.5; end;
0031 
0032 %-------- マスクパターンの作成 --------
0033 
0034 % Size of original image data
0035 [NX,NY,NZ] = size(B);
0036 
0037 ix = round(1:(step/Vsize(1)):NX);
0038 iy = round(1:(step/Vsize(2)):NY);
0039 iz = round(1:(step/Vsize(3)):NZ);
0040 
0041 % データの間引き
0042 % subsampling
0043 B = B(ix,iy,iz);
0044 
0045 % Size of subsampled image data
0046 [NBx,NBy,NBz]=size(B);
0047 
0048 % Make mask image
0049 
0050 Nval = length(Bval);
0051 
0052 switch    Nval
0053 case    1,
0054     % 閾値より大きい値を持つボクセルを抽出
0055     ix = find( B >= Bval );
0056     B  = zeros(NBx,NBy,NBz);
0057     B(ix) = 1;
0058 case    2,
0059     % 2つの閾値の間にある値を持つボクセルを抽出
0060     ix = find( (Bval(1) <= B) & (B <= Bval(2)) );
0061     B  = zeros(NBx,NBy,NBz);
0062     B(ix) = 1;
0063 end
0064 
0065 if  ~exist('plot_mode','var'), return; end;
0066 
0067 if  plot_mode > 1,
0068     % スライス画像表示の Z-座標リスト
0069     zindx = round(zindx/step);
0070 
0071     vb_plot_slice( B, [], zindx, 1, Nfig);
0072 end

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005