Image 2 Subject : T0934 / Multimedia Programming Foundation

advertisement
Image 2
Subject
Session
Tahun
Versi
:
:
:
:
T0934 / Multimedia Programming Foundation
5
2009
1/0
Learning Outcomes
In the end of this session, students must be
able to:
– Understand the basic principal of
image transformation and
enhancement
– Apply correct Java syntax to
transform, enhance, and display an
image
Bina Nusantara
Course Outlines
•
•
•
•
Digital Image Definition
Image Transformation
Image Enhancement
Java 2D API
Bina Nusantara
Digital Image Definition
• Image  array of pixel  Z(x,y)
X
0
N
Z
Y
X = width (0 – N)
Y = height (0 – M)
Z = pixel values
M
Bina Nusantara
Digital Image Definition
• Image  Z(x,y)
• Z refers to RGB values or brightness
Z
Bina Nusantara
R
G
B
Z
Brightness
Image Transform in Java
• drawImage
– draw and scale an image
• ConvolveOp
– blur or sharpen an image
• AffineTransformOp
– transform an image
• Graphics2D.setClip
– crop an image
Bina Nusantara
Image Enhancement in Java
• LookupOp
– remap pixel colors (ex : a negative image)
• RescaleOp
– lighten/darken or reduce/increase opacity of
the image
Bina Nusantara
drawImage
This is an example
to draw image with
Java2D
Bina Nusantara
Image Transformation
newZ (x,y)
= F(Z(x,y))
= result of a Function based
on originalZ(x,y)
Horizontal Flipping
x’ = N – x
y’ = y
Bina Nusantara
Image Transformation
• Vertical Flipping
x’ = x
y’= M - y
Bina Nusantara
Image Transformation
• Rotation
a
x'
y'
z'
Bina Nusantara
=
cos a
sin a
0
-sin a
cos a
0
Matrix /
Kernel
0
0
1
x
y
Z
Image Rotation
• The basic algorithm is not used in practice
– contains unwanted gaps or holes  usually requires a greater number
of pixels than the source to properly display the rotation
Gaps/holes
• Therefore, interpolation is used to solve this
problem
Bina Nusantara
Image Interpolation
Interpolation
Interpolati
on
using known data to
estimate values at
unknown points.
Bina Nusantara
Nearest
Neighbor
• truncating the calculated
coordinates so that the fractional
part of the address is discarded
Bilinear
• employs a 2 x 2 array pixel set
surrounding the calculated pixel
address to obtain a new
transformed pixel value
Bicubic
• fitting a series of cubic polynomials
to the brightness values contained
in the 4 x 4 array of pixels
surrounding the calculated address
Image Transformation
• Cropping
• Scale
• Shear
Bina Nusantara
AffineTransformOp
Rotate
Full codes are
downloadable in
Additional Material
Bina Nusantara
AffineTransformOp
Shear
Full codes are
downloadable in
Additional Material
Bina Nusantara
AffineTransformOp
Scale
Full codes are
downloadable in
Additional Material
Bina Nusantara
AffineTransformOp
Translate
Full codes are
downloadable in
Additional Material
Bina Nusantara
Scale
sx 0
x’
y’
1
Bina Nusantara
=
0
0
sy 0
0
0
1
x
*
y
1
RescaleOp
Rescaling
Full codes are downloadable in Additional Material
Bina Nusantara
Shear
x’
y’
1
Bina Nusantara
=
1
h
0
0
1
0
0
0
1
x
*
y
1
Image Enhancement
Convolution
• an operation in which the final pixel is the weighted sum of the
neighboring pixels
• Use matrix/kernel as well  convolution kernel / linear filter
Convolution
Kernel
Edge
Detection
Blurring
Sharpening
Bina Nusantara
Convolution
• Blurring
Note : This is only an example
of many blur kernel variations
X
Y
Z
Bina Nusantara
1
2
1
2
4
2
1
2
1
Convolution
• Sharpening
X
Y
Z
Bina Nusantara
Note : This is only an example of
many sharpen kernel variations
-1
-1
-1
-1
9
-1
-1
-1
-1
Convolution
• Edge Detection
X
Y
Z
Bina Nusantara
Note : This is only an example of
many edge detection kernel variations
-1
-1
-1
-1
8
-1
-1
-1
-1
ConvolveOp
Blur
Bina Nusantara
Full codes are downloadable in Additional Material
ConvolveOp
Sharpen
Bina Nusantara
Full codes are downloadable in Additional Material
ConvolveOp
Edge
Bina Nusantara
Full codes are downloadable in Additional Material
Image Enhancement
• Brighten/Darken
Brighten
Darken
• Opacity
Bina Nusantara
Opacity 80%
Opacity 50%
Graphics2D.setClip
setClip is used to clip a
portion of images to
make a new image
Bina Nusantara
LookupOp
Invert Color
Full codes are downloadable in Additional Material
Bina Nusantara
References
•
•
•
•
•
•
•
•
•
•
Image Processing with Java 2D. 2008. http://www.javaworld.com/javaworld/jw-091998/jw-09-media.html?page=3
Image Processing and Enhancement. 1999.
http://java.sun.com/j2se/1.3/docs/guide/2d/spec/j2d-image.fm8.html
Image Processing Fundamentals. 2009.
http://www.ph.tn.tudelft.nl/Courses/FIP/noframes/fip.html
Basic Concepts in Digital Image Processing. 2004.
http://micro.magnet.fsu.edu/primer/digitalimaging/javaindex.html
The Digital Darkroom. 2003. http://www.spinroot.com/pico/a3.pdf
Transforming Shapes, Text, and Images. 2008.
http://java.sun.com/docs/books/tutorial/2d/advanced/transforming.html
Digital Image Interpolation. 2009. http://www.cambridgeincolour.com/tutorials/imageinterpolation.htm
Image Convolution. 2009. http://www.eas.asu.edu/~karam/2dconvolution/
Image Filtering with GLSL - Convolution Kernels. 2009.
http://www.ozone3d.net/tutorials/image_filtering.php
Fundamentals of Image Processing. 2009.
http://www.cs.dartmouth.edu/~farid/tutorials/fip.pdf
Bina Nusantara
Download