clcclear allf_rgb=imread('leaf/RGB/2. Salix atrocinerea/iPAD2_C02_EX08.jpg');subplot(221)imshow(f_rgb);title '叶子彩色图'f_gray=rgb2gray(f_rgb);f_med=medfilt2(f_gray,[9,9]);BW1=edge(f_med,'canny');subplot(222)imshow(f_gray); title '叶子灰度图'subplot(223)imshow(BW1); title '叶子边缘'
代码如下:
特别提醒:最后的边缘提取(效果见第二张图),使用了一个函数boundarymask,这个函数是matlab R2016a版本新引入的函数,低版本中没有。如果你使用低版本的matlab,EDGE1这部分代码可以使用edge替代(即直接使用edge对BW1提取边缘,sobel,canny都可以),但效果可能不如boundarymask。
clc; clear; close all;