版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Image Acquisition and Processing by Matlab第 PAGE 55页CONTENTSBasic Image Acquisition Procedure图像采集工具箱重要图解Image Types and Converting 图像类型及其转换Displaying and Exploring Images 图像显示Spatial Transformations 图像的几何运算Image Registration 图像的对齐Designing and Implementing 2-D Linear Filters for Image Data 二维滤波器Tran
2、sforms 图像的变换Morphological Operations 形态学运算Analyzing and Enhancing Images 图像分析和增强ROI-Based Processing 图像分区域处理Image Deblurring 图像复原Color 色彩空间Neighborhood and Block Operations 邻域运算Function ReferenceBasic Image Acquisition ProcedureStep 1硬件安装Step 2获取信息 imaqhwinfo InstalledAdaptors: coreco winvideo MATLA
3、BVersion: 7.9 (R2009b) ToolboxName: Image Acquisition Toolbox ToolboxVersion: 3.4 (R2009b) imaqhwinfo(winvideo) AdaptorDllName: C:.toolboximaqimaqadaptorswin32mwwinvideoimaq.dll AdaptorDllVersion: 3.4 (R2009b) AdaptorName: winvideo DeviceIDs: 1DeviceInfo: 1x1 struct imaqhwinfo(winvideo,1) DefaultFor
4、mat: RGB24_320 x240 DeviceFileSupported: 0 DeviceName: USB PC Camera DeviceID: 1 ObjectConstructor: videoinput(winvideo, 1)SupportedFormats: 1x6 cell dev_info.SupportedFormatsRGB24_160 x120 RGB24_176x144 RGB24_320 x240RGB24_352x288 RGB24_640 x480 RGB24_800 x600 dev_info.SupportedFormats(6)RGB24_800
5、x600Step 3创建video input对象 vid = videoinput(winvideo,1,RGB24_800 x600)Summary of Video Input Object Using USB PC Camera . Acquisition Source(s): input1 is available. Acquisition Parameters: Trigger Parameters: 1 immediate trigger(s) on START. Status: .Step 4(optional)预览视频流 preview(vid) closepreview(v
6、id)Step 5(optional)配置对象属性 get(vid) General Settings: DeviceID = , DiskLogger = , DiskLoggerFrameCount = 0 EventLog = 1x0 struct, FrameGrabInterval = 1, FramesAcquired = 0 FramesAvailable = 0, FramesPerTrigger = 10, Logging = off LoggingMode = memory, Name = RGB24_800 x600-winvideo-1 NumberOfBands =
7、3, Previewing = off, ROIPosition = 0 0 800 600 Running = off, Tag = , Timeout = 10, Type = videoinput, UserData = VideoFormat = RGB24_800 x600, VideoResolution = 800 600 Color Space Settings: BayerSensorAlignment = grbg, ReturnedColorSpace = rgb Callback Function Settings: ErrorFcn = imaqcallback, F
8、ramesAcquiredFcn = FramesAcquiredFcnCount = 0, StartFcn = , StopFcn = , TimerFcn = TimerPeriod = 1, TriggerFcn = Trigger Settings: InitialTriggerTime = , TriggerCondition = none, TriggerFrameDelay = 0 TriggerRepeat = 0, TriggersExecuted = 0, TriggerSource = none TriggerType = immediate Acquisition S
9、ources: SelectedSourceName = input1, Source = 1x1 videosource get(getselectedsource(vid) General Settings: Parent = 1x1 videoinput, Selected = on, SourceName = input1, Tag = Type = videosource Device Specific Properties: BacklightCompensation = on, Brightness = 20, ColorEnable = on, Contrast = 20 Ex
10、posure = 1, FrameRate = 30.0000, Gamma = 4, Hue = 18Saturation = 50, Sharpness = 3 set(vid,TriggerRepeat,Inf); vid.FrameGrabInterval = 5; vid_src = getselectedsource(vid); set(vid_src,Tag,motion detection setup);Step 6获取图像数据 start(vid) data=getdata(vid,6); stop(vid)Step 7清理 delete(vid) clear close(g
11、cf)图像采集工具箱重要图解The Image Acquisition Toolbox Software ComponentsRelationship of Video Input Objects and Video Source ObjectsTransitions from Running to Stopped StatesLogging State TransitionsOverview of Data LoggingImmediate TriggerManual TriggerHardware TriggerSpecifying the Amount of Data to LogImp
12、act of FrameGrabInterval on Data LoggingFrames Available After Initial Trigger ExecutionContents of Memory Buffer Before and After Removing FramesSpecifying a Delay Before Data Logging BeginsExecuting Multiple TriggersUsing wait to Block the MATLAB Command LineDelete a triggers worth of image data (
13、The frames acquired before and after the call to flushdata)Logging Data to a Disk FileOverview of Image Acquisitiongetdata Blocks Until Frames Become AvailableFrames Returned by peekdataFormat of an Individual FrameInitialTriggerTime Records First Trigger ExecutionImage Types and Converting 图像类型及其转换
14、ditherDithering(抖动)是Gif压缩中一项十分有用的技术。由于GIF 和PNG只有256种颜色,因此,在表现一些含有丰富色彩信息的照片图像或含有平缓过度色的图像时,就会出现梯田状的条形色块,这时,我们就需要用到Dithering(抖动)功能,Dithering可以模仿一些在调色板无法找到的颜色,从而使得整个图像颜色与颜色之间的过渡更为自然,不过,Dithering同样会使图像Size变大,因此,我们更多的将这项技术应用于区域压缩。demosaicConvert Bayer pattern encoded image (与相机RAW格式相关) to truecolor (RGB)
15、image.类型转换gray2ind,grayslice,im2bw,ind2gray,ind2rgb,mat2gray,rgb2gray,rgb2indImage class 转换im2uint8, im2uint16, im2int16, im2single, or im2doubleimapprox索引图像转换可能使用,Approximate indexed image using one with fewer colorsImage Arithmetic Saturation RulesValues that exceed the range of the integer type a
16、re saturated to that range如300255,-450Fractional values are roundedDICOMDICOM(Digitalimaging and Communications in Medicine)即数字影像和通信标准,规范医学影像及其相关信息的交换。由美国发射学会和美国国家电器制造商协会NEMA(National Electronical Manufacturers Association)制定。从文件格式上看,用于保存医学数据的DICOM包容的信息量大(除图像信息外,还有很多附加信息,比如患者病例档案等),格式复杂。DICOM的压缩算法种类
17、很多,也可以保存动画图像DICOM的图像基本都是与医学相关的(MRI,CT等),医学图像的特点是分辨率低,特征不清晰等等。对这类图像做分割和特征提取难度较大。Mayo Analyze 7.5A file format, developed by the Mayo Clinic, for storing MRI(Magnetic Resonance Imaging核磁共振成像) data,包含两个文件.hdr和.img。Interfile为了使核医学图像和信息能在不同系统上共享,传递以前将各系统的文件转换成统一的Interfile文件格式。转换后的图像和文件,就可以在不同厂商的计算机上进行图像传
18、递。High Dynamic Range ImagesDynamic range refers to the range of brightness levels, using 32-bit floating-point values to store each color channel. hdrread,makehdr,tonemap(HDR-RGB),hdrwriteDisplaying and Exploring Images 图像显示Displaying Images Using the imshow FunctionImage Displayed in a Figure Windo
19、w by imshow imshow(moon.tif); I = getimage; % assigns the image data from the figure window currently activeSpecifying the Initial Image Magnification imshow(I, InitialMagnification, 150)Image Displayed With and Without a Border imshow(I,Border,tight) % tight|looseDisplaying Each Image in a Separate
20、 Figure figureDisplaying Multiple Images in the Same Figure subplot(m,n,p) subplot(1,2,1), imshow(I1)Using imtool to Explore ImagesOpening the Image Tool imtool(moon.tif);Specifying the Initial Image MagnificationSpecifying the ColormapImporting Image Data from the WorkspaceExporting Image Data to t
21、he WorkspaceSaving the Image Data Displayed in the Image ToolClosing the Image Tool imtool close allExploring Very Large ImagesCreate reduced resolution data set (R-Set) from image file rsetfile = rsetwrite(File_Name) rsetfile = rsetwrite(File_Name, output_filename)File_Name is a TIFF or NITF image
22、fileViewing Image Sequences 查看图像序列Viewing Image Sequences in the Movie Player load mristack % implay(mristack)Viewing Image Sequences as a Montage I=reshape(mristack,256 256 1 21); % repmat may be used montage(I)Converting a Multiframe Image to a Movie I=reshape(mristack,256 256 1 21); mov = immovie
23、(I); implay(mov)Displaying Different Image Types (imshow和imtool可替换)Displaying Grayscale Images That Have Unconventional Ranges imshow(I,DisplayRange,low high) imtool(I,DisplayRange,);Changing the Display Colors of a Binary Image imshow(BW) imshow(BW,1 0 0; 0 0 1)Adding a Colorbar to a Displayed Imag
24、e colorbarSetting Toolbox PreferencesViewing and Changing Preferences Using the Preferences Dialog Boxselect Preferences Image Processing in the File menuRetrieving the Values of Toolbox Preferences Programmatically iptgetpref(ImtoolInitialMagnification)Setting the Values of Toolbox Preferences Prog
25、rammatically iptsetpref(ImshowBorder, tight);Spatial Transformations 图像的几何运算基本运算Resizing I1 = imresize(I,1.25); X1 = imresize(X,100 150,bilinear)Rotating I1 = imrotate(I,35,bilinear);Cropping I1 = imcrop(I); I1 = imcrop(I,60 40 100 90);Performing General 2-D Spatial TransformationsOverview of Genera
26、l 2-D Spatial Transformation ProcessExample: Performing a TranslationStep 1: Import the Image to Be Transformed I = checkerboard; % Step 2: Define the Spatial Transformation xform = 1 0 0; 0 1 0; 40 40 1 ;Step 3: Create the TFORM Structure tt = maketform(affine,xform);Step 4: Perform the Transformat
27、ion I1 x1 y1= imtransform(I,tt);Step 5: View the Output ImageAffine Transform仿射变换是一种二维坐标到二维坐标之间的线性变换,保持二维图形的“平直性”(straightness,即变换后直线还是直线不会打弯,圆弧还是圆弧)和“平行性”(parallelness,其实是指保二维图形间的相对位置关系不变,平行线还是平行线,相交直线的交角不变。)。仿射变换可以通过一系列的原子变换的复合来实现,包括:平移(Translation)、缩放(Scale)、翻转(Flip)、旋转(Rotation)和错切(Shear)。Creati
28、ng TFORM StructuresTransformation Type: affine,projective,box,custom,compositePerforming N-Dimensional Spatial Transformations maketform makeresampler imtransform其它:fliptform,tformfwd,tforminv,findbounds,tformarrayImage Registration 图像的对齐A graphic illustration of the image registration processExampl
29、e: Performing a registrationStep 1: Read the ImagesStep 2: Choose Control Points in the Images by cpselect I0=imread(westconcordorthophoto.png); % base I1=imread(westconcordaerial.png); % input cpselect(I1, I0)Step 3: Save the Control Point Pairs to the MATLAB Workspace点击File-Export Points to Worksp
30、ace,得到base_points input_pointsStep 4: Fine-Tune the Control Point Pair Placement (Optional) INPUT_POINTS = cpcorr(input_points,base_points,I1,I0)Step 5: Specify the Type of Transformation and Infer Its Parameters mytform = cp2tform(INPUT_POINTS, base_points, projective)Step 6: Transform the Unregist
31、ered Image Ir = imtransform(I1, mytform);查看对齐效果 imshow(Ir) hold on h = imshow(I0, gray(256); set(h, AlphaData, 0.6)cp2tform Transformation Typesnonreflective similarityaffineprojectivepolynomialpiecewise linearlwm (local weighted mean)Designing and Implementing 2-D Linear Filters for Image Data 二维滤波
32、器Designing and Implementing Linear Filters in the Spatial DomainConvolution 卷积Step 1: Rotate the convolution kernel 180 degrees about its center element.Step 2: Slide the center element of the convolution kernel so that it lies on top of the (2,4) element of A.Step 3: Multiply each weight in the rot
33、ated convolution kernel by the pixel of A underneath.Step 4: Sum the individual productsCorrelation 相关不旋转kernel,其余与卷积相同Performing Linear Filtering of Images Using imfilter I1 = imfilter (I0, h)default method:相关Boundary Padding:default(the value x=0,即zero padding), x,replicate,symmetric,circularRelat
34、ionship to Other Filtering Functionsfilter2二维相关,cov2二维卷积,covn-n维卷积,这些函数与imfilter在于它们的输出数据类型一定是double,并使用zero paddingFiltering an Image with Predefined Filter Types by fspecial average averaging filter disk circular averaging filter gaussian Gaussian lowpass filter laplacian filter approximating the
35、2-D Laplacian operator log Laplacian of Gaussian filter motion motion filter prewitt Prewitt horizontal edge-emphasizing filter sobel Sobel horizontal edge-emphasizing filter unsharp unsharp contrast enhancement filterDesigning Linear Filters in the Frequency Domain FIR FiltersFIR (finite impulse re
36、sponse) filters have a finite extent to a single point, or impulse. All the Image Processing Toolbox filter design functions return FIR filters.Frequency Transformation Methodftrans2 transforms a one-dimensional FIR filter into a two-dimensional FIR filterdefault method:produces filters with nearly
37、circular symmetryFrequency Sampling Methodfsamp2 returns a filter h with a frequency response that passes through the points in the input matrix Hd Hd = zeros(11,11); Hd(4:8,4:8) = 1; % 构造阶跃平台 h = fsamp2(Hd); % Hd-h转换 freqz2(h) % 显示滤波器频谱缺点:Ripples波纹Windowing Methodfwind1 designs a 2D filter by using
38、 a 2D window that it creates from one or two 1D windows that you specify. fwind2 designs a 2D filter by using a specified 2D window directly.Creating the Desired Frequency Response Matrixfreqspace returns correct, evenly spaced, frequency values for any size response. f1,f2 = freqspace(25,meshgrid);
39、 Hd = zeros(25,25); d = sqrt(f1.2 + f2.2) Hd(d) = 1; mesh(f1,f2,Hd)For this frequency response, the filters produced by fsamp2, fwind1, and fwind2 are real. This result is desirable for most image processing applications.Transforms 图像的变换Discrete Fourier Transform卷积的计算 ifft2(fft2(A).*fft2(B)卷积定理:两个二维
40、连续函数在空间域中的卷积可求其相应的二个傅立叶变换乘积的反变换而得,即 f(x,y) 卷积 h(x,y) F(u,v) H(u,v) 卷积满足交换律,是线性运算,还满足分配律、结合律相关的计算real(ifft2(fft2(bw).*fft2(rot90(a,2),256,256)与卷积的区别,Kernel图像要先旋转180度Discrete Cosine TransformDCT相当于长度是它两倍的离散傅里叶变换,这个离散傅里叶变换是对一个实偶函数进行的(因为一个实偶函数的傅里叶变换仍然是一个实偶函数)DCT经常被信号处理和图像处理使用,用于对信号和图像(JPEG和MPEG等)进行有损数据压
41、缩。当信号具有接近Markov processes的统计特性时,DCT的去相关性接近于具有最优的去相关性的Karhunen-Love(K-L)变换的性能。 The DCT Transform Matrix 本方法适用于small square imputs,如8x8,16x16dctmtx makes discrete cosine transform matrixT*I*T 等价于 dct2(I) % T=dctmtx(size(I,1),I是正方形图像Radon Transform R,xp = radon(I,theta); IR = iradon(R,theta);点光源投影变换 fa
42、nbeam和ifanbeamMorphological Operations 形态学运算Dilation and Erosion 膨胀和腐蚀CommandOperation RulePadding Rule膨胀imdilateThe value of the output pixel is the maximum value of all the pixels in the input pixels neighborhood. Pixels beyond the image border are assigned the minimum value afforded by the data t
43、ype. Generally, these pixels are set to 0. 腐蚀imerodeThe value of the output pixel is the minimum value of all the pixels in the input pixels neighborhood. Pixels beyond the image border are assigned the maximum value afforded by the data type. BW: set to 1. uint8 grayscale images: set to 255.Structu
44、ring Elements: a matrix consisting of only 0s and 1s that can have any arbitrary shape and size. The pixels with values of 1 define the neighborhood.SE = strel(arbitrary, NHOOD)SE = strel(arbitrary, NHOOD, HEIGHT)SE = strel(ball, R, H, N)SE = strel(diamond, R)SE = strel(disk, R, N)SE = strel(line, L
45、EN, DEG)SE = strel(octagon, R)SE = strel(pair, OFFSET)SE = strel(periodicline, P, V)SE = strel(rectangle, MN)SE = strel(square, W)Object methods: getheight, getnhood, getsequence, isflat, reflect, translateDilating or Eroding an Image SE = strel(square,3); BW2 = imdilate(BW,SE); or BW2 = imerode(BW1
46、,SE);Combining Dilation and Erosion Morphological opening: erode then dilate Skeletonization: BW2 = bwmorph(BW1,skel,Inf); Perimeter determination确定周界: BW2 = bwperim(BW1); 其它:bwhitmiss(binary hit-miss operation),imclose,imopen,imtophat(top-hat filtering),imbothat(bottom-hat filtering)Morphological R
47、econstruction 形态重构Morphological reconstruction is based on morphological dilation, but its processing:based on two images, a marker and a mask, rather than one image and a structuring element.based on the concept of connectivity, rather than a structuring element.repeats until stability; i.e., the i
48、mage no longer changes.Pixel Connectivity2-D Connectivities4-connectedPixels are connected if their edges touch. This means that a pair of adjoining pixels are part of the same object only if they are both on and are connected along the horizontal or vertical direction.8-connectedPixels are connecte
49、d if their edges or corners touch. This means that if two adjoining pixels are on, they are part of the same object, regardless of whether they are connected along the horizontal, vertical, or diagonal direction.3-D Connectivities6-connectedPixels are connected if their faces touch.18-connectedPixel
50、s are connected if their faces or edges touch.26-connectedPixels are connected if their faces, edges, or corners touch.Custom Connectivities: define custom neighborhoods by specifying a 3-by-.-by-3 array of 0s and 1s.Flood-Fill Operationsimfill(BW,4 3,8) % 4 3-Specifying the Starting Point, 8-Specif
51、ying ConnectivityI1 = imfill(I,holes); % Filling HolesFinding Peaks and Valleysimregionalmaximregionalminidentify all regional minima or maximaimextendedmaximextendedminidentify regional minima or maxima that are greater than or less than a specified thresholdimhmaximhminremove the less significant
52、minima and maxima but retain the significant minima and maximaimimposeminemphasize specific minima (dark objects) in an imageDistance Transform 距离变换bwdist: Distance transform of binary imageD给出BW每一像素离其最近非零像素的距离,L则是对应非零像素的一维下标D = bwdist(BW)D,L = bwdist(BW)D,L = bwdist(BW,method) method: Euclidean(def
53、ault),City Block,Chessboard,Quasi-EuclideanLabeling and Measuring Objects in a Binary ImageLabeling Objects in a Binary Imagebwconncomp computes connected components BW=logical(zeros(8,9); BW(2:4,2:3)=1 BW(5:7,5:6)=1 BW(2:3,7:9)=1, BW(3,7)=0 cc = bwconncomp(BW) Connectivity: 8ImageSize: 8 9NumObject
54、s: 3PixelIdxList: 6x1 double 6x1 double 5x1 doublelabelmatrix construct a label matrix labeled = labelmatrix(cc)Original imageLabeled image illustrationbwlabel, bwlabeln: 过时的函数,效果同bwconncompSelecting Objects in a Binary Image imshow(BW) BW2 = bwselectFinding the Area of the Foreground of a Binary Im
55、age bwarea(BW) % = 17.1250Finding the Euler Number of a Binary Image欧拉数: the total number of objects in the image minus the number of holes in those objectsbweuler(BW) % = 3Lookup Table Operations lut = makelut(fun,n) % makelut creates lookup tables for 2-by-2 and 3-by-3 neighborhoods BW2 = applylut
56、(BW1,lut);Analyzing and Enhancing Images 图像分析和增强Getting Information about Image Pixel Values and Image StatisticsGetting Image Pixel Values Using impixelCreating an Intensity Profile of an Image Using improfileDisplaying a Contour Plot of Image Data C,h=imcontour(I,3); % Create contour plot of image
57、 data clabel(C,h) % Contour plot elevation labelsCreating an Image Histogram Using imhistGetting Summary Statistics About an Imagemean2, std2, and corr2(相关系数,对应一维的corrcoef)Computing Properties for Image Regionsregionprops:Measure properties of image regionsAnalyzing ImagesDetecting Edges Using the e
58、dge Function 边缘检测sobel,prewitt,robertslog(Laplacian of Gaussian method),zerocrosscanny(for weak edges)Detecting Corners Using the cornermetric Function C = cornermetric(I, SensitivityFactor, 0.24); corner_peaks = imregionalmax(C); imshow(I); y, x = find(corner_peaks); hold on, plot(x, y, r.), hold o
59、ffTracing Object Boundaries in an Image 物体边缘追踪bwtraceboundarybwboundariesDetecting Lines Using the Hough Transform 直线检测houghhoughpeakshoughlinesAnalyzing Image Homogeneity Using Quadtree DecompositionS = qtdecomp(I,0.27); % S大小与I相同,数据类型为double,属性为sparseAnalyzing the Texture of an Image 纹理分析Using Tex
60、ture Filter FunctionsrangefiltstdfiltentropyfiltUsing a Gray-Level Co-Occurrence Matrix (GLCM)graycomatrix: calculating how often a pixel with the gray-level value i occurs in a specific spatial relationship to a pixel with the value jgraycoprops: Properties of gray-level co-occurrence matrixAdjusti
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 二零二五年度粮油产业园区物业管理合同范文电子版
- 科技金融中客户关系维护与风险控制策略
- 特殊天气条件下的学生户外活动安全管理
- 小学数学教育与办公效率提升
- 高端住宅的室内空间规划与设计思路
- 打造高效的小微企业金融服务体系研究
- 科技行业防火安全管理探讨与实践
- 能源行业客户群体需求分析与策略制定
- 金融服务行业客服服务流程的智能化转型
- 跨文化家庭的和谐沟通实践
- 2024年计算机二级WPS考试题库380题(含答案)
- 面试官面试技巧(精简版)课件
- 中央空调节能改造方案
- 高校图书馆服务
- 环卫一体化运营方案
- 科技进步类现代轨道交通综合体设计理论与关键技术公
- 源代码审计报告模板
- 干式变压器知识大全课件
- 重大危险源公示牌(完整)-2
- 初一英语英语阅读理解专项训练15篇
- 高中地理学情分析方案和报告
评论
0/150
提交评论