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

vb_image_to_mask

PURPOSE ^

make mask-image by thresholding

SYNOPSIS ^

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

DESCRIPTION ^

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

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