zoukankan      html  css  js  c++  java
  • 图像处理------光束效果 分类: 视频图像处理 2015-07-24 09:34 30人阅读 评论(0) 收藏

    原理:

    光束滤镜,对一幅图像完成光束效果,好似有一束光从图像本身激发出来,按照一定的角度

    散发开来,光束滤镜是一种图像叠加效果,首先要借助于之前的完成的移动模糊滤镜,将一

    幅图像按照一定的阈值二值化以后,加以移动模糊滤镜,将移动模糊之后的图像和原图像叠

    加就产生了光束滤镜效果。

     

    对光束滤镜而言,其最终效果除了移动模糊的三个参数以外,还取决于以下两个参数:

    a.      图像RGB阈值的选取,建议可以直方图以后选取,程序以threshold表示

    b.      光强度大小的值的选取,程序中以strength表示

     

    程序运行效果如下:


    关键代码解析:

    计算RGB阈值代码如下– 输入的阈值范围为[0,1]

    intthreshold3 = (int)(threshold*3*255);

     

    求取二值像素的代码如下:

    int l = r + g + b;

    if (l < threshold3)

        [x] =0xff000000;

    else {

    l /= 3;

    pixels[x] = a | (l << 16) | (l << 8) | l;

    }

    像素叠加乘以强度系数的代码如下(其中r,g,b分别代表RGB的三个颜色分量值):

    r = PixelUtils.clamp((int)(r * strength) + r2);

    g = PixelUtils.clamp((int)(g * strength) + g2);

    b = PixelUtils.clamp((int)(b * strength) + b2);

    光束滤镜的完全源代码如下:

    1. <span style="font-weight: normal;">/* 
    2. ** Copyright 2012 @gloomyfish. All rights reserved. 
    3. */  
    4.   
    5. package com.process.blur.study;  
    6.   
    7. import java.awt.image.BufferedImage;  
    8.   
    9. public class LaserFilter extends MotionFilter {  
    10.   
    11.     private float threshold = 0.5f;  
    12.     private float strength = 0.8f;  
    13.   
    14.     public LaserFilter() {  
    15.     }  
    16.   
    17.     public void setThreshold( float threshold ) {  
    18.         this.threshold = threshold;  
    19.     }  
    20.       
    21.     public float getThreshold() {  
    22.         return threshold;  
    23.     }  
    24.       
    25.     public void setStrength( float strength ) {  
    26.         this.strength = strength;  
    27.     }  
    28.       
    29.     public float getStrength() {  
    30.         return strength;  
    31.     }  
    32.       
    33.     public BufferedImage filter( BufferedImage src, BufferedImage dst ) {  
    34.         int width = src.getWidth();  
    35.         int height = src.getHeight();  
    36.         int[] pixels = new int[width];  
    37.         int[] srcPixels = new int[width];  
    38.   
    39.         BufferedImage laserImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);  
    40.   
    41.         int threshold3 = (int)(threshold*3*255);  
    42.         for ( int y = 0; y < height; y++ ) {  
    43.             getRGB( src, 0, y, width, 1, pixels );  
    44.             for ( int x = 0; x < width; x++ ) {  
    45.                 int rgb = pixels[x];  
    46.                 int a = rgb & 0xff000000;  
    47.                 int r = (rgb >> 16) & 0xff;  
    48.                 int g = (rgb >> 8) & 0xff;  
    49.                 int b = rgb & 0xff;  
    50.                 int l = r + g + b;  
    51.                 if (l < threshold3)  
    52.                     pixels[x] = 0xff000000;  
    53.                 else {  
    54.                     l /= 3;  
    55.                     pixels[x] = a | (l << 16) | (l << 8) | l;  
    56.                 }  
    57.             }  
    58.             setRGB( laserImg, 0, y, width, 1, pixels );  
    59.         }  
    60.   
    61.         laserImg = super.filter(laserImg, null );  
    62.           
    63.         for ( int y = 0; y < height; y++ ) {  
    64.             getRGB( laserImg, 0, y, width, 1, pixels );  
    65.             getRGB( src, 0, y, width, 1, srcPixels );  
    66.             for ( int x = 0; x < width; x++ ) {  
    67.                 int rgb = pixels[x];  
    68.                 int a = rgb & 0xff000000;  
    69.                 int r = (rgb >> 16) & 0xff;  
    70.                 int g = (rgb >> 8) & 0xff;  
    71.                 int b = rgb & 0xff;  
    72.                   
    73.                 int rgb2 = srcPixels[x];  
    74.                 // int a2 = rgb2 & 0xff000000;  
    75.                 int r2 = (rgb2 >> 16) & 0xff;  
    76.                 int g2 = (rgb2 >> 8) & 0xff;  
    77.                 int b2 = rgb2 & 0xff;  
    78.                   
    79.                 if ( r > 0 ) {  
    80.                     r = clamp((int)(r * strength) + r2);  
    81.                     g = clamp((int)(g * strength) + g2);  
    82.                     b = clamp((int)(b * strength) + b2);  
    83.                 } else {  
    84.                     r = r2;  
    85.                     g = g2;  
    86.                     b = b2;  
    87.                 }  
    88.   
    89.                 rgb = a | (r << 16) | (g << 8) | b;  
    90.                 pixels[x] = rgb;  
    91.             }  
    92.             setRGB( laserImg, 0, y, width, 1, pixels );  
    93.         }  
    94.   
    95.         return laserImg;  
    96.     }  
    97.       
    98.     public String toString() {  
    99.         return "Light/Laser...";  
    100.     }  
    101. }  
    102. </span>  

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    Win10 字体模糊解决(DPI缩放禁用),设置默认输入法英文
    windows下使用VS2015编译V8 JavaScript引擎(v5.5
    GDB 多线程调试:只停止断点的线程,其他线程任然执行; 或只运行某些线程 其他线程中断
    wget 显示"英国中部时间",去掉烦人的刷屏显示
    阻止事件冒泡,阻止默认事件,event.stopPropagation()和event.preventDefault(),return false的区别
    CSS
    bootstrap4 调整元素之间距离
    数据库文件结构、sqlserver ON [PRIMARY]
    快速查看数据库中每个表的数据条数
    关于LINQ中SELECT NEW 的问题
  • 原文地址:https://www.cnblogs.com/mao0504/p/4706372.html
Copyright © 2011-2022 走看看