How to convert a folder with multiple type of images such as PNG, GiF, JEPG,...etc into JPG and store the converted images in a folder in desktop ?

13 ビュー (過去 30 日間)
How to convert a folder with multiple type of images such as PNG, GiF, JPEG,...etc into JPG and store the converted images in a folder in desktop ?
  1 件のコメント
Walter Roberson
Walter Roberson 2017 年 12 月 2 日
What kind of file do you have that has multiple types of images stored inside it?

サインインしてコメントする。

採用された回答

Akira Agata
Akira Agata 2017 年 12 月 2 日
How about the following script?
fileList = {'ngc6543a.jpg','corn.tif'};
for kk = 1:numel(fileList)
I = imread(fileList{kk});
[~,fileName,ext] = fileparts(fileList{kk});
imwrite(I,[fileName,'.png']);
end
  13 件のコメント
Walter Roberson
Walter Roberson 2019 年 1 月 17 日
What error did you get with imwrite() ?
Intan Antasari
Intan Antasari 2019 年 1 月 31 日
I got an error because I use imwrite to save .mat format.
I realize that imwrite is use to save image format. I already solve that problem.
I use save (filename, 'A')
Thank you for your help.

サインインしてコメントする。

その他の回答 (2 件)

Jos (10584)
Jos (10584) 2017 年 12 月 4 日
Why not use a dedicated tool to convert images, like good-old IrfanView (does it still exist?) or gimp?

cui,xingxing
cui,xingxing 2019 年 1 月 31 日
編集済み: cui,xingxing 2019 年 1 月 31 日
you can write like this,but can get all images from website(note: modify your urls):
clc
clear
% s=urlread('https://image.baidu.com/search/index?tn=baiduimage&ipn=r&ct=201326592&cl=2&lm=-1&st=-1&sf=1&fmq=&pv=&ic=0&nc=1&z=&se=1&showtab=0&fb=0&width=&height=&face=0&istype=2&ie=utf-8&fm=result&pos=history&word=%E6%B8%85%E6%9C%9D%E7%A1%AC%E5%B8%81');
s = webread('https://mp.weixin.qq.com/s/WlGxKjirx1iKqwmfMzVI0g');
pat='https://[^,"]*.=(jpg|png|gif|jpeg)';
% pat='http://[^,]*.jpg';
expr= regexp(s, pat, 'match');
%%
fid=fopen('images.txt','w');
fprintf(fid,'%s\n',expr{:});
fclose(fid);
for i=1:length(expr)
img_url =expr{i};
try
% s=websave(a,sprintf('%d.jpg',i), 'UserAgent','MATLAB R2015b','Timeout',100,'Get',{'term','urlread'});
s = websave(['./',sprintf('%d.jpg',i)],img_url);
catch ME
continue
end
end
%% show urls
imgs = string(expr);
for i = 1:length(imgs)
fprintf('%s\n',imgs(i));
end
% reference: https://stackoverflow.com/questions/169625/regex-to-check-if-valid-url-that-ends-in-jpg-png-or-gif

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by