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

首頁 > 學院 > 開發設計 > 正文

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

2019-11-11 04:43:40
字體:
來源:轉載
供稿:網友

先上原圖:

下面是程序:

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);%形態學開操作figure; subplot(121)imshow(Io), %顯示執行開操作后的圖像title('Opening (Io)')Ie = imerode(I, se);%對圖像進行腐蝕Iobr = imreconstruct(Ie, I);%形態學重建subplot(122); imshow(Iobr), %顯示重建后的圖像title('Opening-by-reconstruction (Iobr)')Ioc = imclose(Io, se);%形態學關操作figure; subplot(121)imshow(Ioc), %顯示關操作后的圖像title('Opening-closing (Ioc)')Iobrd = imdilate(Iobr, se);%對圖像進行膨脹Iobrcbr = imreconstruct(imcomplement(Iobrd), ...    imcomplement(Iobr));%形態學重建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), %在原圖上顯示極大值區域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)%顯示修改后的極大值區域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')

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


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 磴口县| 绵竹市| 石家庄市| 松溪县| 三台县| 同心县| 林西县| 泰来县| 莆田市| 新平| 淅川县| 屏东市| 邓州市| 铜陵市| 高陵县| 济阳县| 永修县| 海盐县| 且末县| 安西县| 尼玛县| 宁明县| 即墨市| 定安县| 都安| 安图县| 开封市| 滦平县| 澄迈县| 东城区| 南靖县| 马山县| 喀喇沁旗| 佳木斯市| 蓬溪县| 扎鲁特旗| 桂平市| 英超| 上犹县| 华容县| 普兰县|