MATLAB中的局部二值模式 [英] Local Binary Pattern in MATLAB
问题描述
我正在尝试使用图像处理工具箱在MATLAB中执行本地二进制模式。当我执行时,我无法获得LBP图像和LBP直方图。
I am trying to execute local binary pattern in MATLAB using the image processing toolbox. When i execute I can't get a LBP image and LBP histogram.
clear all;
close all;
clc;
I=imread('test.png');
figure,imshow(I)
%% Crop
I2 = imcrop(I);
figure, imshow(I2)
w=size(I2,1);
h=size(I2,2);
%% LBP
scale = 2.^[7 6 5; 0 -inf 4; 1 2 3];
for i=2:w-1
for j=2:h-1
J0=I2(i,j);
I3(i-1,j-1)=I2(i-1,j-1)>J0;
I3(i-1,j)=I2(i-1,j)>J0;
I3(i-1,j+1)=I2(i-1,j+1)>J0;
I3(i,j+1)=I2(i,j+1)>J0;
I3(i+1,j+1)=I2(i+1,j+1)>J0;
I3(i+1,j)=I2(i+1,j)>J0;
I3(i+1,j-1)=I2(i+1,j-1)>J0;
I3(i,j-1)=I2(i,j-1)>J0;
LBP(i,j)=I3(i-1,j-1)*2^7+I3(i-1,j)*2^6+I3(i-1,j+1)*2^5+I3(i,j+1)*2^4+I3(i+1,j+1)*2^3+I3(i+1,j)*2^2+I3(i+1,j-1)*2^1+I3(i,j-1)*2^0;
end
end
figure,imshow(LBP)
figure,imhist(LBP)
问题是什么。我应该从0到255获取数字。
what is the issue.i am supposed to get numbers from 0 to 255.
推荐答案
I3(i-1,j-1) = I2(i-1,j-1)> J0;
创建逻辑输出。如果你不把它转换成别的东西,你的图像只会是0和1。
I3(i-1,j-1)=I2(i-1,j-1)>J0;
creates a logical as output. If you don't go and cast this to something else, you're image will only be zeros and ones.
最简单的方法是初始化 I3
在循环之外,即在开始循环之前有 I3 = I2;
。这样,循环中的所有赋值都会转换为 I2
的类。
The easiest way is to initialize I3
outside the loop, i.e. have I3=I2;
before you start looping. This way, all your assignments inside the loop get converted to whatever class I2
was.
这篇关于MATLAB中的局部二值模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!