实验二 图像分割与边缘检测 一.实验目的及要求 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 al