zoukankan      html  css  js  c++  java
  • 锐化

        图像锐化是补偿图像的轮廓,增强图像的边缘及灰度跳变的部分,使图像变得清晰。图像平滑往往使图像中的边界、轮廓模糊,为了减少这类不利影响,利用图像锐化技术可以使图像的边缘清晰。图像锐化处理的目的是使图像的边缘、轮廓线及图像的细节变得清晰。经过平滑的图像变得模糊的根本原因是对图像进行了平均或积分运算,因此对其进行逆运算。

    1。梯度锐化

        

    Bitmap desc = new Bitmap(source.Width, source.Height);
    BitmapData sourcedata 
    = source.LockBits(new Rectangle(00, source.Width, source.Height), 
                    ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
    BitmapData descdata 
    = desc.LockBits(new Rectangle(00, desc.Width, desc.Height),
                    ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
    unsafe
    {
         
    byte* sourceptr = (byte*)sourcedata.Scan0;  
         
    byte* descptr = (byte*)descdata.Scan0;
         
    int step = source.Width * 3;
         
    double value;
         
    for (int x = 0; x < source.Height; x++)
         {
             
    for (int y = 0; y < source.Width; y++)
             {    
                  value 
    = Math.Sqrt((*sourceptr - *(sourceptr + step + 3)) * (*sourceptr - *(sourceptr + step + 3)) +
                          (
    *(sourceptr + 3- *(sourceptr + step)) * (*(sourceptr + 3- *(sourceptr + step)));
                  
    *(descptr++= value > 255 ? (byte)255 : (byte)(value);
                  sourceptr
    ++;
             }
             sourceptr 
    += sourcedata.Stride - source.Width * 3;
             descptr 
    += descdata.Stride - desc.Width * 3;
         }
    }
    source.UnlockBits(sourcedata);
    desc.UnlockBits(descdata);

    2。拉普拉斯掩膜锐化

    Bitmap desc = new Bitmap(source.Width, source.Height);
    BitmapData sourcedata 
    = source.LockBits(new Rectangle(00, source.Width, source.Height), 
                    ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
    BitmapData descdata 
    = desc.LockBits(new Rectangle(00, desc.Width, desc.Height),
                    ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
    unsafe
    {
         
    byte* sourceptr = (byte*)sourcedata.Scan0;  
         
    byte* descptr = (byte*)descdata.Scan0;
         
    int step = source.Width * 3;
         
    double value;
         
    for (int x = 0; x < source.Height; x++)
         {
             
    for (int y = 0; y < source.Width; y++)
             {    
                  value 
    = Math.Abs(*(sourceptr - step) + *(sourceptr - 3+ *(sourceptr + 3+ 
                                   
    *(sourceptr + step) - *(sourceptr) * 4);
                  
    *(descptr++= value > 255 ? (byte)255 : (byte)(value);
                  sourceptr
    ++;
             }
             sourceptr 
    += sourcedata.Stride - source.Width * 3;
             descptr 
    += descdata.Stride - desc.Width * 3;
         }
    }
    source.UnlockBits(sourcedata);
    desc.UnlockBits(descdata);
  • 相关阅读:
    Express请求处理-静态资源的处理
    PostMan怎样携带登录信息请求后台接口防止出现无法访问资源问题
    Express请求处理-GET和POST请求参数的获取
    Express请求处理-构建模块化路由
    Winform中将WebBrower浏览器控件由IE内核修改为Chrome的WebKit内核
    Electron项目怎样打包成桌面exe应用
    Vue项目打包成桌面程序exe除了使用electron-vue你还可以这样
    Vue项目怎样打包并部署在WindowsServer服务器通过IP访问
    Vue本地执行build之后打开dist目录下index.html正常访问
    H5背景音乐
  • 原文地址:https://www.cnblogs.com/pennant/p/1822387.html
Copyright © 2011-2022 走看看