zoukankan      html  css  js  c++  java
  • 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);


    }

  • 相关阅读:
    深入了解 Flink 网络栈(二):监控、指标和处理背压
    物联网安全技术提高区块链应用数据的可信度
    威胁快报|Bulehero挖矿蠕虫升级,PhpStudy后门漏洞加入武器库
    Ververica Platform-阿里巴巴全新Flink企业版揭秘
    重磅 | 阿里云与MongoDB达成战略合作,成为全球唯一提供最新版MongoDB的云厂商
    阿里巴巴叶军:政企数字化转型,现在是最重要的时机
    Canonical 开源 MicroK8 | 云原生生态周报 Vol. 25
    nyoj42——连通图加欧拉(连通图板子)dfs
    nyoj38——最小生成树
    nyoj20——有向无环图深搜模板
  • 原文地址:https://www.cnblogs.com/libing64/p/2878771.html
Copyright © 2011-2022 走看看