简体   繁体   English

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

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

I want to use bagOfFeatures() function of MATLAB. 我想使用MATLAB的bagOfFeatures()函数。 But it requires input in the form of imageSet or imageDataStore. 但是它需要以imageSet或imageDataStore的形式输入。 The code I want to run is given below: 我要运行的代码如下:

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

But the "sequence" is a cell class and so bagOfFeatures() is giving me errors. 但是“序列”是一个单元格类,因此bagOfFeatures()给我错误。 So I tried this: 所以我尝试了这个:

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

But now the problem is how to do the processing (thresholding) on images saved in imgSets. 但是现在的问题是如何对保存在imgSets中的图像进行处理(阈值处理)。 Also, after processing how to save all the "image_bin" images in imageSet class so that I can give them as input to the BagOfFeatures() function. 另外,在处理了如何将所有“ image_bin”图像保存在imageSet类中之后,我可以将它们作为BagOfFeatures()函数的输入。

I solved this problem myself. 我自己解决了这个问题。 To give input as an imageSet or imageStrore to BagOfFeatures(), we have to store all the "image_bin" images in a folder in PC. 要将输入作为imageSet或imageStrore提供给BagOfFeatures(),我们必须将所有“ image_bin”图像存储在PC的文件夹中。 For that, we have to create that folder in the desired location as 为此,我们必须在所需位置创建该文件夹,如下所示:

mkdir D:\.............\cropped

Then, we have to save the "image_bin" in that folder in a loop as 然后,我们必须将该文件夹中的“ image_bin”循环保存为

file_name = sprintf('D:/............/cropped/image_bin_%d.png',j);
imwrite(image_bin, file_name);

Then, the data from above folder is read in MATLAB memory as 然后,将上述文件夹中的数据读入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);

And It's done. 并且完成了。

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

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