Digital Image Processing Using MATLAB 之笔记一

Digital Image Processing Using MATLAB 之笔记一

自学冈萨雷斯数字图像处理笔记一之基本原理:

目录:


基本知识

1.一幅图像可以被定义为一个二维函数f(x,y),其中x和y是空间(平面)坐标,f在任何坐标点(x,y)处的振幅称为图像在该点的亮度。
-数字化坐标和振幅:坐标值数字化——取样;振幅数字化——量化
-当f的x,y分量和振幅都是有限且离散的量时,称该图像为 数字图像
2.使用函数imread将图像读入MATLAB,语法如下:
imread(filename);
-命令行结尾处的分号在MATLAB中用以取消输出:若命令行中未包含分号,则MATLAB会立即显示该行中的运算的结果。
-名称不区分 大小写

3.函数size可给出一幅图像的行数和列数:

>>f=imread('D:\myimages\test.jpg');
>>size(f)
ans=
    1024   1024

4.函数whos可以显示一个数组的附加信息,如name,size,bytes,class。语法如下:

>>whos f
5.函数imshow用以显示图像,基本语法为
imshow(f,G);
其中,f是一个图像数组,G是显示该图像的灰度级数。若将G省略,则默认的灰度级数是256.
语法
imshow(f,[low high]);
会将所有小于或等于low的值显示为黑色,所有大于或等于high的值显示为白色。介于两者之间讲义默认的级数显示为中等亮度值。
语法
imshow(f,[ ]);
会将变量low设置为数组f的最小值,将变量high设置为数组f的最大值。该形式在显示一副动态范围较小的图像或既有正值又有负值的图像时非常有用。

这里写图片描述

6.函数pixval用来交互显示单个像素的亮度值。
当光标随鼠标在图像移动时,光标所在位置的坐标和该点的亮度值会在该图像窗口的下方显示出来。若按下鼠标左键不放,则pixval将显示光标初始位置和当前位置间的欧几里得距离。

7.figure函数可同时显示两幅图像。

8.函数imwrite将图像写到磁盘上进行保存,语法为:
imwrite(f,filename);
另一种常用但只适用于JPEG图像的函数是imwrite,其语法为:
imwrite(f,filename.jpg,quality,q);
其中,q是一个在0到100的整数,表示JPEG压缩,q越小,图像退化越严重。
9.函数imfinfo可获取图像的详细信息, 语法1:
imfinfo bubbles25.jpg;
其结果在屏幕上显示出信息
语法2:
K=imfinfo(bubbles25.jpg);
其结果把由imfinfo产生的信息存入K,图像的高度和宽度可利用结构域K.Height与K.Width表示。
10.一副二值图像是一个取值只有0和1的逻辑数组。因而,一个取值只包含0和1的unit8类数组,在MATLAB中并不认为是二值图像。使用logical函数可以把数值数组转换为二值数组。 语法:
B=logical(A);
若A中含有除了0和1之外的其他元素,使用该函数可以将所有非零的量变换为逻辑1.
测试一个数组是否为逻辑数组,使用函数islogical:
islogical(A);
: 若A是逻辑数组,则该函数返回1;否则,返回0

11.一幅图像的特性是由数据类和图像类型这两者来表征的。
- 数据类:double,unit8,unit16,unit32,int8,char,logical……
- 图像类型:亮度图像(Intensity images),二值图像(Binary images),索引图像(Indexed images),RGB图像

12.数据类与图像类型之间的转换:
- 数据类间的转换: B=data_class_name(A)
- 图像类与类型之间的转换
这里写图片描述

把一个double类的任意数组转换成取值范围为[0,1]的归一化double数组,利用函数mat2gary完成,基本语法为:
g=matgary(A,[Amin,Amax]);
函数im2double将输入转换为double类 二值与亮度图像类型之间的转换:函数im2bw
g=im2bw(f,T);
: 该函数通过阈值T处理,将衣服亮度图像f转换为一副二值图像g。

13.向量索引:使用一维索引,即v(1)是向量v的第一个元素。向量的元素
使用方括号括起,由空格或逗号隔开。

>>v=[1 3 5 7 9 ]
v=
  1 3 5 7 9
>>v(2)
ans=
   3
>>v(2:4)
ans=
   3 5 7
>>v(3:end)
ans=
   5 7 9
>>v(1:2:end)   //表示索引从1开始计数,步长为2,直到最后一个元素停止
ans=
   1 5 9 
>>w=v.'       //.'表示转置
w =
     1
     2
     3
     4
函数linspace语法为: x=linspace(a,b,n)
该语句产生一个含有n个元素的行向量x,这n个元素之间线性地隔开并且包含a与b。

14.矩阵索引:用一列被方括号括起并用分好隔开的行向量表示。

>>A=[1 2 3; 4 5 6; 7 8 9]
A=
  1 2 3
  4 5 6
  7 8 9
>>C3=A(:,3)   //冒号本身的作用相当于A(13,3)
C3=
   3
   6
   9
>>E=A([1 3],[2 3]) 
E=
   2 3
   8 9
//符号A([a b],[c d])从A中挑选出坐标为行a列c,行a列d,行b列c,行b列d,的元素
>>fp=f(end:-1:1,:);
//图片垂直翻转

这里写图片描述

M函数编程

M文件由文本编辑器创建,并以filename.M形式的文件名存储,其组成部分如下:

  • 函数定义行
    -函数定义行的形式为: function [outputs] =name(inputs)
    若函数只有单个输出变量,可不使用方括号而直接列出;若函数没有输出,则只需使用function,而不需括号或等号;若函数有多个输出,则位于方括号内用空格隔开。
  • H1行
    -H1行是第一个文本行,是单个注释行,形式为:% compute the sum…
  • 帮助文本
    -紧跟在H1后,二者之间无空行。
  • 函数体
    -包含执行计算并给输出变量赋值的MATLAB代码,符号”%”用以添加注释
  • 命令

MATLAB运算符可分为以下三类:

  • 执行数值计算的算术运算符
    -这里写图片描述

    这里写图片描述

  • 在数量上比较操作数的关系运算符
    -这里写图片描述
  • 执行函数AND,OR,NOT的逻辑运算符
    -这里写图片描述

    这里写图片描述

这里写图片描述
这里写图片描述

这里写图片描述

流控制语句

这里写图片描述

  • if,else和elseif
 if expression1
      statements1
 elseif expression2
     statements2    
     ...
 else expressionN
     statementsN 
 end
  • while
 while expression1
       statements1
       while expression2
              statements2
       end
       additional loop1 statements
 end
  • for
 for index1=start1:increment:end
       statements1
       for index2=start2:increment:end
             statements2
       end
       additional loop1 statements
 end
  • switch

    switch switch_expression
        case case_expression
               statement(s)
        case case_expression1
               statement(s)1
        ...
        otherwise
              statement(s)N
    end

交互式IO

函数disp用来在屏幕上显示信息,其语法为
disp(argument)
函数input用于将数据输入到M函数,输入信息可以是单个数字,字符串(用单引号括起),向量(用方括号括起,其中的内容用空格或逗号分开),矩阵(用方括号括起,行与行之间用分号隔开)。其语法为
t=input(message)
本书是DIPUM的第二版,编者Rafael C.Gonzalez。 共压缩成三部分。 注意,需Part1-Part3 三部分都下载了才能解压缩。 (提醒:本书为扫描版,不算清楚,但是也来之不易) For Image and Computer Vision, Image Processing, and Computer Vision courses. This is the first text that provides a balanced treatment of image processing fundamentals and an introduction to software principles used in the practical application of image processing. A seamless integration of material from the leading text, Digital Image Processing by Gonzalez and Woods and the Image Processing Toolbox from Mathworks, Inc. This text works in the MATLAB computing environment; the Toolbox provides a stable, well-supported set of software tools capable of addressing a broad spectrum of applications in digital image processing. The major areas covered include intensity transformations, linear and nonlinear spatial filtering, filtering in the frequency domain, image restoration and registration, color image processing, wavelets, image data compression, morphological image processing, image segmentation, regions and boundary representation and description, and object recognition. From the Back Cover Digital Image Processing Using MATLAB is the first book that provides a balanced treatment of image processing fundamentals and the software principles used in their practical implementation. The book integrates material from the leading text, Digital Image Processing by Gonzalez and Woods, and the Image Processing Toolbox of the MathWorks. Inc., a recognized leader in scientific computing. The Image Processing Toolbox provides a stable, well-supported set of software tools for addressing a broad range of applications in digital image processing. A unique feature of this hook is its emphasis on showing how to enhance those tools by the development of new code. This is important in image processing, where there is a need for extensive experimental work in order to arrive at acceptable problem solutions. After an introduction to the fundamentals of MATLAB programming, the book addresses the mainstream areas of image processing. Areas covered include intensity transformations, linear and nonlinear spatial filtering, filtering in the frequency domain, image restoration and registration, color image processing, wavelets, image data compression, morphological image processing, image segmentation, regions and boundary representation and description, and object recognition.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值