how to change image format

2 vues (au cours des 30 derniers jours)
saeed hassiny
saeed hassiny le 5 Mai 2019
Commenté : firdaus mohamed le 20 Mai 2022
I have 100 images in the directory D:\images . I need to read these images and change the format from PGM into JPG and save the result in the forlder d:\newimages . can any one help me in complete and correct code with my thanks.

Réponses (1)

Murugan C
Murugan C le 5 Mai 2019
Use below code.
clc
clear all
%% Get the info
cd 'Images'
img_dir = dir('*.pgm');
cd ..
len_img = length(img_dir);
fileFmt = '.jpg'; % new file format
for i = 1 : len_img
% get the image one by one.
f = img_dir(i).name;
cd 'Images'
% read image
f1 = imread(f);
cd ..
% extracting file format
[pathstr, name, ext] = fileparts(f);
if strcmp(ext, '.pgm')
% Concatenate with new file format
imgCat = strcat(name, fileFmt);
cd 'NewImages'
% writing into new location
imwrite(f1,imgCat);
cd ..
end
end
  1 commentaire
firdaus mohamed
firdaus mohamed le 20 Mai 2022
Thank you Sir

Connectez-vous pour commenter.

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by