Save images and histograms in a sequence.
2 次查看(过去 30 天)
显示 更早的评论
Hi,
I have a function that detects images in a folder and begins to analyse them. At the end of each analysis, I want it to save the processed image, a text file for mean values and the histograms generated from each image in sequence.
E.g.
Image 1 is loaded, processed and 2 histograms generated. I want to save this as Image 1 - processed, text file and the 2 histograms.
Then it does the same for Image 2 and so on.
Is this possible?
2 个评论
Guillaume
2014-9-25
The straightforward answer to your question is: Yes
I assume it's not all you want to hear, so if you have a problem with one particular aspect ask a more specific question. You seem to have developped the bulk of the function. In comparison what you're asking is fairly simple.
采纳的回答
Guillaume
2014-9-26
The function for creating directories is mkdir. Create the output directory before the processing loop with:
outputdir = fullfile(ImgDirectory, 'Results');
mkdir(outputdir);
To save your file in that directory at the end of the processing loop, you need to prepend the directory name to the file name with fullfile, same as you've done for loading it. sprintf is indeed the function you need to build the file name, read up on the various format fields, %s is what you need to insert a string:
%at the end for K = 1:I2P loop
%assuming that baseFileName does not include extension:
outputfile = sprintf('Process Image - %s.jpg', baseFileName);
%otherwise:
[~, truebasename] = fileparts(baseFileName);
outputfile = sprintf('Process Image - %s.jpg', truebasename);
%save in directory
imwrite(img, fullfile(outputdir, outputfile));
There are various functions for saving text files, csvwrite, dlmwrite, writetable or just do it with low level IO with fopen/fprintf/fclose which allows you to format the file any way you want.
As for saving the histogram figures, saveas or print are the functions to use.
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!