Save images and histograms in a sequence.
1 view (last 30 days)
Show older comments
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 Comments
Guillaume
on 25 Sep 2014
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.
Accepted Answer
Guillaume
on 26 Sep 2014
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 Comments
More Answers (0)
See Also
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!