国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

用matlab分水嶺算法做海岸線的提取

2019-11-11 03:09:14
字體:
供稿:網(wǎng)友

先上原圖:

下面是程序:

rgb = imread('你圖片文件');%讀取原圖像I = rgb2gray(rgb);%轉(zhuǎn)化為灰度圖像figure; subplot(121)%顯示灰度圖像imshow(I)text(732,501,'Image courtesy of Corel',...     'FontSize',7,'HorizontalAlignment','right')hy = fspecial('sobel');%sobel算子hx = hy';Iy = imfilter(double(I), hy, 'replicate');%濾波求y方向邊緣Ix = imfilter(double(I), hx, 'replicate');%濾波求x方向邊緣gradmag = sqrt(Ix.^2 + Iy.^2);%求摸subplot(122); imshow(gradmag,[]), %顯示梯度title('Gradient magnitude (gradmag)')L = watershed(gradmag);%直接應(yīng)用分水嶺算法Lrgb = label2rgb(L);%轉(zhuǎn)化為彩色圖像figure; imshow(Lrgb), %顯示分割后的圖像title('Watershed transform of gradient magnitude (Lrgb)')se = strel('disk', 20);%圓形結(jié)構(gòu)元素Io = imopen(I, se);%形態(tài)學(xué)開操作figure; subplot(121)imshow(Io), %顯示執(zhí)行開操作后的圖像title('Opening (Io)')Ie = imerode(I, se);%對圖像進(jìn)行腐蝕Iobr = imreconstruct(Ie, I);%形態(tài)學(xué)重建subplot(122); imshow(Iobr), %顯示重建后的圖像title('Opening-by-reconstruction (Iobr)')Ioc = imclose(Io, se);%形態(tài)學(xué)關(guān)操作figure; subplot(121)imshow(Ioc), %顯示關(guān)操作后的圖像title('Opening-closing (Ioc)')Iobrd = imdilate(Iobr, se);%對圖像進(jìn)行膨脹Iobrcbr = imreconstruct(imcomplement(Iobrd), ...    imcomplement(Iobr));%形態(tài)學(xué)重建Iobrcbr = imcomplement(Iobrcbr);%圖像求反subplot(122); imshow(Iobrcbr), %顯示重建求反后的圖像title('Opening-closing by reconstruction (Iobrcbr)')fgm = imregionalmax(Iobrcbr);%局部極大值figure; imshow(fgm), %顯示重建后局部極大值圖像title('Regional maxima of opening-closing by reconstruction (fgm)')I2 = I;I2(fgm) = 255;%局部極大值處像素值設(shè)為255figure; imshow(I2), %在原圖上顯示極大值區(qū)域title('Regional maxima superimposed on original image (I2)')se2 = strel(ones(5,5));%結(jié)構(gòu)元素fgm2 = imclose(fgm, se2);%關(guān)操作fgm3 = imerode(fgm2, se2);%腐蝕fgm4 = bwareaopen(fgm3, 20);%開操作I3 = I;I3(fgm4) = 255;%前景處設(shè)置為255figure; subplot(121)imshow(I3)%顯示修改后的極大值區(qū)域title('Modified regional maxima')bw = im2bw(Iobrcbr, graythresh(Iobrcbr));%轉(zhuǎn)化為二值圖像subplot(122); imshow(bw), %顯示二值圖像title('Thresholded opening-closing by reconstruction')D = bwdist(bw);%計(jì)算距離DL = watershed(D);%分水嶺變換bgm = DL == 0;%求取分割邊界figure; imshow(bgm), %顯示分割后的邊界title('Watershed ridge lines (bgm)')gradmag2 = imimposemin(gradmag, bgm | fgm4);%置最小值L = watershed(gradmag2);%分水嶺變換I4 = I;I4(imdilate(L == 0, ones(3, 3)) | bgm | fgm4) = 255;%前景及邊界處置255figure; subplot(121)imshow(I4)%突出前景及邊界title('Markers and object boundaries')Lrgb = label2rgb(L, 'jet', 'w', 'shuffle');%轉(zhuǎn)化為偽彩色圖像subplot(122); imshow(Lrgb)%顯示偽彩色圖像title('Colored watershed label matrix')figure; imshow(I), hold onhimage = imshow(Lrgb);%在原圖上顯示偽彩色圖像set(himage, 'AlphaData', 0.3);title('Lrgb superimposed transparently on original image')

最后得到一個(gè)清晰的海岸線圖像:


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 达孜县| 隆昌县| 吴旗县| 南开区| 义马市| 长沙市| 凤冈县| 宜春市| 澎湖县| 遂宁市| 林西县| 揭东县| 平顺县| 连州市| 襄汾县| 新疆| 蓬莱市| 景洪市| 新晃| 两当县| 共和县| 龙胜| 黎平县| 惠东县| 宜丰县| 宁蒗| 宣化县| 高碑店市| 德令哈市| 南皮县| 绥德县| 安陆市| 东港市| 富宁县| 安阳县| 乃东县| 通渭县| 罗甸县| 威海市| 福清市| 连州市|