Borrar filtros
Borrar filtros

Name of saved image should be the same than read image

1 visualización (últimos 30 días)
Veilchen1900
Veilchen1900 el 11 de Jun. de 2016
Comentada: Veilchen1900 el 12 de Jun. de 2016
Hello! I read images using imread, remove the lens distortion and then write it to a new created folder.The code works but I don't have the original name of the images anymore. I want that the image name e.g. 20160406.png is the same for the new undistorted image. How can I do that?
This is my code:
z=dir('*.png');
NewFolder=mkdir('NewFolder');
for k = 1:numel(z)
X=imread(z(k).name);
Y=undistortImage(X,cameraParams);
imwrite(Y,['NewFolder/', num2str(k),'.png']);
end

Respuesta aceptada

Image Analyst
Image Analyst el 11 de Jun. de 2016
Try this:
files = dir('*.png');
if exist('NewFolder', 'dir')
NewFolder=mkdir('NewFolder');
end
for k = 1:numel(z)
% Get input base file name.
thisImage = imread(files(k).name);
% Correct the image.
correctedImage = undistortImage(thisImage, cameraParams);
% Create the output filename.
baseFileName = files(k).name; % Same as source filename.
fullOutputFileName = fullfile(NewFolder, baseFileName);
% Save the output image.
imwrite(correctedImage, fullOutputFileName);
end

Más respuestas (0)

Categorías

Más información sobre Convert Image Type 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