Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
Digital Image Processing
Java - Buffered Image
Red
Green
Blue
1
Digital Image Processing
Digital Image Processing
Manipulation of images by computer
Input Image
Computer
Output Image
Digital
Image
Processing
2
Physical Image
Analog image
Digital Image
Black
255
Gray
128
White
0
Digital image
3
Colors
255
Black
128
Gray
0
White
255
128
=
0
Red
Green
Blue
Equal
portions
4
of RGB
RGB Colour Cube
B
RGB (Red, Green, Blue)
are the primary colours of the additive colour system.
Blue
Cyan
White
Magenta
Black
Red
Green
Yellow
G
RGB-model in image display,
but of limited use when processsing
color images, because it is not a
perceptual model.
In perceptual terms, colour and intensity
are distinct from one another,
but the RGB components each contain
both colour and intensity information.
R
5
CMY (Cyan, Magenta, Yellow) Colour Model
CMY (Cyan, Magenta, Yellow)
are the primary colours of the subtractive colour system.
B
Blue
C 1 R
M 1 G
Y 1 B
White
Magenta
Black
Red
R
Cyan
Green
Yellow
G
RGB-model in image display,
but of limited use when processsing
color images, because it is not a
perceptual model.
In perceptual terms, colour and intensity
are distinct from one another,
but the RGB components each contain
both colour and intensity information.
6
HSI (Hue, Saturation, Intensity) Colour Model
CMY (Cyan, Magenta, Yellow)
are the primary colours of the subtractive colour system.
B
Blue
C 1 R
M 1 G
Y 1 B
White
Magenta
Black
Red
R
Cyan
Green
Yellow
G
RGB-model in image display,
but of limited use when processsing
color images, because it is not a
perceptual model.
In perceptual terms, colour and intensity
are distinct from one another,
but the RGB components each contain
both colour and intensity information.
7
Image Operations
Global Operations
Gray-Level Histogram
Histogram Equalization
Histogram Matching
Photometric Calibration
Display Calibration
Local Operations
Point Operations
Linear Point Operations
Nonlinear Monotonic Point Operations
Algebraic Operations
Addition / Subtraction / Multiplication / Division
Geometric Operations
Gray-Level Interpolation
Spatial Transformation
Linear System Theory
Fourier Transformations
Wavelets Transformations
8
8-bit greyscale images
byte [ ] [ ] image = new byte [512] [512];
0
511
…..
0
…..
.
.
511
.
.
.
.
…..
0
7
9
An image class
byte
[ -128, 127 ]
0
7
ByteImage image = new ByteImage(100,100);
ByteImage
int width
int height
byte [ ] [ ] data
ByteImage
int getWidth
int getHeight
int getPixel
void setPixel
(int w, int h)
()
()
(int x, int y)
(int x, int y, int value)
10
An RGBImage class
R
G
B
RGBImage
int width
int height
byte [ ] red
byte [ ] green
byte [ ] blue
RGBImage
int getWidth
int getHeight
void getPixel
void setPixel
(int w, int h)
()
()
(int x, int y, int[ ] rgb)
(int x, int y, int[ ] rgb)
11
An RGBImage class.
Use of an array of Color objects.
RGBImage
1
1..*
Color
int width
int height
RGBImage
int
getWidth
int
getHeight
Color getPixel
void setPixel
(int w, int h)
()
()
(int x, int y)
(int x, int y, Color c)
12
An inheritance hierarchy for images
with different pixel data types.
BaseArray {abstract}
BaseImage{abstract}
int size
int width
int height
BaseArray (int n)
int
getSize
double getElement
void
setElement
double getMeanValue
BaseImage (int w, int h)
int
getWidth ( )
int
getHeight (int i)
double getPixel (int x , int y)
void
setPixel (int x, int y, double value )
()
(int i)
(int i , double value)
()
ByteImage
byte [ ]
data
ByteImage (int w, int h)
IntImage
int [ ] data
IntImage (int w, 13
int h)
Image
Image:
Image image = Toolkit.getDefaultToolkit( ).getImage(file)
Availability of image data:
ImageProducer / ImageConsumer / ImageFilter / PixelGrabber
Java2D API
BufferedImage / ...
14
Java2D API Packages
Packages:
java.awt
java.awt.image
java.awt.color
java.awt.font
java.awt.geom
java.awt.print
java.awt.renderable
com.sun.image.codec.jpeg
Image class
15
Java2D API Classes
Image
BufferedImage
Raster
ColorModel
SampleModel
DataBuffer
16
Java2D API Classes
BufferedImage
A BufferedImage object consists of:
- ColorModel
- Raster
Image
BufferedImage
Raster
ColorModel
SampleModel
DataBuffer
17
Java2D API Classes
ColorModel
The ColorModel specifies how the samples
associated with each pixel in the Raster
are implemented.
Image
BufferedImage
Raster
The number of colorcomponent specified
by the ColorModel must match the number
of samples per pixel provided by the Raster.
ColorModel
SampleModel
DataBuffer
There are three subclasses of ColorModel
that specify different implementation
of pixel data:
DirectColorModel, IndexColorModel and
ComponentColorModel.
18
Java2D API Classes
Raster
The Raster holds the image data.
Every pixel in the Raster
has one or more samples associated with it.
Image
BufferedImage
Raster
The Raster can be decomposed into
a DataBuffer and a SampleModel.
ColorModel
SampleModel
DataBuffer
The Raster class
is used to inspect pixel values.
WritableRaster class (a subclass of Raster)
is used to modify pixel values.
19
Java2D API Classes
SampleModel
The SampleModel
specifies how the array elements
managed by the DataBuffer
are translated into the samples of
a particular pixel.
Image
BufferedImage
Raster
ColorModel
SampleModel
DataBuffer
20
Java2D API Classes
DataBuffer
The DataBuffer is a wrapper for the array(s)
used to store pixel data.
Image
BufferedImage
Raster
ColorModel
SampleModel
DataBuffer
21
Types of BufferedImage
There are thirteen different standard types,
representing different combinations of ColorModel and SampleModel:
TYPE_BYTE_BINARY
TYPE_BYTE_GRAY
TYPE_USHORT_GRAY
TYPE_3BYTE_BGR
TYPE_INT_RGB
...
1-bit sample for each pixel; 8 samples packed into a byte
8-bit sample for each pixel, stored in a byte
16-bit sample for each pixel, stored in a short
8-bit blue, green and red samples, each stored in one byte
8-bit red, green and blue samples, packed into an int
22
Methods provided by the BufferedImage class
getWidth
getHeight
getType
getColorModel
int
()
()
()
()
getRGB (int x, int y)
int[ ] getRGB (int x, int y, int w, int h, int[ ] data, int offset, int scansize)
void setRGB
(int x, int y, int value)
void setRGB
(int x, int y, int w, int h, int[ ] data, int offset, int scansize)
23
Methods provided by the Raster class
to inspect pixel values
int[ ]
float[ ]
double[ ]
int[ ]
float[ ]
double[ ]
int
float
double
int[ ]
float[ ]
double[ ]
getPixel
getPixel
getPixel
getPixels
getPixels
getPixels
getSample
getSampleFloat
getSampleDouble
getSamples
getSamples
getSamples
(int x, int y,
(int x, int y,
(int x, int y,
(int x, int y,
(int x, int y,
(int x, int y,
(int x, int y,
(int x, int y,
(int x, int y,
(int x, int y,
(int x, int y,
(int x, int y,
int[ ] data)
float[ ] data)
double[ ] data)
int w, int h, int[ ] data)
int w, int h, float[ ] data)
int w, int h, doble[ ] data)
int band)
int band)
int band)
int w, int h, int band, int[ ] data)
int w, int h, int band, float[ ] data)
int w, int h, int band, double[ ] data)
24
Methods provided by the WritableRaster class
to modify pixel values
void
void
void
void
void
void
void
void
void
void
void
void
setPixel
setPixel
setPixel
setPixels
setPixels
setPixels
setSample
setSample
setSample
setSamples
setSamples
setSamples
(int x, int y,
(int x, int y,
(int x, int y,
(int x, int y,
(int x, int y,
(int x, int y,
(int x, int y,
(int x, int y,
(int x, int y,
(int x, int y,
(int x, int y,
(int x, int y,
int[ ] data)
float[ ] data)
double[ ] data)
int w, int h, int[ ] data)
int w, int h, float[ ] data)
int w, int h, doble[ ] data)
int band)
int band)
int band)
int w, int h, int band, int[ ] data)
int w, int h, int band, float[ ] data)
int w, int h, int band, double[ ] data)
25
DataBuffer
Direct approach for writing the pixel data of an image to a file in binary form
OutputStream output = new BufferedOutputStream ( new FileOutputStream(file) )
DataBufferByte db
= ( DataBufferByte ) image.getRaster( ).getDataBuffer( )
output.write ( db.getData( ) )
26
Reading a BufferedImage
Read:
FileInputStream
fileStream = new FileInputStream ( “in.jpg” )
JPEGImageDecoder input
= JPEGCodec.createJPEGDecoder ( fileStream )
BufferedImage
image
= input.decodeAsBufferedImage ( )
Write:
FileOutputStream
fileStream = new FileOutputStream ( “out.jpg” )
JPEGImageEncoder output
= JPEGCodec.createJPEGEncoder ( fileStream )
output.encode ( image )
27
A Swing component to display images 1
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
public class ImageView extends Jlabel implements Scrollable {
private BufferedImage image;
private Dimension
viewSize;
public ImageView (BufferedImage img) {
image
= img;
int width = Math.min(256, image.getWidth());
int height = Math.min(256, image.getHeigth());
viewSize = new Dimension (width, height);
setPreferredSize ( new Dimension(image.getWidth(), image.getHeight()));
}
public void paintComponent (Graphics g) {
g.drawImage ( image, 0, 0, this);
}
28
A Swing component to display images 2
public void setViewSize ( Dimension newSize ) {
viewSize.setSize ( newSize );
}
public Dimension getPreferredScrollableViewportSize ( ) {
return viewSize;
}
public int getScrollableUnitIncrement ( Rectangle rect, int orient, int dir ) {
return 1;
}
public int getScrollableBlockIncrement ( Rectangle, rect, int orient, int dir ) {
if (orient == SwingConstants.HORIZONTAL)
return image.getWidth ( ) / 10;
else
return image.getHeight ( ) / 10;
}
public boolean getScrollableTracksViewportWidth ( ) {
return false;
}
public boolean getScrollableTracksViewportHeight ( ) {
return false;
}
}
29
Example: Shift of grey level in an image
public BufferedImage shift ( BufferedImage image, int shiftValue ) {
int w = image.getWidth( );
int h = image.getHeight( );
BufferedImage shiftImage = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_GRAY);
Raster
input
WritableRaster output
= image.getRaster( );
= shiftImage.getRaster( );
for ( int y = 0; y < h; y++ ) {
for ( int x = 0; x < w; x++) {
output.setSample ( x, y, 0, input.getSample(x,y,0) + shiftValue);
}
}
return shiftImage;
}
30
End
31