zoukankan      html  css  js  c++  java
  • 分水岭变换

    % Question No: 8
    % Consider a binary image composed of small blobs. Segmenting the circular
    % blobs using
    %   a) Distance Transform
    %   b) Watershed Transform
    
    function watersd(x)
    f=imread(x);
    bw=im2bw(f,graythresh(f));
    bwc=~bw;
    dst=bwdist(bwc);
    ws=watershed(-dst);
    w=ws==0;
    rf=bw&~w;
    figure,imshow(f),title('Original Image');
    figure,imshow(bw,[]),title('Negative Image');
    figure,imshow(ws,[]),title('Watershed - Distance Transform');
    figure,imshow(rf,[]),title('Superimposed - Watershed and original image');
    
    h=fspecial('sobel');
    fd=im2double(f);
    sq=sqrt(imfilter(fd,h,'replicate').^2+imfilter(fd,h','replicate').^2);
    sqoc=imclose(imopen(sq,ones(3,3)),ones(3,3));
    wsd=watershed(sqoc);
    wg=wsd==0;
    rfg=f;
    rfg(wg)=255;
    figure,imshow(wsd),title('Watershed - Gradient');
    figure,imshow(rf),title('Superimposed - Watershed and original image');
    
    im=imextendedmin(f,20);
    Lim=watershed(bwdist(im));
    figure,imshow(Lim),title('Watershed - Marker Controlled');
    em=Lim==0;
    rfmin=imimposemin(sq,im|em);
    wsdmin=watershed(rfmin);
    figure,imshow(rfmin),title('Watershed - Gradient and Marker Controlled');
    rfgm=f;
    rfgm(wsdmin==0)=255;
    figure,imshow(rfgm),title('Superimposed - Watershed (GM) and original image');
    end
    
    
    

  • 相关阅读:
    (7)常量和变量
    (6)python基础数据类型
    PEP8规范
    (5)原码反码补码
    (4)二八十六进制转换
    (3)你的第一个python程序
    (2)python开发环境搭建
    几种常见的开发语言对比
    (1)python的基础认知
    (25)线程---local数据隔离
  • 原文地址:https://www.cnblogs.com/xiangshancuizhu/p/1916903.html
Copyright © 2011-2022 走看看