How do I use the names of images ( .png's) in my folder to transfer over as column headings in a csv?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Greetings, I am looking for guidance to help me understand how to use the names of my hyperspectral images (.png) from a folder as column headings on a CSV to make sure the wavelength associated to a value is from the correct image (as a double check). As an example, if I have these images: 0_0_0.png, 2_0_0.png,.... 244_0_0.png, how can I have the same name transfer over to a csv?
I used 'strsplit()' to break up the folder name so parts of the folder would be included in the CSV but I am not sure what else I need.
Thank you
Folder name Example: 1-4-17_14-02-TL-C-A-1_2017-01-04_RaePond
fields = strsplit(directoryname,'_'); %breaks up main folder name
barcodeString = fields{2}; %barcode
dateString = fields{3}; %date (there are multiple dates)
fileName = fullfile(pwd, 'Hyper_Results.csv'); %csv file name containing all of the results
fid = fopen(fileName, 'wt');
fprintf(fid, 'barcodeString, dateString\n');
% Write headers
fprintf(fid, '%s, %s, %f, %f\n', barcodeString, dateString, "insert .png names");
fclose(fid);
2 Kommentare
Paolo
am 24 Mai 2018
Bearbeitet: Paolo
am 24 Mai 2018
files = dir ('*/*.png')
will list all the .png files under the current directory (including subfolders). You can then access the name of the files with:
files.name
I suggest you use Stephen's filename sorting function is you wish to read the files in a certain order.
I also noticed that in your code you are using 'pwd' when calling fullfile function, meaning that the code will fail to open the .csv file if your working directory changes. I recommend using an absolute path for the .csv file.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Convert Image Type finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!