how to read labels of image dataset from mat files

I have a dataset which contains two folders one for images and another one is the truth_ground which has mat files that has the information about images (number of heads per image) I want to read this dataset so I can get the images with their labels.

 Accepted Answer

Try this
folder = 'c:\whatever\truth_ground';
fullFileName = fullfile(folder, 'someName.mat')
s = load(fullFileName);

3 Comments

thanks for you replay I did this code but it gives me error when I add the data to array of labeling.
if true
path ='C:\Users\Suhair\Documents\Network\crowd-counting-scnn-master\dataset\ShanghaiTech\part_A\train_data\ground-truth\';
for i=1:300
p=strcat(path , strcat(strcat('GT_IMG_',int2str(i)),'.mat'));
s=load(p);
label=s.image_info{1, 1}.number;
categories{i} = label ;
end
%categories=mat2cell(categories)
%rootFolder = 'C:\Users\Suhair\Documents\Network\crowd-counting-scnn-master\dataset\ShanghaiTech\part_A\train_data\images';
path2 ='C:\Users\Suhair\Documents\Network\crowd-counting-scnn-master\dataset\ShanghaiTech\part_A\train_data\images\';
img=load(strcat(path2,'IMG_1.jpg'));
% this line to check that the path is exist.
done='done'
imds = imageDatastore(fullfile(path2, categories), ...
'LabelSource', 'foldernames');
countEachLabel(imds)
imds.ReadSize = numpartitions(imds);
end
end
I get the following error
Error using imageDatastore (line 116) Cannot find files or folders matching: 'C:\Users\Suhair\Documents\Network\crowd-counting-scnn-master\dataset\ShanghaiTech\part_A\train_data\images\؊'.
Error in deepLearning (line 20) imds = imageDatastore(fullfile(path2, categories), ...
now I am sure that the path is correct but it add ؊ at the end of path and I don't know why.
Never, ever, EVER overwrite the built in path variable with a variable of your own with the same name. Notice I did not do that. I used folder instead.
You can also use sprintf() - it's simpler than that strcat stuff.
Attach your .mat file if you want more help.
hi thanks for your replay I used a dataset in this lisnk
https://github.com/desenzhou/ShanghaiTechDataset
my problem is now with imageDatasore function.
thanks

Sign in to comment.

More Answers (0)

Categories

Find more on Genomics and Next Generation Sequencing in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!