繁体   English   中英

如何以imageSet或imageDataStore的形式向MATLAB中的BagOfFeatures()函数提供输入?

[英]How to provide input to BagOfFeatures() function in MATLAB in the form of imageSet or imageDataStore?

我想使用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中的图像进行处理(阈值处理)。 另外,在处理了如何将所有“ image_bin”图像保存在imageSet类中之后,我可以将它们作为BagOfFeatures()函数的输入。

我自己解决了这个问题。 要将输入作为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);

并且完成了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM