Filter löschen
Filter löschen

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)
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
Paolo am 24 Mai 2018
Bearbeitet: Paolo am 24 Mai 2018
You will need to find the filename of the .png files using dir. An example:
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.
Rae Pond
Rae Pond am 4 Jun. 2018
Apologies for the late response.
I got things running but for some reason, the data writes from top to bottom, rather than writing left to right.
I was hoping to do this: column A- barcode of plant & column b- date of the barcode the image
note: each barcode has 20 days of images
then columns C through IK are the images 2 through 244.png's
Currently, things are writing but I can't tell which results go to which image.
Any Suggestions?
Please and Thank you

Melden Sie sich an, um zu kommentieren.

Antworten (0)

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!

Translated by