图像处理--------应用卷积– 轧花与边缘检测

本文涉及的产品
简介: <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-heigh

一:轧花

轧花算子(embossfilter)

对一幅数字图像一阶微分结果即可得到轧花效果,根据不同的算子,轧花又

可以分为凹效果与凸效果两种。两个个最简单的轧花算子为:


轧花算子又称为双极性算子,1对图像的贡献意味着平滑,-1对图像的贡献

意味着突出细节,于是最终就得出了双极性的轧花效果。

 

处理过程:

a.      读取图像像素

b.      使用轧花算子完成对像素数组的卷积操作

c.      整体亮度提升效果– 高斯亮度/基于阈值/直接常量提升

 

轧花滤镜效果:左边为原图, 右边为轧花处理以后效果

 

二:边缘提取

Edge detection是图像处理中非常重要而且也是十分常用的图像处理手段之一,边缘提取是

图像二值化的基本步骤之一。边缘提取从本质上来说是高通滤波,从数字信号的角度看,就

是要保留高频信号,去掉低频信号,因此边缘提取有很多频率域算子,将图像完成FFT之后

在频率域完成高通滤波再转到空间域。显然计算量比较大,空间域最经典的边缘提取算法之

一Candy Edge Detection有着非常好的效果。

 

这里只是抛砖引玉,完成一个最简单基于卷积的空间域边缘提取算子,算子为:

 

完成卷积以后的效果如下:


对于灰度图完成边缘提取以后效果如下:

 

基于卷积还可以完成图像的锐化(Sharp Filter),让图像上的差异更加明显。

一个简单的Sharp Filter可以为

 

得到的效果如下:

 

完成轧花卷积的代码如下:

[java]  view plain copy
  1. @Override  
  2. public BufferedImage filter(BufferedImage src, BufferedImage dest) {  
  3.     int width = src.getWidth();  
  4.        int height = src.getHeight();  
  5.   
  6.        if ( dest == null )  
  7.            dest = createCompatibleDestImage( src, null );  
  8.   
  9.        int[] inPixels = new int[width*height];  
  10.        int[] outPixels = new int[width*height];  
  11.        src.getRGB( 00, width, height, inPixels, 0, width );  
  12.     int index = 0;  
  13.     int index2 = 0;  
  14.     int r=0, g=0, b=0;  
  15.     for ( int y = 0; y < height; y++ ) {  
  16.         for ( int x = 0; x < width; x++ ) {  
  17.             int ta = 255, tr = 0, tg = 0, tb = 0;  
  18.             for(int fr = 0; fr < filterRow; fr++) {  
  19.                 int rowoffset = y + fr;  
  20.                 if(rowoffset < 0 || rowoffset >=height) {  
  21.                     rowoffset = y;  
  22.                 }  
  23.                 for(int fc = 0; fc < filterCol; fc++) {  
  24.                     int coloffset = fc + x;  
  25.                     if(coloffset < 0 || coloffset >= width) {  
  26.                         coloffset = x;  
  27.                     }  
  28.                     index2 = rowoffset * width + coloffset;  
  29.                     int rgb1 = inPixels[index2];  
  30.                     int r1 = (rgb1 >> 16) & 0xff;  
  31.                     int g1 = (rgb1 >> 8) & 0xff;  
  32.                     int b1 = rgb1 & 0xff;  
  33.                     if(isOUT) {  
  34.                         tr += r1 * outfilter[fr][fc];  
  35.                         tg += g1 * outfilter[fr][fc];  
  36.                         tb += b1 * outfilter[fr][fc];  
  37.                     } else {  
  38.                         tr += r1 * infilter[fr][fc];  
  39.                         tg += g1 * infilter[fr][fc];  
  40.                         tb += b1 * infilter[fr][fc];  
  41.                     }  
  42.                 }  
  43.             }  
  44.               
  45.             tr += COLORCONSTANTS;  
  46.             tg += COLORCONSTANTS;  
  47.             tb += COLORCONSTANTS;  
  48.             r = PixelUtils.clamp(tr);  
  49.             g = PixelUtils.clamp(tg);  
  50.             b = PixelUtils.clamp(tb);  
  51.             outPixels[index] = (ta << 24) | (r << 16) | (g << 8) | b;  
  52.             index++;  
  53.         }  
  54.     }  
  55.        dest.setRGB( 00, width, height, outPixels, 0, width );  
  56.        return dest;  
  57. }  

完成简单边缘检测的代码如下:

[java]  view plain copy
  1. private void filter(int[] inPixels, int[] outPixels, int height, int width, double[][] filterKernel) {  
  2.     int index = 0;  
  3.     int index2 = 0;  
  4.     int r=0, g=0, b=0;  
  5.     int semiColumn = filterKernel.length/2;  
  6.     int semiRow = filterKernel[0].length/2;  
  7.     for ( int y = 0; y < height; y++ ) {  
  8.         for ( int x = 0; x < width; x++ ) {  
  9.             int ta = 255, tr = 0, tg = 0, tb = 0;  
  10.             for(int fr = -semiRow; fr <= semiRow; fr++) {  
  11.                 int rowoffset = y + fr;  
  12.                 if(rowoffset < 0 || rowoffset >=height) {  
  13.                     rowoffset = y;  
  14.                 }  
  15.                 for(int fc = -semiColumn; fc <= semiColumn; fc++) {  
  16.                     int coloffset = fc + x;  
  17.                     if(coloffset < 0 || coloffset >= width) {  
  18.                         coloffset = x;  
  19.                     }  
  20.                     index2 = rowoffset * width + coloffset;  
  21.                     int rgb1 = inPixels[index2];  
  22.                     int r1 = (rgb1 >> 16) & 0xff;  
  23.                     int g1 = (rgb1 >> 8) & 0xff;  
  24.                     int b1 = rgb1 & 0xff;  
  25.                     tr += ((double)r1 * filterKernel[fr + semiRow][fc + semiColumn]);  
  26.                     tg += ((double)g1 * filterKernel[fr + semiRow][fc + semiColumn]);  
  27.                     tb += ((double)b1 * filterKernel[fr + semiRow][fc + semiColumn]);  
  28.                 }  
  29.             }  
  30.               
  31.             if(enhanceBrightness) {  
  32.                 tr += COLORCONSTANTS;  
  33.                 tg += COLORCONSTANTS;  
  34.                 tb += COLORCONSTANTS;  
  35.             }  
  36.             r = PixelUtils.clamp(tr);  
  37.             g = PixelUtils.clamp(tg);  
  38.             b = PixelUtils.clamp(tb);  
  39.             outPixels[index] = (ta << 24) | (r << 16) | (g << 8) | b;  
  40.             index++;  
  41.         }  
  42.     }  
  43. }  
相关实践学习
基于函数计算一键部署掌上游戏机
本场景介绍如何使用阿里云计算服务命令快速搭建一个掌上游戏机。
建立 Serverless 思维
本课程包括: Serverless 应用引擎的概念, 为开发者带来的实际价值, 以及让您了解常见的 Serverless 架构模式
相关文章
|
8月前
|
机器学习/深度学习 算法 BI
图像处理HOG特征提取
简要介绍hog特征提取的原理和python代码实现。
|
10月前
|
机器学习/深度学习 计算机视觉
卷积及其图像处理的运用
卷积及其图像处理的运用
96 0
|
数据可视化 算法 计算机视觉
【计算机视觉】图像增强----图像的傅立叶变换
【计算机视觉】图像增强----图像的傅立叶变换
538 0
【计算机视觉】图像增强----图像的傅立叶变换
|
计算机视觉
【计算机视觉】图像增强----直方图均衡化
主要介绍图像增强中直方图均衡化的原理以及相关实操及分析。
659 0
【计算机视觉】图像增强----直方图均衡化
|
算法 计算机视觉 索引
图像处理之HOG特征提取
图像处理之HOG特征提取算法 HOG(Histogram of Oriented Gradient)特征在对象识别与模式匹配中是一种常见的特征提取算法,是基于本地像素块进行特征直方图提取的一种算法,对象局部的变形与光照影响有很好的稳定性,最初是用HOG特征来来识别人像,通过HOG特征提取+SVM训练,可以得到很好的效果,OpenCV已经有了。
1585 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-heig
1623 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-he
2336 0
|
资源调度 算法 Java
图像处理------Canny边缘检测
<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-fami
1737 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
1438 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
1375 0