旋转不变LBP特征-matlab

该博客介绍了如何在Matlab中实现旋转不变的局部二值模式(LBP)特征。通过不断旋转圆形邻域内的LBP特征,选取最小值作为中心像素的LBP特征值。提供了matlab源码及效果图。
摘要由CSDN通过智能技术生成

不断的旋转圆形邻域内的LBP特征,根据选择得到一系列的LBP特征值,从这些LBP特征值选择LBP特征值最小的作为中心像素点的LBP特征。
这里写图片描述


matlab源码

function imglbp = getRotationInvariantLBPFeature(img, radius, neighbors)
    imgSize = size(img);
    if numel(imgSize) > 2
        imgG = rgb2gray(img);
    else
        imgG = img;
    end
    [rows, cols] = size(imgG);
    rows=int16(rows);
    cols=int16(cols);
    imglbp = uint8(zeros(rows-2*radius, cols-2*radius));

    for k=0:neighbors-1
%       计算采样点对于中心点坐标的偏移量rx,ry        
        rx = radius * cos(2.0 * pi * k / neighbors);
        ry = -radius * sin(2.0 * pi * k / neighbors);
%       对采样点偏移量分别进行上下取整        
        x1 = floor(rx);
        x2 = ceil(rx);
        y1 = floor(ry);
        y2 = ceil(ry);
%       将坐标偏移量映射到0-1之间        
        tx =
以下是MATLAB旋转不变LBP特征提取的代码: ```matlab function lbp_feat = rotation_invariant_lbp(img, radius, neighbors) % img: 输入的图像 % radius: LBP算子半径 % neighbors: LBP算子采样点数 % lbp_feat: LBP特征 if nargin < 3 neighbors = 8; end if nargin < 2 radius = 1; end % 获取图像尺寸 [rows, cols] = size(img); % 初始化LBP特征lbp_feat_map = zeros(rows, cols); % 计算LBP特征图 for i = 1 : rows for j = 1 : cols lbp_feat_map(i,j) = get_lbp_pixel(img, i, j, radius, neighbors); end end % 计算旋转不变LBP特征 lbp_feat = zeros(1, 2^neighbors); for i = 0 : neighbors-1 % 将特征图沿着采样点方向旋转 lbp_feat_map_rotated = imrotate(lbp_feat_map, i*360/neighbors, 'nearest', 'crop'); % 计算LBP直方图 lbp_hist = histcounts(lbp_feat_map_rotated(:), 0:2^neighbors); % 更新LBP特征 lbp_feat = lbp_feat + lbp_hist; end % 归一化LBP特征 lbp_feat = lbp_feat / sum(lbp_feat); end function lbp_pixel = get_lbp_pixel(img, row, col, radius, neighbors) % img: 输入的图像 % row, col: 中心像素坐标 % radius: LBP算子半径 % neighbors: LBP算子采样点数 % lbp_pixel: LBP像素值 % 获取图像尺寸 [rows, cols] = size(img); % 初始化采样点坐标 sample_points = zeros(neighbors, 2); % 计算采样点坐标 for i = 1 : neighbors theta = 2*pi*(i-1)/neighbors; sample_points(i,1) = row + radius*cos(theta); sample_points(i,2) = col - radius*sin(theta); end % 处理采样点坐标越界的情况 sample_points(sample_points(:,1)<1 | sample_points(:,1)>rows | sample_points(:,2)<1 | sample_points(:,2)>cols, :) = []; % 计算LBP像素值 lbp_pixel = 0; for i = 1 : size(sample_points, 1) if img(round(sample_points(i,1)), round(sample_points(i,2))) >= img(row, col) lbp_pixel = lbp_pixel + 2^(i-1); end end end ``` 使用方法: ```matlab % 读取图像 img = imread('lena.png'); % 计算旋转不变LBP特征 lbp_feat = rotation_invariant_lbp(img, 1, 8); ```
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值