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

vb_surf_extract

PURPOSE ^

Extract boundary surface from mask image

SYNOPSIS ^

function [F, V, xx, Vmiss, Fmiss, Nmiss] = vb_surf_extract(B, step, Vorgin)

DESCRIPTION ^

 Extract boundary surface from mask image
   [F, V, xx]  = vb_surf_extract(B)
   [F, V, xx]  = vb_surf_extract(B, step)
   [F, V, xx]  = vb_surf_extract(B, step, Vorgin)
 ---
 [IN]  B         : mri Image data
 --- Optional
 [IN]  step      : subsampling step size [mm] (= 0)
 [IN]  Vorgin    : coordinate of origin  [mm] (= [0, 0, 0])

 [OUT] V         : surface vertex
 [OUT] F         : triangle patch index
 [OUT] xx        : normal unit vector of surface

   マスクパターンから境界表面の抽出

 Made by M. Sato 2004-3-28
 Modified by M. Sato 2007-3-16

 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 [F, V, xx, Vmiss, Fmiss, Nmiss]  = vb_surf_extract(B, step, Vorgin)
0002 % Extract boundary surface from mask image
0003 %   [F, V, xx]  = vb_surf_extract(B)
0004 %   [F, V, xx]  = vb_surf_extract(B, step)
0005 %   [F, V, xx]  = vb_surf_extract(B, step, Vorgin)
0006 % ---
0007 % [IN]  B         : mri Image data
0008 % --- Optional
0009 % [IN]  step      : subsampling step size [mm] (= 0)
0010 % [IN]  Vorgin    : coordinate of origin  [mm] (= [0, 0, 0])
0011 %
0012 % [OUT] V         : surface vertex
0013 % [OUT] F         : triangle patch index
0014 % [OUT] xx        : normal unit vector of surface
0015 %
0016 %   マスクパターンから境界表面の抽出
0017 %
0018 % Made by M. Sato 2004-3-28
0019 % Modified by M. Sato 2007-3-16
0020 %
0021 % Copyright (C) 2011, ATR All Rights Reserved.
0022 % License : New BSD License(see VBMEG_LICENSE.txt)
0023 
0024 if ~exist('Vorgin','var'), Vorgin = [0, 0, 0]; end;
0025 if ~exist('step','var'), step = 1; end;
0026 
0027 %
0028 %-------- 境界面抽出 --------
0029 %
0030 
0031 % 3次元データの平滑化
0032 tic
0033 fprintf('smoothing\n')
0034 B = smooth3(B,'gaussian',3);
0035 vb_ptime(toc);
0036 
0037 % 等価強度サーフェスの抽出
0038 tic
0039 fprintf('surface extraction\n')
0040 Val = 0.5;
0041 [F,V] = isosurface(B,Val);
0042 vb_ptime(toc);
0043 
0044 % exchange x-y coordinate
0045 x      = V(:,1);
0046 V(:,1) = V(:,2);
0047 V(:,2) = x;
0048 
0049 % Scale back to original image
0050 NP = size(V,1);
0051 V  = V*step - step/2;
0052 V  = V + Vorgin(ones(NP,1),:);
0053 
0054 % connected surface extraction
0055 % V     : 連結している頂点
0056 % F     : その三角面パッチ
0057 % xx    : F の外向き法線
0058 tic
0059 fprintf('connected surface extraction\n')
0060 [Fall, Vall, Nall] = vb_separate_surf(F,V);
0061 F = Fall{1};
0062 V = Vall{1};
0063 
0064 % 法線方向を外向きに揃える
0065 [F, V, xx] = vb_out_normal(F,V);
0066 vb_ptime(toc)
0067 
0068 % # of disconnected vertex
0069 fprintf('# of connected vertex    = %d\n', Nall(1)) 
0070 
0071 % 閉局面のチェック: omega = 1
0072 omega  = vb_solid_angle_check(V,F);
0073 fprintf('Closed surface index (=1) : %f\n', omega)
0074 fprintf('# of disconnected vertex = %d\n', sum(Nall(2:end))) 
0075 
0076 if nargout < 4, return; end;
0077 
0078 Nsurf = size(Vall,1)-1;
0079 
0080 if Nsurf == 0, 
0081     Fmiss = [];
0082     Vmiss = [];
0083     Nmiss = 0;
0084     return; 
0085 end;
0086 
0087 Fmiss = cell(Nsurf,1);
0088 Vmiss = cell(Nsurf,1);
0089 Nmiss = zeros(Nsurf,1);
0090 
0091 for n=1:Nsurf
0092     Fmiss{n} = Fall{n+1};
0093     Vmiss{n} = Vall{n+1};
0094     Nmiss(n) = Nall(n+1);
0095 end
0096 
0097

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