Clear Filters
Clear Filters

How do I use the names of images ( .png's) in my folder to transfer over as column headings in a csv?

1 view (last 30 days)
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 Comments
Paolo
Paolo on 24 May 2018
Edited: Paolo on 24 May 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 on 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

Sign in to comment.

Answers (0)

Categories

Find more on Convert Image Type 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!