数模论坛

 找回密码
 注-册-帐-号
搜索
热搜: 活动 交友 discuz
查看: 4723|回复: 3

Matlab写/读图的问题?

[复制链接]
发表于 2003-8-6 01:15:47 | 显示全部楼层 |阅读模式
img(:,:,1)=round(rand(5)*255);
img(:,:,2)=round(rand(5)*255);
img(:,:,3)=round(rand(5)*255);
imwrite(img,'rand.bmp','bmp')
a=imread('rand.bmp','bmp');

为什么img和a的值不同?
发表于 2003-8-6 07:12:19 | 显示全部楼层
请详细阅读imwrite的help:
  if the (input) data array is double, the assumed dynamic range is [0,1]

  语句"round(rand(5)*255)",使得double型变量img中几乎所有数据都大于1,超出了动态范围,故而得到的Unit8型变量a中几乎所有数据都为255。

  根据help中的说明:
  For ...RGB images, if the data array is double, the assumed dynamic range is [0,1].  The data array is automatically scaled by 255 before being written out as uint8.  ...If logical data is written to a BMP, ...it is assumed to be a binary image and will be written with a
bitdepth of 1.
  修改程序如下:
  img(:,:,1)=rand(5);
  img(:,:,2)=rand(5);
  img(:,:,3)=rand(5);
  imwrite(img,'rand.bmp','bmp')
  a=imread('rand.bmp','bmp');
  数值上,a=floor(img*255)+1

  如果输入的是unit8或unit16型的img的话,就更容易了

  详细内容参见imwrite、imread的help文件中的Date Types

发表于 2003-8-7 07:39:43 | 显示全部楼层
这是imwrite的帮助文件:
IMWRITE(A,FILENAME,FMT) writes the image A to FILENAME.
    FILENAME is a string that specifies the name of the output
    file, and FMT is a string the specifies the format of the
    file.  A can be either a grayscale image (M-by-N) or a
    truecolor image (M-by-N-by-3).
发表于 2003-8-7 15:54:00 | 显示全部楼层
不止这么少吧
您需要登录后才可以回帖 登录 | 注-册-帐-号

本版积分规则

小黑屋|手机版|Archiver|数学建模网 ( 湘ICP备11011602号 )

GMT+8, 2024-11-30 09:49 , Processed in 0.052144 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表