实验 四 图像分割与边缘检测 一.实验目的及要求 1.利用MATLAB 研究图像分割与边缘检测的常用算法原理; 2.掌握MATLAB 图像域值分割与边缘检测函数的使用方法; 3.了解边缘检测的算法和用途,比较Sobel、Prewitt、Canny等算子边缘检测的差异。 二、实验内容 (一)研究以下程序,分析程序功能;输入执行各命令行,认真观察命令执行的结果。熟悉程序中所使用函数的调用方法,改变有关参数,观察试验结果。 1 .图像阈值分割 clear all, close all; I = imread('cameraman.tif'); figure (1),imshow(I) figure(2); imhist(I) T=120/255; Ibw1 = im2bw(I,T); figure(3); subplot(1,2,1), imshow(Ibw1); T=graythresh(I); L = uint8(T*255) Ibw2 = im2bw(I,T); subplot(1,2,2), imshow(Ibw2); help im2bw; help graythresh; clear all, close all; I = imread('cameraman.tif'); figure (1),imshow(I) figure(2); imhist(I) T=240/255; Ibw1 = im2bw(I,T); figure(3); subplot(1,2,1), imshow(Ibw1); T=graythresh(I); L = uint8(T*255) Ibw2 = im2bw(I,T); subplot(1,2,2), imshow(Ibw2); help im2bw; help graythresh; clear all, close all; I = imread('cameraman.tif'); figure (1),imshow(I) figure(2); imhist(I) T=120/255; Ibw1 = im2bw(I,T); figure(3); subplot(1,2,1), imshow(Ibw1); T=graythresh(I); L = uint8(T*255) Ibw2 = im2bw(I,T); subplot(1,2,2), imshow(Ibw2); help im2bw; help graythresh; 2 .边缘检测 clear all, close all; I = imread('moon.tif'); BW1 = edge(I,'sobel'); BW2 = edge(I,'canny'); BW3 = edge(I,'prewitt'); BW4 = edge(I,'roberts'); BW5 = edge(I,'log'); figure(1), imshow(I), title('Original Image'); figure(2), imshow(BW1), title('sobel'); figure(3), imshow(BW2), title('canny'); figure(4), imshow(BW3), title('prewitt'); figure(5), imshow(BW4), title('roberts'); figure(6), imshow(BW5), title('log'); help edge edgedemo (二)利用 MATLAB 熟悉并验证其它图像分割方法 灰度阈值分割: I=imread('C:\Users\Administrator\Desktop\rice.jpg'); I=rgb2gray(I); I2=im2bw(I); figure,imshow(I2); I2=im2bw(...