(一)实现代码
clc
用各梯度算子对图像进行边缘检测;
Iimreadflowerjpg读入灰度图像I1im2doubleI将彩图序列变成双精度frgb2grayI1将彩色图变成灰色图LRsizef图像大小GRfGPfGSfforx2L1fory2R1GRxxyfxyfx1y1GRyxyfxy1fx1yGRxysqrtGRxxy2GRyxy2roberts图像边缘提取GPxxyfx1y1fxy1fx1y13fx1y1fxy1fx1y13GPyxyfx1y1fx1yfx1y13fx1y1fx1yfx1y13GPxysqrtGPxxy2GPyxy2prewitt图像边缘提取GSxxyfx1y12fxy1fx1y13fx1y12fxy1fx1y13GSyxyfx1y12fx1yfx1y13fx1y12fx1yfx1y13GSxysqrtGSxxy2GSyxy2sobel图像边缘提取e
de
dfiguresubplot221imshowftitle原图象figuresubplot222imshowGRtitleRoberts算子边缘提取figuresubplot223imshowGPtitlePrewitt算子边缘提取figuresubplot224imshowGStitleSobel算子边缘提取
f(二)源代码
利用直方图人工指定阈值对rice进行自动单阈值分割;
oldbufimreadricetifsubplot221imshowoldbuftitle原图像MNsizeoldbufskimhistoldbuf直方图upmaxsk纵坐标最大值subplot222imhistoldbufaxis12560up原直方图title原图像直方图ylabel频数xlabel灰度值fori1125ski0e
dfori126Mski1e
dfori1Mforj1N
ewbufijskoldbufij映射e
de
d
fsubplot223imshow
ewbuftitle单阈值分割Iim2doubleoldbufsestreldisk10创建一个指定大小R平面disk形状的结构化元素。ftimtophatIseThgraythreshftGim2bwftThsubplot224imshowGtitle局部阈值分割局部阈值分割单阈值分割
(三)
用迭代法和OSTU法对rice进行自动单阈值分割;
源代码clearallcloseallclcIimreadcoi
sp
gJim2doubleI索引图像转换为灰度图像TgraythreshI获得阈值Jim2bwIT图像分割figure
fsubplot121imshowIaxissquarexlabela原图像subplot122imshowJaxissquarexlabelbOstu算法分割图像
clearallcloseallclcI1imreadcamerama
tifIim2doubleI1将图像灰度值由8位二进制转化为双精度T0001设置参数T0T1mi
ImaxI2r1fi
dIT1r2fi
dIT1T2mea
Ir1mea
Ir22whileabsT2T1T0迭代阈值T1T2r1fi
dIT1r2fi
dIT1T2mea
Ir1mea
Ir22e
dJim2bwIT2图像分割figuresubplot121imshowI1axissquarexlabela原图像
fsubplot122imshowJaxissquarexlabelb迭代阈值算法分割图像
fr