Borrar filtros
Borrar filtros

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

8 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Image Analyst
Image Analyst el 25 de Sept. de 2018
Editada: Image Analyst el 25 de Sept. de 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

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by