• VC6.0图形处理6图像增强


    源码下载:http://download.csdn.net/detail/renshengrumenglibing/3875522

    //本节包含高斯平滑,中值滤波和锐化三个部分,三者均为模板操作,只是模板不同,算法均相同,希望读者仔细研读其中之一,其他两个自然就明白了


    void CBMPViewerDoc::OnMenuitem32790() //高斯平滑
    {
    // TODO: Add your command handler code here
    //模板1/16*[1 2 1 ; 2 ,4 ,2 ; 1, 2,1]
    int linewidth;
    linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;



    HLOCAL hTemp;
    hTemp = LocalAlloc(LHND ,linewidth * bi.biHeight );

    LPSTR lpTemp;
    lpTemp = (char*)LocalLock(hTemp);
    unsigned char *lpScr;
    unsigned char * lpDest;
    int sum ;
    int Gauss[9] = {1, 2, 1 , 2 ,4 ,2 , 1, 2,1 };
    // TODO: Add your command handler code here
    for(int i = 0 ; i< bi.biHeight ; i++){

    for(int j = 0 ; j< bi.biWidth ; j++){
    lpDest = (unsigned char *)lpTemp + linewidth *(bi.biHeight - i -1) + j; 
    if((i == 0 ) || (j ==0) || (i == bi.biHeight) || (j == bi.biWidth) ){
    lpScr = (unsigned char*)lpBuf + linewidth*(bi.biHeight - i -1) + j;
    *lpDest = *lpScr;

    else{
    sum = 0 ;
    for(int m = i -1 ; m <= i+1 ;m++){
    for(int n = j-1; n<=j+1; n++){
    lpScr = (unsigned char*)lpBuf + linewidth*(bi.biHeight - m -1) + n;
    sum += (*lpScr) * Gauss[3*(m - i +1) + n - j +1];
    }
    }
    sum/= 16;
    if((sum >= 0 )&&(sum <= 255))
    {
    *lpDest = sum;
    }
    else if(sum > 255) *lpDest = 255;
    else *lpDest= 0;




    }
    }

    }
        
    memcpy(lpBuf, lpTemp, linewidth * bi.biHeight);
    // Invalidata(TRUE);

    UpdateAllViews(NULL,0,NULL);



    }






    void CBMPViewerDoc::OnMenuitem32791() //锐化处理
    {
    //模板1/16*[1 1 1 ; 1 ,1 ,1 ; 1, 1,1]
    int linewidth;
    linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;


    HLOCAL hTemp;
    hTemp = LocalAlloc(LHND ,linewidth * bi.biHeight );

    LPSTR lpTemp;
    lpTemp = (char*)LocalLock(hTemp);
    unsigned char *lpScr;
    unsigned char * lpDest;
    int sum ;
    int m_template[9] = {0, -1, 0 , -1 ,5 ,-1 , 0, -1,0 };
    // TODO: Add your command handler code here
    for(int i = 0 ; i< bi.biHeight ; i++){

    for(int j = 0 ; j< bi.biWidth ; j++){
    lpDest = (unsigned char *)lpTemp + linewidth *(bi.biHeight - i -1) + j; 
    if((i == 0 ) || (j ==0) || (i == bi.biHeight) || (j == bi.biWidth) ){
    lpScr = (unsigned char*)lpBuf + linewidth*(bi.biHeight - i -1) + j;
    *lpDest = *lpScr;

    else{
    sum = 0 ;
    for(int m = i -1 ; m <= i+1 ;m++){
    for(int n = j-1; n<=j+1; n++){
    lpScr = (unsigned char*)lpBuf + linewidth*(bi.biHeight - m -1) + n;
    sum += (*lpScr) * m_template[3*(m - i +1) + n - j +1];
    }
    }

    if((sum >= 0 )&&(sum <= 255))
    {
    *lpDest = sum;
    }
    else if(sum > 255) *lpDest = 255;
    else *lpDest= 0;

    }
    }

    }
        
    memcpy(lpBuf, lpTemp, linewidth * bi.biHeight);
    // Invalidata(TRUE);

    UpdateAllViews(NULL,0,NULL);
    }
    void CBMPViewerDoc::OnMenuitem32792() //中值滤波
    {
    //模板1/16*[1 1 1 ; 1 ,1 ,1 ; 1, 1,1]
    int linewidth;
    linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;


    HLOCAL hTemp;
    hTemp = LocalAlloc(LHND ,linewidth * bi.biHeight );

    LPSTR lpTemp;
    lpTemp = (char*)LocalLock(hTemp);
    unsigned char *lpScr;
    unsigned char * lpDest;
    int sum ;
    int m_template[9] = {1, 1, 1 , 1 ,1 ,1 , 1, 1,1 };
    // TODO: Add your command handler code here
    for(int i = 0 ; i< bi.biHeight ; i++){

    for(int j = 0 ; j< bi.biWidth ; j++){
    lpDest = (unsigned char *)lpTemp + linewidth *(bi.biHeight - i -1) + j; 
    if((i == 0 ) || (j ==0) || (i == bi.biHeight) || (j == bi.biWidth) ){
    lpScr = (unsigned char*)lpBuf + linewidth*(bi.biHeight - i -1) + j;
    *lpDest = *lpScr;

    else{
    sum = 0 ;
    for(int m = i -1 ; m <= i+1 ;m++){
    for(int n = j-1; n<=j+1; n++){
    lpScr = (unsigned char*)lpBuf + linewidth*(bi.biHeight - m -1) + n;
    sum += (*lpScr) * m_template[3*(m - i +1) + n - j +1];
    }
    }
    sum/= 9;
    if((sum >= 0 )&&(sum <= 255))
    {
    *lpDest = sum;
    }
    else if(sum > 255) *lpDest = 255;
    else *lpDest= 0;

    }
    }

    }
        
    memcpy(lpBuf, lpTemp, linewidth * bi.biHeight);
    // Invalidata(TRUE);

    UpdateAllViews(NULL,0,NULL);


    }

  • 相关阅读:
    网络处理1-异步GET请求
    &lt;十二&gt;读&lt;&lt;大话设计模式&gt;&gt;之状态模式
    oracle的shared、dedicated模式解析
    java 调用ant的自己定义task,默认不是build.xml 的一点问题
    【Android开发-8】生命周期,Activity中打开另外一个Activity
    Robot Framework自己主动化測试框架之我见
    三张图教你生成一个Android jar 库。
    Array types are now written with the brackets around the element type问题的解决方法
    HDU 4085 Peach Blossom Spring 斯坦纳树 状态压缩DP+SPFA
    Java 线程池ThreadPoolExecutor简单应用
  • 原文地址:https://www.cnblogs.com/libing64/p/2878771.html
Copyright © 2020-2023  润新知