필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
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
Paolo
Paolo 2018년 5월 24일
편집: Paolo 2018년 5월 24일
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 2018년 6월 4일
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

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by