如何从 Matlab 中的数据集中提取 LBP 特征?
How to extract LBP features from datasets in Matlab?
我已经了解了如何从单个图像中提取特征,如本示例所述:https://www.mathworks.com/help/vision/ref/extractlbpfeatures.html
现在我正在为我的 matlab 项目处理 1000 张图像的数据集,以提取自行车、汽车和摩托车的特征。我的数据集中有三个独立的文件夹,包括自行车、汽车和摩托车。在执行过程中,我收到错误提示,
Error using extractLBPFeatures>parseInputs (line 148)
Expected I to be one of these types:
double, single, int16, uint16, uint8, logical
Instead its type was imageSet.
Error in extractLBPFeatures (line 129)
params = parseInputs(I,varargin{:});
Error in LBP (line 21)
bycycleLBP = extractLBPFeatures(bycycleData,'Upright',false);
我该怎么办?下面是我的示例代码 ==>
imSet = imageSet('dataset\train','recursive');
bicycleData = imSet(1);
carData = imSet(2);
motorbikeData = imSet(3);
%%Extract LBP Features
bicycleLBP = extractLBPFeatures(bicycleData,'Upright',false);
carLBP = extractLBPFeatures(carData,'Upright',false);
motorbikeLBP = extractLBPFeatures(motorbikeData,'Upright',false);
bicycle = bicycleLBP.^2;
car = carLBP.^2;
motorbike = motorbikeLBP.^2;
figure
bar([bicycle; car; motorbike]','grouped');
title('LBP Features Of bicycle, car and motorbike');
xlabel('LBP Histogram Bins');
legend('Bicycle','Car','Motorbike');
请帮助我实现示例代码。
在尝试提取特征之前,让我们先看一下两个变量。
>> whos imSet bicycleData
Name Size Bytes Class Attributes
imSet 1x3 1494 imageSet
bicycleData 1x1 498 imageSet
变量 imSet
是 3 个 imageSet
对象的列表。第一个代表自行车,所以你适当地将自行车 imageSet 拉入它自己的变量 bicycleData
,这是一个单数 imageSet
。到目前为止一切顺利,但是当我们查看 extractLBPFeatures
...
的文档时
features = extractLBPFeatures(I,Name,Value)
I — Input image
Input image, specified as an M-by-N 2-D grayscale image that is real, and non-sparse.
该函数一次只能提取一张灰度图的特征。您必须遍历 imageSet
以一次提取一个特征。
% Create a cell array to store features per image.
bicycleFeatures = cell(size(bicycleData.ImageLocation));
for i = 1:length(bicycleFeatures)
% Read in individual image, and convert to grayscale to extract features.
image = imread(bicycleData.ImageLocation{i});
bicycleFeatures{i} = extractLBPFeatures(rgb2gray(image));
end
请记住,您仍有 post 处理工作要做。这会提取每个图像的特征,因此您必须确定要如何组合每个数据集中的特征数据。
我已经了解了如何从单个图像中提取特征,如本示例所述:https://www.mathworks.com/help/vision/ref/extractlbpfeatures.html
现在我正在为我的 matlab 项目处理 1000 张图像的数据集,以提取自行车、汽车和摩托车的特征。我的数据集中有三个独立的文件夹,包括自行车、汽车和摩托车。在执行过程中,我收到错误提示,
Error using extractLBPFeatures>parseInputs (line 148)
Expected I to be one of these types:
double, single, int16, uint16, uint8, logical
Instead its type was imageSet.
Error in extractLBPFeatures (line 129)
params = parseInputs(I,varargin{:});
Error in LBP (line 21)
bycycleLBP = extractLBPFeatures(bycycleData,'Upright',false);
我该怎么办?下面是我的示例代码 ==>
imSet = imageSet('dataset\train','recursive');
bicycleData = imSet(1);
carData = imSet(2);
motorbikeData = imSet(3);
%%Extract LBP Features
bicycleLBP = extractLBPFeatures(bicycleData,'Upright',false);
carLBP = extractLBPFeatures(carData,'Upright',false);
motorbikeLBP = extractLBPFeatures(motorbikeData,'Upright',false);
bicycle = bicycleLBP.^2;
car = carLBP.^2;
motorbike = motorbikeLBP.^2;
figure
bar([bicycle; car; motorbike]','grouped');
title('LBP Features Of bicycle, car and motorbike');
xlabel('LBP Histogram Bins');
legend('Bicycle','Car','Motorbike');
请帮助我实现示例代码。
在尝试提取特征之前,让我们先看一下两个变量。
>> whos imSet bicycleData
Name Size Bytes Class Attributes
imSet 1x3 1494 imageSet
bicycleData 1x1 498 imageSet
变量 imSet
是 3 个 imageSet
对象的列表。第一个代表自行车,所以你适当地将自行车 imageSet 拉入它自己的变量 bicycleData
,这是一个单数 imageSet
。到目前为止一切顺利,但是当我们查看 extractLBPFeatures
...
features = extractLBPFeatures(I,Name,Value)
I — Input image
Input image, specified as an M-by-N 2-D grayscale image that is real, and non-sparse.
该函数一次只能提取一张灰度图的特征。您必须遍历 imageSet
以一次提取一个特征。
% Create a cell array to store features per image.
bicycleFeatures = cell(size(bicycleData.ImageLocation));
for i = 1:length(bicycleFeatures)
% Read in individual image, and convert to grayscale to extract features.
image = imread(bicycleData.ImageLocation{i});
bicycleFeatures{i} = extractLBPFeatures(rgb2gray(image));
end
请记住,您仍有 post 处理工作要做。这会提取每个图像的特征,因此您必须确定要如何组合每个数据集中的特征数据。