-
Matlab显示图像问题,double处理后,图像变白
2016-02-25 16:46:07在matlab中,我们常使用imshow()函数来显示图像,而此时的图像矩阵可能经过了某种运算。在matlab中,为了保证精度,经过了运算的图像矩阵I其数据类型会从unit8型变成double型。如果直接运行imshow(I),我们会发现...在matlab中,我们常使用imshow()函数来显示图像,而此时的图像矩阵可能经过了某种运算。在matlab中,为了保证精度,经过了运算的图像矩阵I其数据类型会从unit8型变成double型。如果直接运行imshow(I),我们会发现显示的是一个白色的图像。这是因为imshow()显示图像时对double型是认为在0~1范围内,即大于1时都是显示为白色,而imshow显示uint8型时是0~255范围。而经过运算的范围在0-255之间的double型数据就被不正常得显示为白色图像了。
那么如何解决这个问题呢?笔者曾经用fix()函数把图像矩阵由实数形式转化成整数形式,但这样仍无法改变图像矩阵是double型的事实。
通过搜索,找到两个解决方法:
imshow(I/256); ----------将图像矩阵转化到0-1之间
imshow(I,[]); -----------自动调整数据的范围以便于显示 (不明白原理!)
PS:imshow(I,[]),将I的最小值看作0,最大值看作255,所以黑白明显
从实验结果看两种方法都解决了问题,但是从显示的图像看,第二种方法显示的图像明暗黑白对比的强烈些!不知什么原理!
此外还找到一些方法,还没有试过,记录如下:
uint8和im2uint8的区别
图像数据在计算前需要转换为double,以保证精度; 很多矩阵数据也都是double的,要想显示其,必须先转换为图像的标准数据格式. 如果转换前的数据符合图像数据标准(比如如果是double则要位于0~1之间),那么可以直接使用im2uint8如果转换前的数据分布不合规律,则使用uint8,将其自动切割至0~255(超过255的按255) 最好使用mat2gray,将一个矩阵转化为灰度图像的数据格式(double)
另外,可以用isgray判断矩阵是否是一个图像数据矩阵
总之,im2uint8、im2double要跟uint8、double
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/tina_lulu_21/archive/2008/07/01/2603162.aspx
-
关于Matlab中double类型图像的后续处理问题
2018-11-13 16:19:21关于Matlab中double类型图像的后续处理问题,问题描述:使用了同态滤波之后,图像类型为double,采用imshow(I,[])可以成功显示,但是使用imwrite保存时,所保存的却是全白图像。 原因:imwrite函数保存图像时,...关于Matlab中double类型图像的后续处理问题,问题描述:使用了同态滤波之后,图像类型为double,采用imshow(I,[])可以成功显示,但是使用imwrite保存时,所保存的却是全白图像。
原因:imwrite函数保存图像时,如果图像是double型,取值范围是0~1;若为uint8型,取值范围是0~255. 如果图像满足这两条件中的任何一个,这个矩阵就可以被直接保存成图像,但是运行同态滤波后我的图像像素在8~14之间
如上图所示,这样就使得imwrite函数将其默认为全1 ,即全白图像。
解决方法:
1
I1 = uint8(round((T/
20
)*
255
));
将double图像T归一化再乘255转化为unit8类型,就可以继续进行其他的图像操作了
仍存问题是,我的图像double值为8~14,当double为0~255(一般都是),就直接如下操作就可以了
1
I1 = uint8(round((T));
-
matlab imshow显示图像详解
2019-03-11 21:31:47最近在用octave (类似于matlab的计算软件, 函数和matlab一致) 写程序的时候, 在显示图像和保存图像的时候遇到了一些小问题, 所以简单的总结了一下。 本文用的图像为灰度图像: imread() 返回的图像类型是uint...最近在用octave (类似于matlab的计算软件, 函数和matlab一致) 写程序的时候, 在显示图像和保存图像的时候遇到了一些小问题, 所以简单的总结了一下。
本文用的图像为灰度图像:
imread() 返回的图像类型是uint8类型, 这时用imshow显示图像的时候, imshow会认为输入矩阵的范围在0-255, 如果imshow的参数为double类型的,那么imshow认为输入矩阵的值为0-1.
很多时候需要将图像转换为double类型的, 但是转换以后直接使用imshow显示的是一片白色, 是因为当imshow显示图像的时候, 会认为double类型的图像矩阵的范围在0-1, 超过1的像素值当作1处理, 这样就是几乎所有的像素都是白色。
情况1:
% img will be uint8 type
img = imread('syz.bmp');
% imshow: when the parameter img is uint8 type,
% imshow will default make the range of pixel value as [0-255]
imshow(img);
fprintf('Program paused. Press enter to continue.\n');
pause;这个时候直接显示读入的图像是正确的, 因为这个时候图像的类型是uint8
显示结果:情况2:
当把图像转换double数据类型后:
% sometimes we need to process the img by double type,
% so, you may convert the data type to double
dimg = double(img);
% but, right now you will not get the correct display,
% because if the parameter of imshow is double type, if will defaultly
% take range of [0-1], but now the range is [0-255]
% all the value over 1 is ceilled to 1. (clamped to 1)
% so, the displayed image will be a whole white picture.
imshow(dimg);
fprintf('Program paused. Press enter to continue.\n');
pause;这个时候, 因为imshow的参数为double类型, imshow认为参数的值为0-1, 但是实际还是0-255, 这样超过1的值被认为是1, 显示几乎全是白色
情况3: 如何正确的显示 double 类型的图像呢, 有两种方式
% how to correctly display double typed image
% way 1: convert double to uint8
imshow(uint8(dimg));
fprintf('Program paused. Press enter to continue.\n');
pause;
% way 2: change the value of double typed image to [0-1]
maxVal = max(max(dimg));
imshow(dimg / maxVal);
fprintf('Program paused. Press enter to continue.\n');
pause;方式1 将图像转换为uint8类型, 方式2将图像像素值归约到0-1之间
显示结果:这两个显示结果是一样的。
情况4: 有些时候,图像经过处理以后会存在值为负数的像素, 如何显示呢?
这需要将所有的负数处理掉, 可以将所有的像素减去这个图像的最小的像素值, 最小的像素值为负数, 那么图像的像素值就都为正数了。
%% some other occurence, the image maybe in double type,
% but some normalization operation will lead to negative pixel value
% In order to display the image, we need to add a value that make
% all negative value to positive value
% here i just minus a specific value, in real application,
% a face image maybe normalized by substract mean face.
normImg = dimg - 127; % then normImg will have some negative values
minVal = min(min(normImg));
imshow(uint8(normImg - minVal));
fprintf('Program paused. Press enter to continue.\n');
pause;显示结果:
下面是整个示例代码:
%% this file is used to show how to use imshow or imagesc and so on
% there is some different when you use imshow to display double image or uint8 image
% here all the code will process gray image, RGB color image will not suitable for this file's code
% but you can convert RGB color image to gray image if you want to exercise by this code
% img will be uint8 type
img = imread('syz.bmp');
% imshow: when the parameter img is uint8 type,
% imshow will default make the range of pixel value as [0-255]
imshow(img);
fprintf('Program paused. Press enter to continue.\n');
pause;
% sometimes we need to process the img by double type,
% so, you may convert the data type to double
dimg = double(img);
% but, right now you will not get the correct display,
% because if the parameter of imshow is double type, if will defaultly
% take range of [0-1], but now the range is [0-255]
% all the value over 1 is ceilled to 1. (clamped to 1)
% so, the displayed image will be a whole white picture.
imshow(dimg);
fprintf('Program paused. Press enter to continue.\n');
pause;
% how to correctly display double typed image
% way 1: convert double to uint8
imshow(uint8(dimg));
fprintf('Program paused. Press enter to continue.\n');
pause;
% way 2: change the value of double typed image to [0-1]
maxVal = max(max(dimg));
imshow(dimg / maxVal);
fprintf('Program paused. Press enter to continue.\n');
pause;
%% some other occurence, the image maybe in double type,
% but some normalization operation will lead to negative pixel value
% In order to display the image, we need to add a value that make
% all negative value to positive value
% here i just minus a specific value, in real application,
% a face image maybe normalized by substract mean face.
normImg = dimg - 127; % then normImg will have some negative values
minVal = min(min(normImg));
imshow(uint8(normImg - minVal));
fprintf('Program paused. Press enter to continue.\n');
pause;
%% if you want to save image by imwrite()
% if the image is double type, you need to normalize the value to [0-1]
% if the image is uint8 type, it's ok to save image directly. -
matlab imshow显示图像
2017-03-17 16:25:58在matlab中,我们常使用imshow()函数来显示图像,而此时的图像矩阵可能经过了某种运算。在matlab中,为了保证精度,经过了运算的图像矩阵A其数据类型会从unit8型变成double型。如果直接运行imshow(A),我们会发现...转载自
在matlab中,我们常使用imshow()函数来显示图像,而此时的图像矩阵可能经过了某种运算。在matlab中,为了保证精度,经过了运算的图像矩阵A其数据类型会从unit8型变成double型。如果直接运行imshow(A),我们会发现显示的是一个白色的图像。这是因为imshow()显示图像时对double型是认为在0~1范围内,即大于1时都是显示为白色,而imshow显示uint8型时是0~255范围。而经过运算的范围在0-255之间的double型数据就被不正常得显示为白色图像了。
通过搜索,找到两个解决方法:
imshow(I/256); ———–将图像矩阵转化到0-1之间
imshow(I,[]); ———–自动调整数据的范围以便于显示 (不明白原理!) -
matlab中用imshow()显示double类型图像中出现的问题
2018-06-06 17:45:18在matlab中,我们常使用imshow()函数来显示图像,而此时的图像矩阵可能经过了某种运算。在matlab中,为了保证精度,经过了运算的图像矩阵I其数据类型会从unit8型变成double型。如果直接运行imshow(I),我们会发现... -
MATLAB读取显示图像时数据格式转换原因
2020-10-21 15:59:211、MATLAB在读取图像时要将图片数据转换为double imread() 把灰度图存入一个8位矩阵或彩图存入8位RGB矩阵中 因为MATLAB读入图像的数据是uint8格式,但是MATLAB中一般采用double型(64)位进行和运算,所以要... -
MATLAB imshow处理double型图像
2020-03-10 09:49:37若图像数据经过处理后由uint8变成double型,直接运行imshow,会显示全白 因为imshow()显示图像时对double型是认为在01范围内,即大于1时都是显示为白色,而imshow显示uint8型时是0255范围。而经过运算的范围在0-255... -
matlab_处理图像时为什么把数据转换为double型,及显示
2018-04-15 11:32:56为了节省存储空间,matlab为图像提供了特殊的数据类型uint8(8位无符号整数),以此方式存储的图像称作8位图像。imread把灰度图像存入一个8位矩阵,当为RGB图像时,就存入8位RGB矩阵中。因此,... -
MATLAB图像imshow函数显示问题、uint8与double类型转换、自定义图像显示函数
2020-12-21 11:43:04MATLAB求图像直方图、累计直方图前言一、图像显示问题说明1.说明2.案例展示二、图像类型转换三、自定义显示函数1.函数代码2.函数调用总结 前言 在图像处理中,很多处理手段都需要求图像的直方图或者累计直方图,... -
MATLAB显示图像变白问题
2017-09-30 22:01:31使用matlab显示图像有时候会出现显示白色的情况,这里说下存在的两种可能。显示图像类型原因博客讲解 <:http://blog.csdn.net/hongshan50/article/details/6444914> 简单来说,就是图像的数据类型是double类型,... -
Matlab显示图像三维信息
2016-11-14 15:30:38Matlab显示图像三维信息 im1=imread('lena.bmp');mesh(double(im1));colormap gray -
matlab显示图像频谱
2017-05-17 15:42:11将以下代码保存为m文件: function display_spectrums(file) img=imread(file);...img=double(img); f=fft2(img); f=fftshift(f); magnitude=log(1+abs(f)); subplot(2,1,1),imshow(magnitude,[]),tit -
Matlab中处理double型图像以及对imshow(I,[])函数的理解
2019-10-11 16:24:31近期学习使用matlab处理图像,对于显示double型图像遇到些问题,查阅相关博客、论坛,总结如下: 1、在matlab中,为了保证精度,经过了运算的图像矩阵I其数据类型会从uint8型变成double型。 2、如果直接运... -
matlab—图像显示
2016-12-02 20:17:13matlab图像类型转换以及uint8、double、im2double、im2uint8和mat2gray等说明 原始的两张图像: 今天在做实验的时候,遇到一个图像显示的问题,就是图像转成double类型处理后忘了转回到uint8类型就 -
Matlab图像显示
2018-09-26 13:24:30y是调整后的图像矩阵,x是原图像矩阵。设调整后的灰度范围是【rangehigh-rangelow】。 1、原图像矩阵灰度值范围以及平均值获取 maxIm=double(max(max(inputIm))),inputIm是原图像矩阵 minIm=double(min... -
Matlab--图像处理之imshow遇到的uint8和double之间的弯路
2020-12-23 13:26:451、imread() 返回的图像类型是uint8类型, 这时用imshow显示图像的时候, imshow会认为输入矩阵的范围在0-255, 如果imshow的参数为double类型的,那么imshow认为输入矩阵的值为0-1.(所以如果是double类型的矩阵... -
matlab 图像显示 命令 image imshow
2017-07-06 20:18:34C 可以是一MxN 或 MxNx3维的矩阵,且可以是包含 double, uint8,或 uint16 数据.image是用来显示附标图像 即显示的图像上有x,y坐标轴的显示,可以看到图像的像素大小。 但可以加上axis off命令即可把坐标去掉。 ...