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

vb_face_extract_trial

PURPOSE ^

Morfology operation for face extraction

SYNOPSIS ^

function [B, F, V, Vmiss, Fmiss] = vb_face_extract_trial(imagefile,Para)

DESCRIPTION ^

 Morfology operation for face extraction
  [B, F, V] = vb_face_extract_trial(imagefile,Para)
 MRI構造画像から顔表面画像の抽出する最適パラメタを試す

 job_mode  = -1;    % stop after making binary mask by thresholding
 job_mode  = 0;    % stop after morphology
 job_mode  = 1;    % stop after face extraction
                     % extraction disconnected surface other than face
 job_mode  = 2;    % make mask data for face (closed surface)

 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, F, V, Vmiss, Fmiss] = vb_face_extract_trial(imagefile,Para)
0002 % Morfology operation for face extraction
0003 %  [B, F, V] = vb_face_extract_trial(imagefile,Para)
0004 % MRI構造画像から顔表面画像の抽出する最適パラメタを試す
0005 %
0006 % job_mode  = -1;    % stop after making binary mask by thresholding
0007 % job_mode  = 0;    % stop after morphology
0008 % job_mode  = 1;    % stop after face extraction
0009 %                     % extraction disconnected surface other than face
0010 % job_mode  = 2;    % make mask data for face (closed surface)
0011 %
0012 % Copyright (C) 2011, ATR All Rights Reserved.
0013 % License : New BSD License(see VBMEG_LICENSE.txt)
0014 
0015 if ~exist('Para','var'), Para.job_mode = 1; end;
0016 
0017 if ~isfield(Para,'job_mode'), 
0018     job_mode = 1;
0019 else
0020     job_mode = Para.job_mode ;
0021 end;
0022 if ~isfield(Para,'plot_mode'), 
0023     plot_mode = 1;
0024 else
0025     plot_mode = Para.plot_mode ;
0026 end;
0027 if ~isfield(Para,'Radius'), 
0028     Radius = [ -2 2 ]; 
0029 else
0030     Radius = Para.Radius ;
0031 end;
0032 if ~isfield(Para,'step'), 
0033     step = 2; 
0034 else
0035     step = Para.step  ;
0036 end;
0037 if ~isfield(Para,'Bval'), 
0038     Bval = []; 
0039 else
0040     Bval = Para.Bval  ;
0041 end;
0042 if ~isfield(Para,'pmax'), 
0043     pmax = 0.998; 
0044     Bval = []; 
0045 else
0046     pmax = Para.pmax ;
0047     Bval = []; 
0048 end;
0049 if ~isfield(Para,'zmin'), 
0050     zmin = 10;
0051 else
0052     zmin = Para.zmin;
0053 end;
0054 
0055 if ~isfield(Para,'zindx'), 
0056     % スライス画像表示の Z-座標リスト
0057     zindx = [40:20:200];
0058 else
0059     zindx = Para.zindx;
0060 end;
0061 if ~isfield(Para,'Nfig'), 
0062     % subplot の 数
0063     Nfig  = [3, 3];
0064 else
0065     Nfig  = Para.Nfig ;
0066 end;
0067 if ~isfield(Para,'Msize'), 
0068     % Marker size
0069     Msize = 4;
0070 else
0071     Msize = Para.Msize;
0072 end;
0073 
0074 
0075 %
0076 % Load 3D MRI image to analyze_right_hand coordinate
0077 %
0078 [B, DIM] = vb_load_analyze_to_right(imagefile);
0079 
0080 % Calculate background noise threshold value
0081 % by estimating Rayleigh distribution which represent backgound noise
0082 
0083 if isempty(Bval)
0084     [Bval, Nhist, level] = vb_back_threshold(B,pmax,plot_mode);
0085 end
0086 
0087 if job_mode == -2, return; end;
0088 
0089 % 閾値より大きい値を持つボクセルを頭部として抽出
0090 % Make mask image from MRI data
0091 B = vb_image_to_mask(B, Bval, step, plot_mode, zindx, Nfig);
0092 
0093 if job_mode < 0, return; end;
0094 
0095 % Apply morphology operations
0096 % Dilation/erosion are done consecutively according to Radius
0097 B = vb_morphology_operation(B, Radius, step, plot_mode, zindx, Nfig);
0098 
0099 if job_mode == 0, return; end;
0100 
0101 % face extraction
0102 %  V  : 顔表面頂点        face vertex
0103 %  F  : その三角面パッチ  patch index
0104 
0105 [F, V, xx, Vmiss, Fmiss]  = vb_surf_extract(B, step);
0106 
0107 % 顔表示
0108 if plot_mode > 0,
0109     figure;
0110     vb_plot_surf(V,F,[0.8 0.7 0.6],'none',1);
0111     view([135, 15]);
0112 end
0113 
0114 Nmin  = 20;
0115 Vmax  = max(V);
0116 Vmin  = min(V);
0117 Nsurf = size(Vmiss,1);
0118 NX = 2; NY = 2;
0119 nfig = NX*NY;
0120 
0121 if plot_mode > 0,
0122     for n=1:Nsurf
0123         if size(Vmiss{n},1) < Nmin, continue; end;
0124         nfig = nfig+1;
0125         if nfig > NX*NY, figure; nfig = 1; end;
0126         subplot(NY,NX,nfig)
0127         vb_plot_surf(Vmiss{n},Fmiss{n},[0.8 0.7 0.6],'none',1);
0128         hold on
0129         xlim([Vmin(1) Vmax(1)]);
0130         ylim([Vmin(2) Vmax(2)]);
0131         zlim([Vmin(3) Vmax(3)]);
0132         view([135, 15]);
0133     end
0134 end
0135 
0136 if plot_mode == 2,
0137     % Histgram of MRI intensity
0138     figure;
0139     plot(level,Nhist);
0140     hold on
0141     plot([Bval Bval], [0 Nhist(round(Bval))*2], 'r-');
0142     title('Histgram of MRI intensity')
0143 
0144     % 元の画像に抽出した曲面を重ね合わせ
0145     [B, DIM] = vb_load_analyze_to_right(imagefile);
0146     vb_plot_slice( B, V, zindx, 1, Nfig, Msize);
0147 end
0148 
0149 if job_mode == 1, return; end;
0150 
0151 % Make mask image from face vertex
0152 %  B  : Mask image
0153 
0154 B = vb_face_to_mask(V,F,DIM,step,zmin,plot_mode,zindx);
0155 
0156 %%%%%%% Additional Plot
0157 
0158 if job_mode < 3, return; end;
0159

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