在处理图像之前问什么用matlab double转uint8和uint8

MATLAB基本函数一 矩阵运算
  1.基本算数运算(加减乘除)
    + -运算要求矩阵维数相同,例m*n
    * /运算,例A=B*C,B矩阵是m*n矩阵,B是n*p矩阵,则A是m*p矩阵
    A/B相当于A*inv(B),A与B的逆矩阵相乘
    A\B相当于inv(A)*B
  2.点运算.*
.^两个矩阵对应元素进行相应运算
  3.关系运算&、& &= &= == ~=,表达式成立则为1,否则为0.如果是矩阵,
  则按位置逐个进行比较。
  4.逻辑运算& | ~
  5.矩阵其他运算
    1.矩阵求逆inv(A)
    2.行列式求值det(A)
    3.对角矩阵diag(A)
    4.矩阵转置'例:A'
二、矩阵其他运算
  1.矩阵尺寸[m,n]=size(A),A的行和列分别保存在m和n中
  2.绝对值abs(A),返回A中每个元素的绝对值
  3.最大值max(A)最小值min(A),返回矩阵A中每一列的最大值或最小值
  4.求和sum(A),返回矩阵A中每一列的和
  5.向下取整floor(A),向上取整ceil(A),对每一个元素取小于或等于元素值,
    如果是复数,对实部和虚部分别运算
  6.近似取整是round(A),
  7.取整数部分是fix(A)
  8.查找非零值find(A),返回的是非零元素位置的向量。将矩阵作为一维信号处理的
  9.求均值,median(A),对每一列元素求均值返回
  10.矩阵变形函数reshape(A,m,n),将矩阵A按照访问顺序变成m*n维的矩阵
  11.矩阵补充padarray(A,[m n],padvalue,DIRECTION),将矩阵A扩展成m*n维的矩阵,
  12.矩阵左右颠倒、上下颠倒。fliplr(A)或flipud(A);
  13.统计矩阵中元素个数,numel(A)
  1.figure函数
  产生一个绘图窗口
  2.指定绘图位置,将多个图形显示在一个窗口中,subplot(m,n,p),绘制在m行n列,第p的图形。
  3.绘制二维曲线plot(X,Y),将一维列向量X作为x坐标,一维列向量y作为y坐标;如果
四、图像处理基础知识
  1.图像处理常用数据类型,uint8,double,single
    double是默认数据类型,取值范围0-1,0表示分量最低的值,是黑色。
  1表示分量最高的,是白色。常在运算的中间结果运用,保证运算的精度。
    logical值为0或1,常用于形态学、图像分割、图像识别等。
  2.测试图像矩阵checkerboard(n,p,q),返回矩阵类型是double,矩阵由p*q个小单元构成
  每个小单元是由4个小方块组成,每个方块的边长都为n个像素。小方块为黑白相间或黑灰相间
  白色为1,黑色为0,灰色为0.7;
  3、图像类型转换,常用函数im2uint8(A),im2uint16(A),im2double(A),im2bw(A)转换为logical类型
  一个比较有用的函数是mat2gray(A),如果在处理图像的过程中,数据超出了数据类型所能表达的范围,
  它可以对图像进行归一化。
阅读(...) 评论() 上传我的文档
 下载
 收藏
该文档贡献者很忙,什么也没留下。
 下载此文档
正在努力加载中...
第十讲 图像处理
下载积分:900
内容提示:第十讲 图像处理
文档格式:PPT|
浏览次数:0|
上传日期: 11:06:03|
文档星级:
该用户还上传了这些文档
第十讲 图像处理
官方公共微信[原]matlab ( octave ) imshow显示图像详解 - 推酷
[原]matlab ( octave ) imshow显示图像详解
最近在用octave (类似于matlab的计算软件, 函数和matlab一致) 写程序的时候, 在显示图像和保存图像的时候遇到了一些小问题, 所以简单的总结了一下。
本文用的图像为灰度图像:
imread() 返回的图像类型是uint8类型, 这时用imshow显示图像的时候, imshow会认为输入矩阵的范围在0-255, 如果imshow的参数为double类型的,那么imshow认为输入矩阵的值为0-1.
很多时候需要将图像转换为double类型的, 但是转换以后直接使用imshow显示的是一片白色, 是因为当imshow显示图像的时候, 会认为double类型的图像矩阵的范围在0-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');
这个时候直接显示读入的图像是正确的, 因为这个时候图像的类型是uint8
显示结果:
当把图像转换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');
这个时候, 因为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');
% 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');
方式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');
显示结果:
下面是整个示例代码:
%% 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');
% 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');
% how to correctly display double typed image
% way 1: convert double to uint8
imshow(uint8(dimg));
fprintf('Program paused. Press enter to continue.\n');
% 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');
%% 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');
%% 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.
已发表评论数()
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
正文不准确
标题不准确
排版有问题
主题不准确
没有分页内容
图片无法显示
视频无法显示
与原文不一致

我要回帖

更多关于 uint8array js 的文章

 

随机推荐