2分六合

  • 热门专题

图像分析之锐化滤波

作者:quarryman  发布日期:2016-01-08 19:50:33
Tag标签:    
  • 本文叙述了几种实现图像锐化的方式,包括拉普拉斯滤波,加权均值滤波,形态学梯度和顶帽底帽变换。本文的特色在于,大致证明了这几种方式可以实现图像锐化的原因。

    更新记录

    本文持续更新,如果你发现错误,欢迎指出。

    2016年01月08日,发布博文。

    参考

    J.S. Lee, Digital image enhancement and noise filtering by use of local statistics, IEEE Transactions on Pattern Analysis and Machine Intelligence, 2(2):165-168, 1980.

    https://en.wikipedia.org/wiki/Unsharp_masking

    https://en.wikipedia.org/wiki/Erosion_(morphology)

    https://en.wikipedia.org/wiki/Dilation_(morphology)

    https://en.wikipedia.org/wiki/Opening_(morphology)

    https://en。wikipedia。org/wiki/Closing_(morphology)

    https://en。wikipedia。org/wiki/Top-hat_transform

    https://en.wikipedia.org/wiki/Mathematical_morphology

    https://en.wikipedia.org/wiki/Morphological_Gradient

    相关代码

    拉普拉斯滤波和加权均值滤波(主要是高斯滤波)实现图像锐化的代码比较常见,于是只给出如下代码。

    代码一,形态学梯度实现图像锐化

     1 #include <cv.h>
     2 #include <highgui.h>
     3 
     4 // 除了kcvMorphologicalSharpenLike
     5 // factor为正值时,会有锐化效果,为负值时,会有模糊效果。
     6 void kcvMorphologicalSharpenInt(const IplImage* src, IplImage* dst,
     7     double factor, IplConvKernel* element)
     8 {
     9     cvErode(src, dst, element, 1);
    10     cvSub(src, dst, dst);
    11     cvAddWeighted(src, 1, dst, factor, 0, dst);
    12 }
    13 
    14 void kcvMorphologicalSharpenExt(const IplImage* src, IplImage* dst,
    15     double factor, IplConvKernel* element)
    16 {
    17     cvDilate(src, dst, element, 1);
    18     cvSub(dst, src, dst);
    19     cvAddWeighted(src, 1, dst, -factor, 0, dst);
    20 }
    21 
    22 void kcvMorphologicalSharpen(const IplImage* src, IplImage* dst,
    23     double factor1, double factor2, IplConvKernel* element)
    24 {
    25     IplImage* tmp = cvCreateImage(cvGetSize(src), 8, src->nChannels);
    26     kcvMorphologicalSharpenInt(src, tmp, factor1, element);
    27     cvErode(src, dst, element, 1);
    28     cvSub(src, dst, dst);
    29     cvAddWeighted(tmp, 1, dst, factor2, 0, dst);
    30     cvReleaseImage(&tmp);
    31 }
    32 
    33 void kcvMorphologicalSharpenLike(const IplImage* src, IplImage* dst,
    34     double factor, IplConvKernel* element)
    35 {
    36     IplImage* tmp = cvCreateImage(cvGetSize(src), 8, src->nChannels);
    37     cvDilate(src, tmp, element, 1);
    38     cvErode(src, dst, element, 1);
    39     cvSub(tmp, dst, dst);
    40     cvAddWeighted(src, 1, dst, factor, 0, dst);
    41     cvReleaseImage(&tmp);
    42 }
    43 
    44 int main()
    45 {
    46     IplImage* src = cvLoadImage("lena.jpg", 1);
    47     IplImage* dst = cvCloneImage(src);
    48     IplConvKernel* element = cvCreateStructuringElementEx(3, 3, 1, 1, CV_SHAPE_RECT, 0);
    49     int64 t1, t2;
    50 
    51     cvShowImage("src", src);
    52     t1 = cvGetTickCount();
    53     kcvMorphologicalSharpenInt(src, dst, 1, element);
    54     t2 = cvGetTickCount();
    55     printf("kcvMorphologicalSharpenInt %f ms\n", (t2 - t1) / (1000 * cvGetTickFrequency()));
    56     cvShowImage("kcvMorphologicalSharpenInt", dst);
    57 
    58     t1 = cvGetTickCount();
    59     kcvMorphologicalSharpenExt(src, dst, 1, element);
    60     t2 = cvGetTickCount();
    61     printf("kcvMorphologicalSharpenExt %f ms\n", (t2 - t1) / (1000 * cvGetTickFrequency()));
    62     cvShowImage("kcvMorphologicalSharpenExt", dst);
    63 
    64     t1 = cvGetTickCount();
    65     kcvMorphologicalSharpen(src, dst, 1, 1, element);
    66     t2 = cvGetTickCount();
    67     printf("kcvMorphologicalSharpen %f ms\n", (t2 - t1) / (1000 * cvGetTickFrequency()));
    68     cvShowImage("kcvMorphologicalSharpen", dst);
    69 
    70     t1 = cvGetTickCount();
    71     kcvMorphologicalSharpenLike(src, dst, 1, element);
    72     t2 = cvGetTickCount();
    73     printf("kcvMorphologicalSharpenLike %f ms\n", (t2 - t1) / (1000 * cvGetTickFrequency()));
    74     cvShowImage("kcvMorphologicalSharpenLike", dst);
    75 
    76     t1 = cvGetTickCount();
    77     kcvMorphologicalSharpenLike(src, dst, -1, element);
    78     t2 = cvGetTickCount();
    79     printf("kcvMorphologicalSharpenLike 2 %f ms\n", (t2 - t1) / (1000 * cvGetTickFrequency()));
    80     cvShowImage("kcvMorphologicalSharpenLike 2", dst);
    81 
    82     cvWaitKey(0);
    83     cvDestroyAllWindows();
    84     cvReleaseImage(&src);
    85     cvReleaseImage(&dst);
    86     return 0;
    87 }

    代码二,顶帽底帽变换实现图像锐化

    close all
    I = imread('lena.jpg');
    imshow(I)
    se = strel('disk', 3);
    topHat = imtophat(I, se);
    botHat = imbothat(I, se);
    J = imadd(I, 1.5 * topHat);
    figure, imshow(J);
    J = imsubtract(I, 1.5 * botHat);
    figure, imshow(J);
    J = imsubtract(imadd(I, topHat), botHat);
    figure, imshow(J)
    J = imadd(imadd(I, topHat), botHat);
    figure, imshow(J)
    J = imsubtract(imsubtract(I, topHat), botHat);
    figure, imshow(J)

    正文

     

About IT165 - 广告服务 - 隐私声明 - 版权申明 - 免责条款 - 网站地图 - 网友投稿 - 联系方式
本站内容来自于互联网,仅供用于网络技术学习,学习中请遵循相关法律法规

  • <tr id='fty2c'><strong id='fty2c'></strong><small id='fty2c'></small><button id='fty2c'></button><li id='fty2c'><noscript id='fty2c'><big id='fty2c'></big><dt id='fty2c'></dt></noscript></li></tr><ol id='fty2c'><option id='fty2c'><table id='fty2c'><blockquote id='fty2c'><tbody id='fty2c'></tbody></blockquote></table></option></ol><u id='fty2c'></u><kbd id='fty2c'><kbd id='fty2c'></kbd></kbd>

    <code id='fty2c'><strong id='fty2c'></strong></code>

    <fieldset id='fty2c'></fieldset>
          <span id='fty2c'></span>

              <ins id='fty2c'></ins>
              <acronym id='fty2c'><em id='fty2c'></em><td id='fty2c'><div id='fty2c'></div></td></acronym><address id='fty2c'><big id='fty2c'><big id='fty2c'></big><legend id='fty2c'></legend></big></address>

              <i id='fty2c'><div id='fty2c'><ins id='fty2c'></ins></div></i>
              <i id='fty2c'></i>
            1. <dl id='fty2c'></dl>