在Matlab中将(.png)格式的图像转换为(.jpg)格式 [英] convert image with (.png) format to (.jpg) format in Matlab

查看:2740
本文介绍了在Matlab中将(.png)格式的图像转换为(.jpg)格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我需要将所有(.png)格式的图像转换为(.jpg)格式.我使用了imwrite函数(Matlab的函数之一):

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');

我只能转换一张图像...我需要转换所有图像并将其保存在新文件夹中. 有人可以让我知道我该怎么做吗? 将图像转换为(.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?

请转发您的宝贵建议.

谢谢

推荐答案

您需要做的是这样:

  1. 获取要转换的所有文件的列表.使用函数dir,该函数返回带有组件name的结构.
  2. 编写循环以一次浏览一个文件并进行转换-您可以使用已经编写的代码,但是当然您必须在每次迭代时设置文件名.
  3. 写出转换后的文件时,在要写的文件名中包括新文件夹的相对路径,例如:imwrite(S,'./newfolder/D-1.jpg').
  1. Get a list of all the files that you want to convert. Use the function dir, which returns a structure with a component name.
  2. 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.
  3. 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').

转换后图像的属性是否有变化?通常是的,因为png和jpeg编码的信息有所不同. Matlab函数imreadimwrite的帮助对此进行了解释.您可能会发现自己需要或想要在写入图像之前对其进行修改.

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.

这篇关于在Matlab中将(.png)格式的图像转换为(.jpg)格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆