How do I save multiple images after converting them?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Vinay Chawla
el 15 de Dic. de 2020
Comentada: Vinay Chawla
el 15 de Dic. de 2020
Hello,
I am trying to apply Median filter on a set of image data (50 Images) and I was wondering if someone can help me with the code to save each image after coonversion. I am using the following code and tool 'imsave' to save the images, but it is giving me an error
D = 'C:\Users\ChawlaV\Desktop\MATLAB\CNN Input 2\Alligator Cracks';
S = dir (fullfile(D,'*.png'));
for k = 1: numel(S);
F = fullfile (D, S (k).name);
I = imread (F);
grayImage = rgb2gray(I);
MFImage = medfilt2(grayImage);
path = ('C:\Users\ChawlaV\Desktop\MATLAB\CNN MF\Alligator Cracks'\'*.png*');
imsave(MFImage);
figure, imshow (MFImage);
end
%% ERROR
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/462075/image.png)
Thank you,
0 comentarios
Respuesta aceptada
Image Analyst
el 15 de Dic. de 2020
Don't use imsave(). And don't use path as the name of the variable - it's a very important built in global variable.
Try it this way, which has tons of improvements (like better variable names, using imwrite(), etc.).
inputFolder = 'C:\Users\ChawlaV\Desktop\MATLAB\CNN Input 2\Alligator Cracks';
outputFolder = 'C:\Users\ChawlaV\Desktop\MATLAB\CNN MF\Alligator Cracks';
fileListing = dir (fullfile(inputFolder,'*.png'));
for k = 1: numel(fileListing)
% Get the input filename.
inputFullFileName = fullfile (inputFolder, fileListing(k).name);
% Read in the original image from disk.
grayImage = imread (inputFullFileName);
% Display the image
subplot(1, 2, 1);
imshow(grayImage);
% Check to see if it's grayscale, like it should be.
if ndims(grayImage) == 3
% It's color. Need to convert it to gray scale.
grayImage = rgb2gray(grayImage);
end
% Median filter the image.
MFImage = medfilt2(grayImage);
% Display the image
subplot(1, 2, 2);
imshow(MFImage);
drawnow; % Force update.
% Save the image to the output folder.
fullFileName = fullfile(outputFolder, fileListing(k).name);
imwrite(MFImage, fullFileName);
end
Más respuestas (0)
Ver también
Categorías
Más información sobre Convert Image Type en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!