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

首頁 > 學院 > 開發(fā)設計 > 正文

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

2019-11-11 02:40:05
字體:
來源:轉載
供稿:網(wǎng)友

先上原圖:

下面是程序:

rgb = imread('你圖片文件');%讀取原圖像I = rgb2gray(rgb);%轉化為灰度圖像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);%直接應用分水嶺算法Lrgb = label2rgb(L);%轉化為彩色圖像figure; imshow(Lrgb), %顯示分割后的圖像title('Watershed transform of gradient magnitude (Lrgb)')se = strel('disk', 20);%圓形結構元素Io = imopen(I, se);%形態(tài)學開操作figure; subplot(121)imshow(Io), %顯示執(zhí)行開操作后的圖像title('Opening (Io)')Ie = imerode(I, se);%對圖像進行腐蝕Iobr = imreconstruct(Ie, I);%形態(tài)學重建subplot(122); imshow(Iobr), %顯示重建后的圖像title('Opening-by-reconstruction (Iobr)')Ioc = imclose(Io, se);%形態(tài)學關操作figure; subplot(121)imshow(Ioc), %顯示關操作后的圖像title('Opening-closing (Ioc)')Iobrd = imdilate(Iobr, se);%對圖像進行膨脹Iobrcbr = imreconstruct(imcomplement(Iobrd), ...    imcomplement(Iobr));%形態(tài)學重建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;%局部極大值處像素值設為255figure; imshow(I2), %在原圖上顯示極大值區(qū)域title('Regional maxima superimposed on original image (I2)')se2 = strel(ones(5,5));%結構元素fgm2 = imclose(fgm, se2);%關操作fgm3 = imerode(fgm2, se2);%腐蝕fgm4 = bwareaopen(fgm3, 20);%開操作I3 = I;I3(fgm4) = 255;%前景處設置為255figure; subplot(121)imshow(I3)%顯示修改后的極大值區(qū)域title('Modified regional maxima')bw = im2bw(Iobrcbr, graythresh(Iobrcbr));%轉化為二值圖像subplot(122); imshow(bw), %顯示二值圖像title('Thresholded opening-closing by reconstruction')D = bwdist(bw);%計算距離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');%轉化為偽彩色圖像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')

最后得到一個清晰的海岸線圖像:


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 南和县| 方城县| 琼结县| 醴陵市| 临湘市| 富平县| 河东区| 本溪市| 吉林市| 扎鲁特旗| 西安市| 祁连县| 全州县| 松潘县| 仪征市| 凤城市| 姚安县| 祁门县| 且末县| 永福县| 措美县| 丰镇市| 赤峰市| 万州区| 阿合奇县| 绥江县| 嘉定区| 丽水市| 蒙山县| 高密市| 冀州市| 博野县| 伊吾县| 和林格尔县| 随州市| 射阳县| 茂名市| 克拉玛依市| 横峰县| 靖边县| 卢湾区|