图像处理------光束效果

简介: <p style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"><strong>原理:</strong></p><p style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height

原理:

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

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

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

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

 

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

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

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

[java]  view plain copy
  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>  
相关文章
|
4月前
|
计算机视觉
图像处理之光束效果
图像处理之光束效果
17 0
|
编解码 算法 计算机视觉
小波分析法图像处理----图像增强
小波分析法图像处理----图像增强
721 0
小波分析法图像处理----图像增强
|
资源调度 计算机视觉 Java
图像处理------图像加噪
<p style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;">图像噪声源于现实世界中数字信号总会受到各种各样的干扰,最终接受的图像和源于的数字信号之间总</p> <p style="color: rgb(51, 51, 51); font-family: Arial; fon
1633 0
|
计算机视觉 Java
图像处理------直方图均衡化
<p style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"><span style="font-size: 18px;"><strong>基本思想</strong>:</span></p> <p style="color: rgb(51, 51, 51); font-fam
1469 0
|
计算机视觉 Python Java
图像处理------光源退化效果
<p style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"><strong><span style="font-size: 18px;">基本思想:</span></strong></p> <p style="color: rgb(51, 51, 51); font-fam
1459 0
|
算法 Java 计算机视觉
图像处理------噪声之美 - 随机噪声产生
<p style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"><strong>数学原理:</strong></p> <p style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-heig
1527 0
|
算法 Java 计算机视觉
图像处理------基于像素的皮肤检测技术
<p style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;">基于像素的皮肤检测技术</p> <p style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;">
2143 0
|
计算机视觉
图像处理------ 二值腐蚀
<p style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"><strong>概述:</strong></p> <p style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height
1408 0
|
Java 计算机视觉 算法
图像处理------移动模糊
<p style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;">卷积模糊或者卷积平滑滤波,可以消除图像噪声,也可以产生一些常见的图像模糊特效,但</p> <p style="color: rgb(51, 51, 51); font-family: Arial; font-siz
1234 0
|
资源调度 算法 Java
图像处理------高斯模糊
<p style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;">高斯模糊是一种两维的卷积模糊操作,在图像完成高斯模糊相对于均值模糊来说,</p> <p style="color: rgb(51, 51, 51); font-family: Arial; font-size: 1
1617 0