




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、1Chapter 2 fundamentals2 MATLAB is a high-performance language for technical computing. It integrates computation, visualization, and programming in an easy-to-use environment where problems and solutions are expressed in familiar mathematical notation. Typical uses include the following: Math and c
2、omputationAlgorithm developmentData acquisitionModeling, simulation, and prototypingData analysis, exploration, and visualizationScientific and engineering graphicsApplication development, including graphical user interface building Introduction of matlab3 MATLAB is complemented by a family of appli
3、cation specific solutions called toolboxes. The IPT is a collection of MATLAB functions(called M-functions or M-files) that extend the capability of the MATLAB environment for the solution of DIP problems. Other toolboxes that sometimes are used to complement IPT are the Signal Processing, Neural Ne
4、twork, Fuzzy Logic, and Wavelet Toolboxes. Introduction of matlab42.1 The matlab working environment5MATLAB坐標定義習慣6F=imread(filename); %filename is a string containing the complete name of the image file(including any applicable extension). If filename contains no path information, then it means the
5、file in the current working directory.2.2 Reading, Displaying and writing Images7Function size: M N= size(f);Function whos: whos fFunction imshow: imshow(f, G)Where f is an image array, and G is the number of intensity levels used to display it. If G is omitted, it defaults to 256 levels. Using the
6、syntax imshow(f, low high)Displays as black all values less than or equal to low, and as white all values greater than or equal to high. f=imread(圖片room.bmp); m n=size(f); figure(1),imshow(f)8910Function imwrite: imwrite(f, filename); A more general imwrite syntax applicable only to JPEG image is: i
7、mwrite(f, filename.jpg, quality, q);Where q is an integer between 0 to 100( the lower the number the higher the degradation due to jpeg compression). imwrite(f,f:f1.bmp); f=imread(圖片bubbles.bmp); imwrite(f,f:bubbles25.jpg,quality,25); figure(1),subplot(2,2,1),imshow(f:bubbles25.jpg) imwrite(f,d:bubb
8、les5.jpg,quality,5); subplot(2,2,2), imshow(d:bubbles5.jpg)1112Function imfinfo: imfinfo(filename)How to compute the compression ratio for bubbles25.jpg? k=imfinfo(f:bubbles25.jpg); image_bytes=k.Width*k.Height*k.BitDepth/8; compressd_bytes=k.FileSize; compress_ratio=image_bytes/compressd_bytescompr
9、ess_ratio = 29.9839imfinfo moon.jpg13Function imwrite:A more general imwrite syntax applicable only to tif image has the form: imwrite(f, filename.tif, compression,parameter, resolution, colres rowres);parameter = none indicates no compression;= packbits indicates packbits compression(the default fo
10、r nonbinary image);= ccitt indicates ccitt compression(the default for binary image);colres rowres contains two integers that give the column resolution and row resolution in dots-per-unit(the default values are 72 72).Specifying the resolution by a single scalar,res, is equvilent to writing res res
11、.14Figure 2.5(a) is an 8-bit X-ray image of a circuit board generated during quality inspection. It is in jpg format, at 200 dpi(點每英寸) .The image is of size 450*450 pixels, so its dimentions are 2.25*2.25 inches. We want to store this image in tif format, with no compression, under the name sf. In a
12、ddition, we want to reduce the size of the image to 1.5*1.5 inches while keeping the pixels count at 450*450. The following statement yields the desired result: f=imread(圖片circuit.jpg); imwrite(f,sf.tif,compression,none,resolution,300 300); imshow(sf.tif)15162.3Data Classes 17Image typesThe toolbox
13、supports four types of images: Intensity image Binary image Indexed image RGB imageAn intensity image is a data matrix whose values have been scaled to represent intensities.A binary image is a logical array of 0s and 1s.18Converting between Data Classes B=data_class_name(A)Where data_class_name is
14、one of the names in the first column of table 2.2.B=double(A)A: an array of class uint8.B: a double-precision array.2.4 Converting between Data Classes and Image types19Converting between Image Classes and typesThe toolbox provides specific functions that perform the scaling necessary to convert bet
15、ween image classes and types.20 f=-0.5 0.5;0.75 1.5; g=im2uint8(f)g = 0 128 191 25521Mat2grayFunction:Convert a matrix to a grayscale intensity image.Syntax:I = mat2gray(A,amin amax)I = mat2gray(A)I = mat2gray(A,amin amax) converts the matrix A to the intensity image I. The returned matrix I contain
16、s values in the range 0 (black) to 1.0 (full intensity or white). amin and amax are the values in A that correspond to 0 and 1.0 in I. I = mat2gray(A) sets the values of amin and amax to the minimum and maximum values in A.22Example f=1 2;3 4f = 1 2 3 4 g=mat2gray(f)g = 0 0.3333 0.6667 1.0000 gb=im2
17、bw(g,0.6)gb = 0 0 1 1 gb=f2gb = 0 0 1 1 gbv=islogical(gb)gbv = 1 gbd=im2double(gb)gbd = 0 0 1 1 gbd=im2double(im2bw(mat2gray(f),0.6)gbd = 0 0 1 123Vector Indexing a row vector: an array of dimention 1*N v=1 3 5 7 9v = 1 3 5 7 9 w=v. v(1:3) v(1:end) v(1:2:end) v(end:-2:1)2.5 Array Indexing 2425 f=imr
18、ead(pout.tif); fp=f(end:-1:1,:); subplot(2,2,1),imshow(f) subplot(2,2,2),imshow(fp) fc=f(20:100,20:120); fs=f(1:2:end,1:2:end); subplot(2,2,3),imshow(fc) subplot(2,2,4),imshow(fs) plot(f(20,:)2626 Some Important Standard ArraysZeros(M,N) 0s of class doubleones(M,N) 1s of class doubletrue(M,N) logica
19、l matrix of 1sfalse(M,N) logical matrix of 0smagic(N) returns an n-by-n matrix constructed from the integers 1 through n2 with equal row and column sums. The order n must be a scalar greater than or equal to 3.M = magic(3)27Rand(M,N) numbers in the interval 0,1Randn(M,N) gaussian2827 Introduction to
20、 M-Function Programming M-files 函數M-files 腳本M-filesSo-called M-files in MATLAB can be scripts that simply execute a series of MATLAB statements, or they can be functions that can accept arguments and can produce one or more outputs. 29 M-files are created using a text editor and are stored with a na
21、me of the form filename.m. The components of function M-files are:The function definition line :一般只有函數m-文件才具有The H1 line:the first help text line用于lookfor查詢Help text: 解釋m文件實現的功能The function bodyCommentsExample:Script M-files Myprime.mExample: function M-files30Function 輸出變量函數名稱(輸入變量)語句;end;M腳本文件沒有參數
22、傳遞功能,但M函數文件有此功能。M函數文件的格式有嚴格規定,它必須以“ function ”開頭,其格式如下:31函數文件與命令文件的主要區別在于 :1.函數文件一般都要帶參數,都要有返回結果,而命令文件沒有參數與返回結果2.函數文件的變量是局部變量,運行期間有效,運行完畢就自動被清除,而命令文件的變量是全局變量,執行完畢后仍被保存在內存中3.函數文件要定義函數名,且保存該函數文件的文件名必須是函數名.m。M函數文件可以有多個因變量和多個自變量,當有多個因變量時用 括起來。32operators Matlab operators logical operatorsarithmetic oper
23、ators relational operatorsP43 Eg.2.6P43 Eg.2.7P43 Eg.2.8, 2.9333435圖像的疊加函數imadd I=imread(rice.png); J=imread(cameraman.tif); K=imadd(I,J,uint16); imshow(K,)圖像的求補函數imcomplement BW=imread(text.png); BW2=imcomplement(BW); subplot(1,2,1),imshow(BW) subplot(1,2,2),imshow(BW2)線性組合函數imlincomb其使用格式如下:Z= iml
24、incomb(K1,A1,k2,A2,kn,An)Z= imlincomb(K1,A1, ,kn,An,K)36下例對圖形進行符合下列公式的線性組合操作:K(r,c)=I (r,c)-J (r,c)+128 I=imread(cameraman.tif); J=uint8(filter2(fspecial(gaussian),I); K=imlincomb(1,I,-1,J,128); subplot(1,2,1),imshow(J) subplot(1,2,2),imshow(K)37Flow control38Code optimizationMatlab is a programming
25、 language specifically designed for array operations.To increase the computational speed.Two approaches for it1、Vectorizing loops convert for and while loops to equivalent vector or matrix operations P5539 function meshgrid: Generate X and Y matrices for three-dimensional plots X,Y = meshgrid(x,y) transforms the domain specified by vectors x and y into arrays X and Y, which can be used to evaluate functions of two variables and three-dimensional mesh/surface plots. The rows of the output array X are copies of the vector x; columns of the outpu
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 安徽黃梅戲藝術職業學院《國際貿易實務仿真》2023-2024學年第二學期期末試卷
- 保山職業學院《傳統建筑環境營造理論與方法》2023-2024學年第二學期期末試卷
- 北京協和醫學院《教育技術與應用理論教學》2023-2024學年第二學期期末試卷
- 大連藝術學院《動畫分鏡頭》2023-2024學年第二學期期末試卷
- 蘇州健雄職業技術學院《金融科技概論》2023-2024學年第二學期期末試卷
- 喀什職業技術學院《英語閱讀與翻譯》2023-2024學年第二學期期末試卷
- 百色學院《現場管理》2023-2024學年第二學期期末試卷
- 湖北三峽職業技術學院《教育科研方法與論文撰寫》2023-2024學年第二學期期末試卷
- 皖江工學院《雕塑基礎》2023-2024學年第二學期期末試卷
- 湘潭大學《品牌與形象設計》2023-2024學年第二學期期末試卷
- 夏季極端天氣安全教育
- 《網絡與新媒體廣告(第2版)》 課件 第7章 新媒體廣告的設計
- 《智能優化算法解析》 課件 第5章-基于人類行為的智能優化算法
- 2025河南鄭州航空港科創投資集團有限公司“領創”社會招聘40人筆試參考題庫附帶答案詳解
- 2025寧夏固原農村電力服務限公司社會招聘(約22人)自考難、易點模擬試卷(共500題附帶答案詳解)
- 2025年上半年廣西玉林市總工會招聘編外工作人員7人易考易錯模擬試題(共500題)試卷后附參考答案
- 全國統一旅游電子合同編號查詢
- 人工智能與教育創新的結合心得體會
- 1.2治國安邦的總章程 教案 -2024-2025學年統編版道德與法治八年級下冊
- 深部煤層氣勘探開發關鍵實驗技術及發展方向
- 醫療護理醫學培訓 簡易呼吸氣囊的使用
評論
0/150
提交評論