在Matlab中把(.png)格式的图像转换成(.jpg)格式 |
您所在的位置:网站首页 › fullfile翻译 › 在Matlab中把(.png)格式的图像转换成(.jpg)格式 |
百度翻译此文
有道翻译此文
问题描述
In my application I need to convert all images with (.png) format to (.jpg) format. I used the imwrite function (one of Matlab's functions): S=imread('D-1.png'); imwrite(S,'D-1.jpg');and I can convert just one image... I need to convert all images and save them in a new folder. Could any one please let me know how I can do that? Is there are any changes in the properties of the image after convert it to the (.jpg) format? Please forward your valuable suggestions. Thanks 推荐答案What you need to do is this: Get a list of all the files that you want to convert. Use the function dir, which returns a structure with a component name. Write a loop to go through the files one at a time and convert them -- you can use the code you've already written, but of course you'll have to set the file names at each iteration. When you write the converted file out, include the relative path to the new folder in the name of the file you are writing, something like: imwrite(S,'./newfolder/D-1.jpg').Are there any changes to the properties of the image after conversion ? In general yes, since there are differences in the information that png and jpeg encode. The Matlab help for functions imread and imwrite explain some of this. You may find that you need, or want, to modify the image that you read before writing it. 其他推荐答案This here, combined with what you have should do the trick! 其他推荐答案I take the suggestion from members and I tried the following coding so I was able to convert the (.png ) format to (.jpg) format: fileFolder = fullfile('D:','\Last Work Nov. 2010 16','Last ColTexFeapro28 Nov', 'Brodatz classes', 'Brodatz999'); dirOutput = dir(fullfile(fileFolder,'D*.png')); fileNames = {dirOutput.name}; for k=1:length(fileNames) I=fileNames{k}; S=imread(I); newName = sprintf('image%04d.jpg',k); // convert from (.png to .jpg ) format movefile(fileNames{k},newName); |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |