0

我想使用 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);

但是“序列”是一个单元类,所以 bagOfFeatures() 给了我错误。所以我尝试了这个:

Dataset = 'D:\dsktop\kinect_leap_dataset\acquisitions';
imgFolder = fullfile(Dataset);
imgSets = imageSet(imgFolder, 'recursive');
imgSets.Description

但现在的问题是如何对 imgSets 中保存的图像进行处理(阈值化)。此外,在处理完如何在 imageSet 类中保存所有“image_bin”图像之后,我可以将它们作为 BagOfFeatures() 函数的输入。

4

1 回答 1

0

我自己解决了这个问题。要将输入作为 imageSet 或 imageStrore 提供给 BagOfFeatures(),我们必须将所有“image_bin”图像存储在 PC 的文件夹中。为此,我们必须在所需位置创建该文件夹

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);

它已经完成了。

于 2017-07-31T05:29:05.937 回答