Image Enhancement Christoph Lampert / Chris Wojtan Some slides adapted from Selim Aksoy, Bilkent University
Representing an Image in Code 2D matrix of values, starting from the upper left (start counting at zero) Integer, floating point, …, ? boolean (0=black, 1=white) floating point (0.0=black, 1.0=white) 8-bit integer (0=black, 255=white) – most common Whatever is convenient Floating point is good for continuous math (exponentiation, division, …) Integers are useful for dividing up values into discrete sets (histograms, segmentation, …) 2 Pixel [1][3]
ImageJ You will write some code for homework Accessing and writing in an image image.get(10,15); tells us the pixel value at row 10, column 15 image.set(10, 25, 0); sets that pixel value to black Repeating an operation for every pixel for (int y=0; y<yMax; y++) for (int x=0; x<xMax; x++) image.set(x, y, 0); 3
Beware – “casting” between int and double Most images need ints in the end, but intermediate computation should be in doubles. int always rounds to an integer. This is usually undesired. int y = 0.9;// y=0 int y = 128/255;// y=0 int y = sin(x);// y=0 “Cast” between the two types (double) will treat a number like a real value (int) will treat a number like an integer int x = 100; int num_pixels = 1024; double f = (double) x / (double) num_pixels; int output_value = (int) (f * 255.0); 4
ImageJ Demos Black.java Linear.java SineWave.java Checker.java Circle.java Max.java Template.java Compute_Histogram.java 5
6 Image enhancement The principal objective of enhancement is to process an image so that the result is more suitable than the original for a specific application. Enhancement can be done in Spatial domain, Frequency domain. Common reasons for enhancement include Improving visual quality, Improving machine recognition accuracy.
7 Image enhancement First, we will consider point processing where enhancement at any point depends only on the image value at that point.
8 Image enhancement First, we will consider point processing where enhancement at any point depends only on the image value at that point. For gray level images, we will use a transformation function of the form s = T(r) where “r” is the original pixel value and “s” is the new value after enhancement.
Thresholding if image.get(x,y) < T image.set(x,y,0); else image.set(x,y,255); Images from
10 Image enhancement
11 Image enhancement
12 Image enhancement
13 Image enhancement
14 Image enhancement
15 Image enhancement Contrast stretching:
16 Image enhancement
17 Histogram processing
18 Histogram processing
19 Histogram processing
20 Histogram processing
21 Histogram processing Intuitively, we expect that an image whose pixels tend to occupy the entire range of possible gray levels, tend to be distributed uniformly will have a high contrast and show a great deal of gray level detail. It is possible to develop a transformation function that can achieve this effect using histograms.
22 Histogram equalization
23 Histogram equalization
CS 484, Fall 2012©2012, Selim Aksoy 24 Histogram equalization Adapted from Wikipedia
CS 484, Fall 2012©2012, Selim Aksoy 25 Histogram specification whatever the heck you want The math is similar, but your new image has a histogram close to any p(y), instead of a uniform distribution.
26
CS 484, Fall 2012©2012, Selim Aksoy 27 Histogram equalization Original RGB imageHistogram equalization of each individual band/channel Histogram stretching by removing 2% percentile from each individual band/channel
Enhancement using logical operations Boolean operations
Enhancement using logical operations Boolean operations
Enhancement using logical operations Boolean operations NOT AND OR XOR INPUTOUTPUT ABNOT AA AND BA OR BA XOR BA AND NOT B
31 Enhancement using arithmetic operations Addition/Subtraction
Enhancement using arithmetic operations Multiplication
Enhancement using arithmetic operations Masking, alpha channel = arithmetic operations
34 Geometric Transformations
35 Geometric Transformations
36 Geometric Transformations
37 Geometric Transformations in Code