DIP2-Enhancement(PointProcessing)

Image Enhancement

1.Reasons for doing this:

  • Highlighting interesting detail in images
  • Removing noise from images
  • Making images more visually appealing2

2. Two broad categories of image enhancement

Spatial domain techniques

    • Direct manipulation of image pixels
  • Point processing
  • Neighbourhood operations

b. Frequency domain techniques

    • Manipulation of Fourier transform or wavelet transform of an image

2.1 Techniques in spatial domain

–Thresholding

–Logarithmic transformation

–Power law transforms

–Grey level slicing

–Bit plane slicing

–Logic operations

–Image subtraction

–Image averaging

a. Thresholding

 1 #include <opencv2\opencv.hpp>
 2 #include <iostream>
 3 #include <string>
 4 using namespace cv;
 5 using namespace std;
 6 int main()
 7 {
 8     IplImage* img; //声明IplImage指针
 9     //载入图像
10     img = cvLoadImage("C://Users//Administrator//Desktop//dip//moon.png",0) ;
11
12     cvNamedWindow( "Image1", 1 );//创建窗口
13     cvShowImage( "Image1", img );//显示图像
14
15     for(int row = 0; row<img->height; row++)
16     {
17         for (int col=0; col<img->width; col++)
18         {
19             if((unsigned char)(img->imageData[row*img->widthStep+col])>80)
20                 img->imageData[row*img->widthStep+col] = 255;
21             else
22                 img->imageData[row*img->widthStep+col] = 0;
23         }
24     }
25
26         cvNamedWindow( "Image", 1 );//创建窗口
27         cvShowImage( "Image", img );//显示图像
28         cvWaitKey(0); //等待按键
29
30         cvDestroyWindow( "Image" );//销毁窗口
31         cvDestroyWindow( "Image1" );//销毁窗口
32         cvReleaseImage( &img ); //释放图像
33         return 0;
34 }

结果:

b. Logarithmic transformation

  expression: s = c * log(1 + r)

 1 #include <opencv2\opencv.hpp>
 2 #include <iostream>
 3 #include <string>
 4 #include <math.h>
 5 #include <stdio.h>
 6 using namespace cv;
 7 using namespace std;
 8 int main()
 9 {
10     IplImage* img; //声明IplImage指针
11     //载入图像
12     img = cvLoadImage("C://Users//Administrator//Desktop//dip//light.png",0) ;
13
14     cvNamedWindow( "Image1", 1 );//创建窗口
15     cvShowImage( "Image1", img );//显示图像
16     /*printf("%x",img->imageData[(img->height)*(img->widthStep)/2+(img->width)/2]);*/
17
18     for(int row = 0; row<img->height; row++)
19     {
20         for (int col=0; col<img->width; col++)
21         {
22             //----------------关键代码在这儿----------------------
23                 (unsigned char)img->imageData[row*img->widthStep+col];
24                 img->imageData[row*img->widthStep+col] = (unsigned char)(20*(log(1+(double)img->imageData[row*img->widthStep+col])));
25         }
26     }
27
28         cvNamedWindow( "Image", 1 );//创建窗口
29         cvShowImage( "Image", img );//显示图像
30
31
32         cvWaitKey(0); //等待按键
33         cout<<"hello";
34         /*printf("%x",img->imageData[(img->height)*(img->widthStep)/2+(img->width)/2]);*/
35
36         cvDestroyWindow( "Image" );//销毁窗口
37         cvDestroyWindow( "Image1" );//销毁窗口
38         cvReleaseImage( &img ); //释放图像
39         return 0;
40 }

结果:

注意:程序让图像显示出了更多细节,但是不知道为什么中间的255白点变成了0?

   Line16,32试图输出确切的灰度级,未果。。

c. Power law transforms  

  expression: s = c * r ^γ

 1 #include <math.h>
 2 #include <stdio.h>
 3 using namespace cv;
 4 using namespace std;
 5 int main()
 6 {
 7     IplImage* img; //声明IplImage指针
 8     //载入图像
 9     img = cvLoadImage("C://Users//Administrator//Desktop//dip//spine.png",0) ;
10
11     cvNamedWindow( "Image1", 1 );//创建窗口
12     cvShowImage( "Image1", img );//显示图像
13
14     for(int row = 0; row<img->height; row++)
15     {
16         for (int col=0; col<img->width; col++)
17         {
18             //----------------关键代码在这儿----------------------
19                 (unsigned char)img->imageData[row*img->widthStep+col];
20                 img->imageData[row*img->widthStep+col] = 8*pow((double)(unsigned char)img->imageData[row*img->widthStep+col],0.6);
21         }
22     }
23
24         cvNamedWindow( "Image", 1 );//创建窗口
25         cvShowImage( "Image", img );//显示图像
26
27         cvWaitKey(0); //等待按键
28         cvDestroyWindow( "Image" );//销毁窗口
29         cvDestroyWindow( "Image1" );//销毁窗口
30         cvReleaseImage( &img ); //释放图像
31         return 0;
32 }

结果:c=8, γ=0.6 如下

  c=16, γ=0.4 如下

  c=20, γ=0.3 如下

d. Grey level slicing

      

  

It is similar to thresholding

e. Bit plane slicing

f. Image subtraction

  

  Application: Change Detection

    •Tracking moving vehicles

    •Tracking walking persons

    •Change detections

Example1:

 1 #include <opencv2\opencv.hpp>
 2 #include <iostream>
 3 #include <string>
 4 #include <math.h>
 5 #include <stdio.h>
 6 using namespace cv;
 7 using namespace std;
 8 int main()
 9 {
10     IplImage* img; //声明IplImage指针
11     IplImage* img2;
12     //载入图像
13     img = cvLoadImage("C://Users//Administrator//Desktop//dip//car.png",0) ;
14     img2 = cvLoadImage("C://Users//Administrator//Desktop//dip//cargone.png",0) ;
15     cout<<img->height<<endl;
16     cout<<img->width<<endl;
17     cout<<img2->height<<endl;
18     cout<<img2->width<<endl;
19
20     cvNamedWindow( "OriginalImage", 1 );//创建窗口
21     cvShowImage( "OriginalImage", img );//显示图像
22
23     cvNamedWindow( "OriginalImageCarGone", 1 );//创建窗口
24     cvShowImage( "OriginalImageCarGone", img2 );//显示图像
25
26     for(int row = 0; row<img->height; row++)
27     {
28         for (int col=0; col<img->width; col++)
29         {
30             //----------------关键代码在这儿----------------------
31                 (unsigned char)img->imageData[row*img->widthStep+col];
32                 (unsigned char)img2->imageData[row*img->widthStep+col];
33
34                 img->imageData[row*img->widthStep+col] = (255+(img2->imageData[row*img->widthStep+col])-(img->imageData[row*img->widthStep+col]))/2;
35         }
36     }
37
38         cvNamedWindow( "ProcessedImage", 1 );//创建窗口
39         cvShowImage( "ProcessedImage", img );//显示图像
40
41         cvWaitKey(0); //等待按键
42         cvDestroyWindow( "OriginalImage" );//销毁窗口
43         cvDestroyWindow( "OriginalImageCarGone" );//销毁窗口
44         cvDestroyWindow( "ProcessedImage" );//销毁窗口
45         cvReleaseImage( &img ); //释放图像
46         cvReleaseImage( &img2 ); //释放图像
47         return 0;
48 }

理想结果应该是这样:

    

可是 我的却是这样:

在黑框里调试输出了两张图片的高和宽,竟然不一样!

老干妈的PPT有问题啊啊

Example2:

 1 #include <opencv2\opencv.hpp>
 2 #include <iostream>
 3 #include <string>
 4 #include <math.h>
 5 #include <stdio.h>
 6 using namespace cv;
 7 using namespace std;
 8 int main()
 9 {
10     IplImage* img; //声明IplImage指针
11     IplImage* img2;
12     //载入图像
13     img = cvLoadImage("C://Users//Administrator//Desktop//dip//banana.png",0) ;
14     img2 = cvLoadImage("C://Users//Administrator//Desktop//dip//bananamove.png",0) ;
15     cout<<"img1:height:"<<img->height<<endl;
16     cout<<"img1:width:"<<img->width<<endl;
17     cout<<"img2:height:"<<img2->height<<endl;
18     cout<<"img2:width:"<<img2->width<<endl;
19
20     cvNamedWindow( "OriginalImage", 1 );//创建窗口
21     cvShowImage( "OriginalImage", img );//显示图像
22
23     cvNamedWindow( "OriginalImageCarGone", 1 );//创建窗口
24     cvShowImage( "OriginalImageCarGone", img2 );//显示图像
25
26     for(int row = 0; row<img->height; row++)
27     {
28         for (int col=0; col<img->width; col++)
29         {
30             //----------------关键代码在这儿----------------------
31                 (unsigned char)img->imageData[row*img->widthStep+col];
32                 (unsigned char)img2->imageData[row*img->widthStep+col];
33
34                 img->imageData[row*img->widthStep+col] = (255+(img2->imageData[row*img->widthStep+col])-(img->imageData[row*img->widthStep+col]))/2;
35         }
36     }
37
38         cvNamedWindow( "ProcessedImage", 1 );//创建窗口
39         cvShowImage( "ProcessedImage", img );//显示图像
40
41         cvWaitKey(0); //等待按键
42         cvDestroyWindow( "OriginalImage" );//销毁窗口
43         cvDestroyWindow( "OriginalImageCarGone" );//销毁窗口
44         cvDestroyWindow( "ProcessedImage" );//销毁窗口
45         cvReleaseImage( &img ); //释放图像
46         cvReleaseImage( &img2 ); //释放图像
47         return 0;
48 }

结果:

结果分析:

处理后的图片可以看到杯子移动、香蕉旋转、订书机的变化等,也就是图片不是标准的只动了一点,相机的位置估计有些变化,另外 大部分场景不是变成黑色,可能原因是光线变化。

看来这个功能可以秒玩“大家来找茬”

g. Image averaging

  An image f(x,y) with nois n(x,y)

  

To reduce the noise, we can collect a series of images of f(x,y) with different n(x,y), then get the averge image of them.

For example, we can get the Consecutive frames from a video.

3. Image Histograms(图像直方图)

通常,容易分辨的图片,其灰度直方图是比较均匀分布的,像曝光不足或过度的图像就会使图像灰度级整体偏小或偏大。

本节的内容是将不均匀的图像灰度直方图转换为比较均匀的。

转换公式可以是:

使用该公式有两点好处:a. 单调递增; b. 值域会映射到[0,1].

Example:

如此,就完成了整体灰度级的重新映射!

哈哈 竟然写完了 吃饭去喽~

时间: 2024-10-20 21:50:53

DIP2-Enhancement(PointProcessing)的相关文章

【论文:麦克风阵列增强】Speech Enhancement Based on the General Transfer Function GSC and Postfiltering

作者:桂. 时间:2017-06-06  16:10:47 链接:http://www.cnblogs.com/xingshansi/p/6951494.html 原文链接:http://pan.baidu.com/s/1i51Kymp 未完待续 前言 这篇文章是TF-GSC的改进版.虽然TF-GSC对于方向性干扰的抑制效果不错,对于弥散噪声(diffuse noise,题外话:不同方向directional noise的均值,或者接近这种效果,可以理解为diffuse noise.)TF-GS

SAP Table Enhancements (Master Data Enhancement of Customers and Vendors )

How to extend vendor or customer master data with SAP enhancement spots http://sapuniversity.eu/how-to-extend-vendor-or-customer-master-data-with-sap-enhancement-spots/ Step by step guide to enhance/update Vendor Master and generate idocs - Part1 htt

【ZT】Enhancement Framework – Introduction

Enhancement Framework – Introduction By Naimesh Patel | March 26, 2014 | Enhancement Implementation ABAP Enhancement Implementations concept which allows you to easily enhance the standard SAP delivered functionality with your desired one. With this

读书笔记:Speech enhancement: theory and practice

选读<Speech enhancement: theory and practice>.主要是自己的读书笔记. Chapter 1:Introduction 第一章~第四章,主要介绍语音增强算法的基础知识; Chapter 2:Discrete-Time Signal Processing and Short-Time fourier Analysis Chapter 3:Speech Production and Perception Chapter 4:Noise Compensation

CapsLock Enhancement via AutoHotKey

上次写了一篇博文,讲如何通过AutoHotKey改造CaspLock,使其成为一个方便的编辑按键,并特意给出了设计的思路方便参考. 见地址:http://www.cnblogs.com/Vonng/p/4240219.html 今日闲来无事,将这一脚本进行了不少修改,增加了一些更为实用的功能,例如媒体控制.并参照@shines77的改进将鼠标操作加入脚本中. 主要的改动包括:将CapsLock键 + F1到F7改造为了媒体功能键:CapsLock+B, W, S, Q的功能变更:CapsLock

ABAP Enhancement:第二部分

声明:原创作品,转载时请注明文章来自SAP师太技术博客:www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将追究法律责任!原文链接:http://www.cnblogs.com/jiangzhengjun/p/4291296.html 第三代:基于类的增强(BADI)... 25 BADI新方式实现... 42 1-构建BADI. 42 2-实现BADI. 44 3-使用BADI过滤器... 49 4-多个实现时究竟调谁... 51 查找系统中的BA

验证码识别 edge enhancement - 轮廓增强 region finding - 区域查找

Computer Science An Overview _J. Glenn Brookshear _11th Edition The task of understanding general images is usually approached as a two- step process: (1) image processing, which refers to identifying characteristics of the image, and (2) image analy

Enhancement in SAP abap.

Recently I have been taught through how to do enhancement for those standard programs. Th reason for doing enhancement is that since we can't directly change the standard code therefore we can add our own functionalities to it. Before implementing th

【译】wikibooks/Silhouette Enhancement

轮廓增强 原文: https://en.wikibooks.org/wiki/Cg_Programming/Unity/Silhouette_Enhancement A semitransparent jellyfish. Note the increased opaqueness at the silhouettes.一直半透明的水母,注意它的轮廓的不透明度是增强了的. This tutorial covers the transformation of surface normal vect

[ZZ] [siggraph10]color enhancement and rendering in film and game productio

原文link:<color enhancement and rendering in film and game production> 是siggraph 2010,“Color Enhancement and Rendering in Film and Game Production” course的一个paper. 从摄影到电影里面使用的技术,来启发游戏里怎么使用. 很不错的一个地方是:了解到了filmic tone mapping是怎么来的了,之前uncharted2的文章还看的我一头