how do I link Excel variable and numerical columns with with all images names ?

1 回表示 (過去 30 日間)
Maen
Maen 2019 年 7 月 20 日
回答済み: Vinai Datta Thatiparthi 2019 年 7 月 30 日
Hello I have a file with 50 images has different variable names like gddd_1, gddd_2.......etc. all these image names are at excel file with the first coloumn. these images are classified with excel file for 3 different classes as coloumns, ech coloumn representing zeros for ones . each row of the excel file has the image name in the first coloumn and ifront of the image names are the class numbers zero for not included the image in this class or one for image included for this class.
I want to link the image.names with excel file image.names and the classes for each row.
Thank you
  4 件のコメント
Guillaume
Guillaume 2019 年 7 月 20 日
Maen's comment mistakenly posted as an answer moved here:
I means the excel file containing an information I need to classifying each image as the xlsx file and I want to read the images and define each image variable with zeros and ones .
if not possibel I need to match between image names which has the name with xlsx file name.
thank you
Guillaume
Guillaume 2019 年 7 月 20 日
Your question is really not clear. What do you need help with?
  • How to import that excel file into matlab?
  • How to read the image listed in this excel file?
  • Something else?
  • All of the above?

サインインしてコメントする。

回答 (1 件)

Vinai Datta Thatiparthi
Vinai Datta Thatiparthi 2019 年 7 月 30 日
To begin with, read the data from the excel sheet into MATLAB using the command readtable. Update the path to the folder containing the images (if the location is a .zip file, extract the contents into a folder).
data = readtable('data_information.xlsx');
imgNames = table2array(data(:,1));
From your question, it is unclear what exactly it is that you want to do to “link” the values. In this example, I have assumed that you want to name the files as per the name in column 1 and append the type of object to this name. For example, a file ‘ddd_1’ that has been marked as a ‘car’ according to the Excel file will be saved as ddd_1_car.jpg.
for i=1:numel(imgNames)
info = table2array(data(i,2:4));
pos = find(info==1); % pos = 1,2,3 for car, bus & train respectively
im = imread(imgNames{i});
if pos == 1
imwrite(im, strcat(imgNames{i},'_car.jpg'));
elseif pos == 2
imwrite(im, strcat(imgNames{i},'_bus.jpg'));
elseif pos == 3
imwrite(im, strcat(imgNames{i},'_train.jpg'));
end
end
If you want to rename the files as it is, please refer to this link:
Note that this is a simple example of how you can map the names. You may continue to work on this code to get your expected results.
Hope this helps.

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by