how to use save a new file with a prefix before the original file name in a loop

7 次查看(过去 30 天)
Hi,
I would like to save each file in a loop using a prefix (in this case, "blur_") before the name of the original file. This is the code I have so far
for i = 1:N
blur{i} = imgaussfilt(imdata{i},10)
imshow(blur{1})
imwrite(blur{i},sprintf('blurred_circle_%d.png',i))
end
using this code I am able to define a prefix (blurred_circle_) and then to give a number to each file and save them. the point is that I need my output to be like 'blurred_(original filename).png'. How can I do that?
thanks A

采纳的回答

Image Analyst
Image Analyst 2018-9-25
编辑:Image Analyst 2018-9-25
Try this:
files = dir('*.png');
for k = 1 : length(files)
thisName = files(k).name
fullFileName = fullfile(files(k).folder, files(k).name)
theImage = imread(fullFileName);
subplot(1, 2, 1);
imshow(theImage);
drawnow;
blurredImage = imgaussfilt(theImage, 10);
subplot(1, 2, 2);
imshow(blurredImage);
drawnow;
outputBaseFileName = sprintf('Blur_%s', thisName);
outputFullFileName = fullfile(files(k).folder, outputBaseFileName)
imwrite(blurredImage, outputFullFileName);
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by