admin 发表于 2022-5-14 12:43:53

计算图像的局部二值模式特征LBP


function [ Vout ] = CalcImgLBPFeature( Iin )
% Calc image Local Binary Pattern( LBP ) feature
%
% < Input arguments >
% 'Iin' - input image( 'uint8' | 'uint16' | 'double' format )
%
% < Output arguments >
% 'Vout' - feature vector

% init return value ...
Vout = [];

% gray color image ...
if ( ndims( Iin ) == 3 )
Ig = ( 0.3 .* Iin( :, :, 1 ) + 0.59 .* Iin( :, :, 2 ) + 0.11 .* Iin( :, :, 3 ) );
else
Ig = Iin;
end;

% '3 x 3' neigbourhood 'sliding' operation ...
M = colfilt( Ig, [ 3 3 ], 'sliding', @CalcTextureUnit );

% create histogram ...
[ Vout ] = CalcHistogram( M, 256 );

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                           Sub Function                              %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [ Lt ] = CalcTextureUnit( Mt )
% Compute the texture unit for ONE pixel ...
%
% < Input arguments >
% 'Mt' - neigbourhood block value
%
% < Output arguments >
% 'Lt' - neigbourhood 'sliding' operation result value

% '3 x 3' template value(s) ...
Ve = [ 1 8 32 2 0 64 4 16 128 ];
   
% compute the threshold value, which is the mean value ...
Lt = mean( Mt, 1 );
   
% duplicate ...
Mc = repmat( Lt, size( Mt, 1 ), 1 );

% compute by threshold value ...
K = ( Mt > Mc );

% return result ...
Lt = Ve * K;
页: [1]
查看完整版本: 计算图像的局部二值模式特征LBP