HOW TO CHANGE MULTIPLE JPG TO PNG IMAGES

HOW TO CHANGE MULTIPLE JPG TO PNG IMAGES

2 Comments

Please do not SHOUT.
sorry for my mistake and also clarify that. i only ask my doubt regards the program sir

Sign in to comment.

 Accepted Answer

f=dir('Yourfolder\*.jpg');
fil={f.name};
for k=1:numel(fil)
file=fil{k}
new_file=strrep(file,'.jpg','.png')
im=imread(file)
imwrite(im,new_file)
end

13 Comments

ajith
ajith on 13 Jun 2013
Edited: ajith on 13 Jun 2013
but dimension is not reduced ie) 3 dimension matrix is not change into 2 dimension matrix
Yes? PNG does support 2D image formats, but it also supports 3D image formats.
i run this code after check the dimension of the png format it shows 200x200x3 i need it to make only 2 dimension only
Worked great. Thanks!
can you explain me about this part: "imwrite(im,new_file)" -Matlab shows "Error using imwrite (line 454)"-
You would have an error if the file name you gave to write to is one that could not be opened.
Thank you, but when i want to show the "new_file" by code imshow(new_file), Matlab shows that "Error using images.internal.getImageFromFile Cannot find the specified file"
Example:
im = imread('cameraman.tif');
new_file = fullfile(tempdir(), 'test_image.png');
imwrite(im, new_file);
fprintf('The image was stored into file name: "%s"\n', new_file )
imshow(new_file)
Notice how I told it which directory to write into
Duy, start a new question and attach your code so we don't spend/waste time guessing at what you have and how to fix it.
Thank You so much!! @Azzi Abdelmalek
can you please make me clear part of the code
for k=1:nume1 (fil)
here "nume1" stands for what
It is not "nume1" but numel
When I use your code I found that error
Error using strrep
Char inputs must be row vectors.
Are there any explanation?
regards

Sign in to comment.

More Answers (0)

Asked:

on 29 May 2013

Commented:

on 19 Apr 2021

Community Treasure Hunt

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

Start Hunting!