我想使用MATLAB的bagOfFeatures()函数。但它需要以imageSet或imageDataStore的形式输入。我想要运行的代码如下:
Dataset = 'D:\dsktop\kinect_leap_dataset\acquisitions';
thresh1 = 0;
thresh2 = 20;
k = dir(fullfile(Dataset,'\P*\G*\*_depth.png'));
kf = {k(~[k.isdir]).folder};
kn = {k(~[k.isdir]).name};
for j=1:length(k)
% Applying thresholding to the original image
full_name = horzcat(kf{j},filesep,kn{j});
image = imread(full_name);
image_bin1 = (image < thresh2);
image_bin2 = (thresh1 < image);
image_bin = abs(image_bin2- image_bin1);
sequence{i} = image_bin;
end
% Bag of Features
bag = bagOfFeatures(sequence);
但&#34;序列&#34;是一个单元格类,所以bagOfFeatures()给了我错误。所以我尝试了这个:
Dataset = 'D:\dsktop\kinect_leap_dataset\acquisitions';
imgFolder = fullfile(Dataset);
imgSets = imageSet(imgFolder, 'recursive');
imgSets.Description
但现在的问题是如何对imgSets中保存的图像进行处理(阈值处理)。此外,在处理完如何保存所有&#34; image_bin&#34; imageSet类中的图像,以便我可以将它们作为BagOfFeatures()函数的输入。
答案 0 :(得分:0)
mkdir D:\.............\cropped
然后,我们必须将“image_bin”保存在循环中的
循环中file_name = sprintf('D:/............/cropped/image_bin_%d.png',j);
imwrite(image_bin, file_name);
然后,来自上面文件夹的数据在MATLAB存储器中读取为
imds = imageDatastore('D:/.............../cropped', 'Labels', label);
% label is an array of labels made by the user
[trainingSet, validationSet] = splitEachLabel(imds, 0.3, 'randomize');
% Bag of Features
bag = bagOfFeatures(trainingSet);
已经完成了。