简体   繁体   中英

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

I want to use bagOfFeatures() function of MATLAB. But it requires input in the form of imageSet or 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. 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. 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.

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. 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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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