Save images and histograms in a sequence.
3 ビュー (過去 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 件)
参考
カテゴリ
Help Center および File Exchange で Creating, Deleting, and Querying Graphics Objects についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!