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);


    }

  • 相关阅读:
    Android学习网站(1)
    selenium借助AutoIt识别上传(下载)详解
    Apache部署django项目
    win7 64 安装mysql-python:_mysql.c(42) : fatal error C1083: Cannot open include file: 'config-win.h': No such file or directory
    前端技术Bootstrap的hello world
    djngo快速实现--使用Bootstrap
    自动化基础普及之selenium是啥?
    Robot Framework自动化测试(四)--- 分层思想
    Robot Framework自动化测试(三)---Selenium API
    Robot Framework自动化测试(二)---元素定位
  • 原文地址:https://www.cnblogs.com/libing64/p/2878771.html
Copyright © 2011-2022 走看看