且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Matlab中将(.png)格式的图像转换为(.jpg)格式

更新时间:2023-11-11 21:03:16

您需要做的是这样:

  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.