Download int always rounds

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
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)
Pixel [1][3]

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
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;
int y = 128/255;
int y = sin(x);
// y=0
// y=0
// 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
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.
6
Image enhancement

First, we will consider point processing where
enhancement at any point depends only on the
image value at that point.
7
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.
8
Thresholding
if image.get(x,y) < T
image.set(x,y,0);
else
image.set(x,y,255);
Images from http://www.svi.nl/SeedAndThreshold
Image enhancement
10
Image enhancement
11
Image enhancement
12
Image enhancement
13
Image enhancement
14
Image enhancement

Contrast stretching:
15
Image enhancement
16
Histogram processing
17
Histogram processing
2
2
2
3
3
4
5
5
1
1
2
2
4
5
6
5
0
1
1
2
2
6
7
7
0
0
1
2
2
4
6
4
9
5
4
3
4
3
2
0
1
2
3
2
4
5
6
7
18
Histogram processing
2
2
2
3
3
4
5
5
1
1
2
2
4
5
6
5
0
1
1
2
2
6
7
7
0
0
1
2
2
4
6
4
0.3
9
1.0
32
0
0
1
2
3
4
5
6
7
19
Histogram processing
20
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.
21
Histogram equalization
http://fourier.eng.hmc.edu/e161/lectures/contrast_transform/node3.html
22
Histogram equalization
23
Histogram equalization
Adapted from Wikipedia
CS 484, Fall 2012
©2012, Selim Aksoy
24
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.
http://fourier.eng.hmc.edu/e161/lectures/contrast_transform/node3.html
CS 484, Fall 2012
©2012, Selim Aksoy
25
26
Enhancement using logical operations

Boolean operations
Enhancement using logical operations

Boolean operations
Enhancement using logical operations

Boolean operations




NOT
AND
OR
XOR
INPUT
OUTPUT
A
B
NOT A
A AND B
A OR B
A XOR B
A AND NOT B
0
0
1
0
0
0
0
0
1
1
0
1
1
0
1
0
0
0
1
1
1
1
1
0
1
1
0
0
Enhancement using arithmetic operations

Addition/Subtraction
31
Enhancement using arithmetic operations

Multiplication
Enhancement using arithmetic operations

Masking, alpha channel = arithmetic operations
Geometric Transformations

34
Geometric Transformations

35
Geometric Transformations

36
Geometric Transformations in Code

37