Digital Image Processing Java Buffered Image Red Green
Digital Image Processing Java - Buffered Image Red Green Blue 1
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 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 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 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]; 0 511 …. . 0 …. . 511 . . …. . 0 7 9
An image class byte [ -128, 127 ] 0 7 Byte. Image image = new Byte. Image(100, 100); Byte. Image int width int height byte [ ] data Byte. Image int get. Width int get. Height int get. Pixel void set. Pixel (int w, int h) () () (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 get. Width int get. Height void get. Pixel void set. Pixel (int w, int h) () () (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 get. Width int get. Height Color get. Pixel void set. Pixel (int w, int h) () () (int x, int y, Color c) 12
An inheritance hierarchy for images with different pixel data types. Base. Array {abstract} Base. Image{abstract} int size int width int height Base. Array (int n) int get. Size double get. Element void set. Element double get. Mean. Value Base. Image (int w, int h) int get. Width ( ) int get. Height (int i) double get. Pixel (int x , int y) void set. Pixel (int x, int y, double value ) () (int i , double value) () Byte. Image byte [ ] data Byte. Image (int w, int h) Int. Image int [ ] data Int. Image (int w, 13 int h)
Image: Image image = Toolkit. get. Default. Toolkit( ). get. Image(file) Availability of image data: Image. Producer / Image. Consumer / Image. Filter / Pixel. Grabber Java 2 D API Buffered. Image /. . . 14
Java 2 D API Packages: 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
Java 2 D API Classes Image Buffered. Image Raster Color. Model Sample. Model Data. Buffer 16
Java 2 D API Classes Buffered. Image A Buffered. Image object consists of: - Color. Model - Raster Image Buffered. Image Raster Color. Model Sample. Model Data. Buffer 17
Java 2 D API Classes Color. Model The Color. Model specifies how the samples associated with each pixel in the Raster are implemented. Image Buffered. Image Raster The number of colorcomponent specified by the Color. Model must match the number of samples per pixel provided by the Raster. Color. Model Sample. Model Data. Buffer There are three subclasses of Color. Model that specify different implementation of pixel data: Direct. Color. Model, Index. Color. Model and Component. Color. Model. 18
Java 2 D API Classes Raster The Raster holds the image data. Every pixel in the Raster has one or more samples associated with it. Image Buffered. Image Raster The Raster can be decomposed into a Data. Buffer and a Sample. Model. Color. Model Sample. Model Data. Buffer The Raster class is used to inspect pixel values. Writable. Raster class (a subclass of Raster) is used to modify pixel values. 19
Java 2 D API Classes Sample. Model The Sample. Model specifies how the array elements managed by the Data. Buffer are translated into the samples of a particular pixel. Image Buffered. Image Raster Color. Model Sample. Model Data. Buffer 20
Java 2 D API Classes Data. Buffer The Data. Buffer is a wrapper for the array(s) used to store pixel data. Image Buffered. Image Raster Color. Model Sample. Model Data. Buffer 21
Types of Buffered. Image There are thirteen different standard types, representing different combinations of Color. Model and Sample. Model: TYPE_BYTE_BINARY TYPE_BYTE_GRAY TYPE_USHORT_GRAY TYPE_3 BYTE_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 Buffered. Image class get. Width get. Height get. Type get. Color. Model int () () get. RGB (int x, int y) int[ ] get. RGB (int x, int y, int w, int h, int[ ] data, int offset, int scansize) void set. RGB (int x, int y, int value) void set. RGB (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[ ] get. Pixels get. Sample. Float get. Sample. Double get. Samples (int x, int y, int[ ] data) (int x, int y, float[ ] data) (int x, int y, double[ ] data) (int x, int y, int w, int h, int[ ] data) (int x, int y, int w, int h, float[ ] data) (int x, int y, int w, int h, doble[ ] data) (int x, int y, int band) (int x, int y, int w, int h, int band, int[ ] data) (int x, int y, int w, int h, int band, float[ ] data) (int x, int y, int w, int h, int band, double[ ] data) 24
Methods provided by the Writable. Raster class to modify pixel values void void void set. Pixels set. Samples set. Samples (int x, int y, int[ ] data) (int x, int y, float[ ] data) (int x, int y, double[ ] data) (int x, int y, int w, int h, int[ ] data) (int x, int y, int w, int h, float[ ] data) (int x, int y, int w, int h, doble[ ] data) (int x, int y, int band) (int x, int y, int w, int h, int band, int[ ] data) (int x, int y, int w, int h, int band, float[ ] data) (int x, int y, int w, int h, int band, double[ ] data) 25
Data. Buffer Direct approach for writing the pixel data of an image to a file in binary form Output. Stream output = new Buffered. Output. Stream ( new File. Output. Stream(file) ) Data. Buffer. Byte db = ( Data. Buffer. Byte ) image. get. Raster( ). get. Data. Buffer( ) output. write ( db. get. Data( ) ) 26
Reading a Buffered. Image Read: File. Input. Stream file. Stream = new File. Input. Stream ( “in. jpg” ) JPEGImage. Decoder input = JPEGCodec. create. JPEGDecoder ( file. Stream ) Buffered. Image image = input. decode. As. Buffered. Image ( ) Write: File. Output. Stream file. Stream = new File. Output. Stream ( “out. jpg” ) JPEGImage. Encoder output = JPEGCodec. create. JPEGEncoder ( file. Stream ) output. encode ( image ) 27
A Swing component to display images 1 import java. awt. *; import java. awt. image. *; import javax. swing. *; public class Image. View extends Jlabel implements Scrollable { private Buffered. Image image; private Dimension view. Size; public Image. View (Buffered. Image img) { image = img; int width = Math. min(256, image. get. Width()); int height = Math. min(256, image. get. Heigth()); view. Size = new Dimension (width, height); set. Preferred. Size ( new Dimension(image. get. Width(), image. get. Height())); } public void paint. Component (Graphics g) { g. draw. Image ( image, 0, 0, this); } 28
A Swing component to display images 2 public void set. View. Size ( Dimension new. Size ) { view. Size. set. Size ( new. Size ); } public Dimension get. Preferred. Scrollable. Viewport. Size ( ) { return view. Size; } public int get. Scrollable. Unit. Increment ( Rectangle rect, int orient, int dir ) { return 1; } public int get. Scrollable. Block. Increment ( Rectangle, rect, int orient, int dir ) { if (orient == Swing. Constants. HORIZONTAL) return image. get. Width ( ) / 10; else return image. get. Height ( ) / 10; } public boolean get. Scrollable. Tracks. Viewport. Width ( ) { return false; } public boolean get. Scrollable. Tracks. Viewport. Height ( ) { return false; } } 29
Example: Shift of grey level in an image public Buffered. Image shift ( Buffered. Image image, int shift. Value ) { int w = image. get. Width( ); int h = image. get. Height( ); Buffered. Image shift. Image = new Buffered. Image(w, h, Buffered. Image. TYPE_BYTE_GRAY); Raster input Writable. Raster output = image. get. Raster( ); = shift. Image. get. Raster( ); for ( int y = 0; y < h; y++ ) { for ( int x = 0; x < w; x++) { output. set. Sample ( x, y, 0, input. get. Sample(x, y, 0) + shift. Value); } } return shift. Image; } 30
End 31
- Slides: 31