zoukankan      html  css  js  c++  java
  • matlab中imwrite函数详解(imwrite的输出格式)

      参考资料:

      https://www.mathworks.com/help/matlab/ref/imwrite.html?s_tid=srchtitle

      你可能觉得imread函数很简单,但是还是有一些细节要注意。比如我就对imwrite函数输出的图片格式有一些疑问,下面对imwrite函数的用法进行解释,先放一下官方文档:


    imwrite(A,filename) writes image data A to the file specified by filename, inferring the file format from the extension. imwrite creates the new file in your current folder. The bit depth of the output image depends on the data type of A and the file format. For most formats:

    • If A is of data type uint8, then imwrite outputs 8-bit values.

    • If A is of data type uint16 and the output file format supports 16-bit data (JPEG, PNG, and TIFF), then imwrite outputs 16-bit values. If the output file format does not support 16-bit data, then imwrite returns an error.

    • If A is a grayscale or RGB color image of data type double or single, then imwrite assumes that the dynamic range is [0,1] and automatically scales the data by 255 before writing it to the file as 8-bit values. If the data in A is single, convert A to double before writing to a GIF or TIFF file.

    • If A is of data type logical, then imwrite assumes that the data is a binary image and writes it to the file with a bit depth of 1, if the format allows it. BMP, PNG, or TIFF formats accept binary images as input arrays.

    If A contains indexed image data, you should additionally specify the map input argument.


      imwrite的用法本身也很简单,A是一个图像矩阵,从上述说明中可以看出,A的数据类型可以是uint8,uint16,logical等,还可以是indexed image data即索引图。filename是一个字符串,将输出图像的路径和文件名传给filename即可。更进一步从描述中可看出,输出图片文件的格式由后缀名(extension)决定,uint8基本都支持,uint16则仅有部分图片格式支持。此时我们就要specific文件名的后缀,防止出现error。

      看文档又好奇这个indexed image即索引图是什么,在网上找了一张图:

      简单来说就是给一幅图像出现的所有RGB值编一个映射表,然后有一个和图像形状一样的索引矩阵,查表即可得到RGB图。 

  • 相关阅读:
    1053: 正弦函数
    1052: 数列求和4
    1051: 平方根的和
    1050: 阶乘的累加和
    POJ 1321 棋盘问题(搜索的方式)
    HDU 1176 免费馅饼
    BZOJ 2423 (求LCS的长度和种类数)
    HDU 2612 (2次BFS,有点小细节)
    POJ 1088 滑雪(模板题 DFS+记忆化)
    HRBUST 1186 青蛙过河 (思路错了)
  • 原文地址:https://www.cnblogs.com/chester-cs/p/13100267.html
Copyright © 2011-2022 走看看