形态学滤波

  最烦的事情莫过于每年的遥感图像处理软件的测评了,这个月逃不掉了,只好坐软件开发方面的工作,其实我自己好喜欢研究算法而不是成熟算法的实现。今天下午和晚上实现了二值和灰度图象的形态学滤波算法的实现。 其中二值图像部分暂且用MATLAB实现的,灰度图部分采用了C#。
      文献参考:
   (1)数字图像处理(MATLAB版)
   (2)http://www.codeproject.com/cs/media/Image_Processing_Lab.asp
      实现的很丑陋,都不好意思贴出来了:(
function out = mydialate;%(inimg, structure)
in = imread('binary.tif');
out = in;
structure=[ 1 1 1;
    1 1 1;
    1 1 1;];
[cy,cx]=size(in);
[sey,sex]=size(structure);
halfsex =floor(sex/2);
halfsey =floor(sey/2);
for row = halfsey+1:(cy-halfsey)
    for col = halfsex+1:(cx-halfsex)
         for indexrow=row-halfsey:row+halfsey
               for indexcol = col-halfsex:col+halfsex
                   winrow=indexrow-row+halfsey+1;
                   wincol = indexcol-col+halfsex+1;
                   tempwin=structure(winrow,wincol);
                  if in(row,col)==1
                   out(indexrow,indexcol) = or(tempwin,out(indexrow,indexcol)); 
                  end
               end
         end
    end
endfunction out = myerosion;%(inimg, structure)
in = imread('binary.tif');
out = in;
structure=[ 1 1 1;
    1 1 1;
    1 1 1;];
[cy,cx]=size(in);
[sey,sex]=size(structure);
halfsex =floor(sex/2);
halfsey =floor(sey/2);
for row = halfsey+1:(cy-halfsey)
    for col = halfsex+1:(cx-halfsex)
         for indexrow=row-halfsey:row+halfsey
               for indexcol = col-halfsex:col+halfsex
                   winrow=indexrow-row+halfsey+1;
                   wincol = indexcol-col+halfsex+1;
                   tempwin=structure(winrow,wincol);
                   if tempwin == 1
                       if in(indexrow,indexcol)==0
                         out(row,col) = 0;
                     end
                  end
               end
         end
    end
end

posted @ 2010-12-25 21:04  hailong  阅读(1087)  评论(0编辑  收藏  举报