Classify photos based on their labels

3 views (last 30 days)
I'm a newbie to image processing with MATLAB. Please help me to modify the code
I am working on a database that contains 6392 images of left and right eye images. Each of these images has a different label, which is placed in an Excel file based on the name of the images.
dataset:(https://www.kaggle.com/andrewmvd/ocular-disease-recognition-odir5k)
I wrote the following script to categorize images based on labels, but unfortunately I got an error.
"Brace indexing is not supported for variables of this type."
Please help me correct the code.
Code and screenshots of images and labels are attached at the bottom.
datapath='C:\Users\FarHad\Downloads\Compressed\ODIRK\preprocessed_images';
% Two-class Data path
multi_class_datapath='C:\Users\FarHad\Downloads\Compressed\ODIRK\preprocessed_images\right';
% Class Names
class_names={'Normal','Diabetes','Glaucoma','Cataract','AMD','Hypertension','Myopia','OtherDiseases'};
mkdir(sprintf('%s%s',multi_class_datapath,class_names{1}))
mkdir(sprintf('%s%s',multi_class_datapath,class_names{2}))
mkdir(sprintf('%s%s',multi_class_datapath,class_names{3}))
mkdir(sprintf('%s%s',multi_class_datapath,class_names{4}))
mkdir(sprintf('%s%s',multi_class_datapath,class_names{5}))
mkdir(sprintf('%s%s',multi_class_datapath,class_names{6}))
mkdir(sprintf('%s%s',multi_class_datapath,class_names{7}))
mkdir(sprintf('%s%s',multi_class_datapath,class_names{8}))
% Read the Excel Sheet with Labels
[num_data]=xlsread('full_df.xlsx');
% Determine the Labels
train_labels=num_data(:,end);
% Filename
filename=num_data(1:end,2);
% Determine the Files put them in separate folder
for idx=1:length(filename)
% You could uncomment if you would like to see live progress
% fprintf('Processing %d among %d files:%s \n',idx,length(filename),filename{idx})[/%]
% Read the image
current_filename=strrep(filename{idx}, char(39), '');
img=imread(sprintf('%s%s.jpg',datapath,current_filename));
% Write the image in the respective folder
imwrite(img,sprintf('%s%s%s%s.jpg',multi_class_datapath,class_names{train_labels(idx)},'\',current_filename));
clear img;
end
  2 Comments
Farhad Abedinzadeh
Farhad Abedinzadeh on 9 Dec 2021
I'm sorry for the mistake,for simplicity, I renamed the photos from 0 to 6391, and also numbered the labels from 0 to 7, for example, I replaced the normal class which is is located in the above table with the letter ['N'] with 0, the Diabetes class which is is located in the above table with the letter ['D'] have replaced with 1, and so on for other diseases up to 7.
And I saved the new labels in a new Excel file, then I called that new file in MATLAB and got the following error.
error:
Brace indexing is not supported for variables of this type.
Error in maincode (line 25)
current_filename=strrep(filename{idx}, char(39), '');

Sign in to comment.

Accepted Answer

yanqi liu
yanqi liu on 10 Dec 2021
Edited: yanqi liu on 10 Dec 2021
yes,sir,may be upload full_df.xlsx
now,i thinke filename is numberic vector, so
current_filename=strrep(filename{idx}, char(39), '');
use
disp(filename)
current_filename=strrep(num2str(filename(idx)), char(39), '');

More Answers (0)

Community Treasure Hunt

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

Start Hunting!