实验二 图像分割与边缘检测 一.实验目的及要求 1.利用MATLAB 研究图像分割与边缘检测的常用算法原理; 2.掌握MATLAB 图像域值分割与边缘检测函数的使用方法; 3.了解边缘检测的算法和用途,比较Sobel、Prewitt、Canny等算子边缘检测的差异。 二、实验内容 (一)研究以下程序,分析程序功能;输入执行各命令行,认真观察命令执行的结果。熟悉程序中所使用函数的调用方法,改变有关参数,观察试验结果。 1 .图像阈值分割 clear all, close all; I = imread('rice.tif'); figure (1),imshow(I) figure(2); imhist(I) T=120/255; Ibw1 = im2bw(I,T); %选择阈值T=120/255 对图像二值化; figure(3); subplot(1,2,1), imshow(Ibw1); T=graythresh(I); %采用Otsu 方法计算最优阈值T对图像二值化; L = uint8(T*255) Ibw2 = im2bw(I,T); subplot(1,2,2), imshow(Ibw2); help im2bw; help graythresh; (令T取不同值,重做上述试验,观察试验结果) 以下是程序执行结果: Comand 窗口: L = 125 IM2BW Convert image to binary image by thresholding. IM2BW produces binary images from indexed, intensity, or RGB images. To do this, it converts the input image to grayscale format (if it is not already an intensity image), and then converts this grayscale image to binary by thresholding. The output binary image BW has values of 0 (black) for all pixels in the input image with luminance less than LEVEL and 1 (white) for all other pixels. (Note that you specify LEVEL in the range [0,1], regardless of the class of the input image.) BW = IM2BW(I,LEVEL) converts the intensity image I to black and white. BW = IM2BW(X,MAP,LEVEL) converts the indexed image X with colormap MAP to black and white. BW = IM2BW(RGB,LEVEL) converts the RGB image RGB to black and white. Note that the function GRAYTHRESH can be used to compute LEVEL automatically. Class Support ------------- The input image can be of class uint8, uint16, or double. The output image BW...