Azzera filtri
Azzera filtri

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

7 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Image Analyst
Image Analyst il 25 Set 2018
Modificato: Image Analyst il 25 Set 2018
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

Più risposte (0)

Categorie

Scopri di più su Data Type Conversion in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by