0% found this document useful (0 votes)
15 views27 pages

Week11 (Image Processing)

Uploaded by

cheery.bowl7899
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views27 pages

Week11 (Image Processing)

Uploaded by

cheery.bowl7899
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

Image

processing
Image processing
01 What is an image ?
02 Spectral rescale
03 Geometric transformation
04 Image filtering
05 Color conversion
06 Lookup table editing
Image processing
Image processing
What is an image
• A grid (matrix) of intensity values and is defined by
an array of point values called pixels
255 255 255 255 255 255 255 255 255 255 255 255

255 255 255 255 255 255 255 255 255 255 255 255

255 255 255 20 0 255 255 255 255 255 255 255

255 255 255 75 75 75 255 255 255 255 255 255

255 255 75 95 95 75 255 255 255 255 255 255

255 255 96 127 145 175 255 255 255 255 255 255

255 255 127 145 175 175 175 255 255 255 255 255

255 255 127 145 200 200 175 175 95 255 255 255

255 255 127 145 200 200 175 175 95 47 255 255

255 255 127 145 145 175 127 127 95 47 255 255

255 255 74 127 127 127 95 95 95 47 255 255

255 255 255 74 74 74 74 74 74 255 255 255

255 255 255 255 255 255 255 255 255 255 255 255

255 255 255 255 255 255 255 255 255 255 255 255
(common to use one byte per value: 0 = black, 255 = white)
Image processing

• Each pixel value represent a color, gray level, and other attributes of the corresponding

point

• Images are useful objects in graphic rendering.

• The output of graphics rendering is typically an image

• Java 2D offers power image-processing facilities

• Rescaling

• Filtering

• Geometric transforms, ….
Image processing

● The image class BufferedImage is used to represent an image with an


immediately available data store.
● A BufferedImage contains a Raster and a ColorModel.
● A Raster represents pixel values in numerical forms and a ColorModel specifies
the mapping between numerical values in the raster and the actual color
● JAVA Advanced Image (JAI) is an optional package that offers even more
advanced and comprehensive image processing capabilities.
Image processing

-The source image is usually given as a file in one of many image file formats
-An object is created in the java program to represent an image
-The external image file needs to be read into image object
-The image may be displayed in a device such as a screen or printer
-The next step is to process the image through one or more image processing operators.
-The result is another image object
-The processed image can be displayed and written to an external image file
Image processing

- A Java 2D image processing program uses BufferedImage to represent images


The following creates a blank buffered image

BufferedImage bi = new BufferedImage(300, 400,BufferedImage.TYPE_INT_RGB);

With the graphic2D object g2 you may perform all types of graphics renderings on the
BufferedImage, just like drawing to the screen

Graphics2D g2 = (Graphics2D)(bi.createGraphics());
Image processing

public void paintComponent(Graphics g){


super.paintComponent(g);
Graphics2D g2=(Graphics2D) g;
BufferedImage bi = new BufferedImage(500, 500,
BufferedImage.TYPE_INT_RGB);
Graphics2D gi = (Graphics2D)(bi.createGraphics());
Parm(gi);//add the drawing
g2.drawImage(bi, 0,0, this);
try {
File initialImage = new File("d://image.jpg");
ImageIO.write(bi,"jpg", initialImage);
} catch (IOException e){}

}
Image processing

BufferedImage img;
public void paint(Graphics g) {

g.drawImage(img, 0, 0, null); }
public LoadImageApp() {
try {
img = ImageIO.read(new File("earth.png"));
} catch (IOException e) { }
}
Image processing
Spectral rescaling
Image processing
Spectral rescaling

This transform applies pixel by pixel transformation of color based on some linear function

( , )= ( , )+

Commonly used to lighten or darken a given image


𝑔
𝑥
𝑦
𝑎
𝑓
𝑥
𝑦
𝑏
Image processing
Spectral rescaling

Original image

Lightened image
with factors 2,0
darkened image with
a=0.6,b=0

RescaleOp li=new
RescaleOp(2.0f,0,null);
RescaleOp dr=new RescaleOp(0.6f,0,null);
g2.drawImage(li.filter(src, g2.drawImage(dr.filter(src, null),
null), 0,src.getHeight(), 2*src.getWidth(),src.getHeight(), this);
this);
Image processing
Geometric transformations
Image geometric transformation
This operation has no effect on the pixel intensities
The effect of such operation is on the pixel locations that are reorganized according to the performed
operations

( , ) = ( ( , ))
Where T is the geometric transform
𝑔
𝑥
𝑦
𝑓
𝑇
𝑥
𝑦
Geometric transformation
code

AffineTransform xform = new


AffineTransform();
xform.setToRotation(Math.PI/6);
op = new AffineTransformOp(xform,
AffineTransformOp.TYPE_BILINEAR);
dstImage = op.filter(sourceImage, null);
Image processing
Filtering
Image filtering
• The image filtering intended to spatially enhance the image properties such as edges.

• Main purposes of filtering:

• Noise reduction

• Edge detection

• Image sharepening

• Mathematically convolution operation is used to apply a given filter on a given image

• Mathematically a filter is a matrix of values that is commonly of odd size with specific effect
Filter types
• Noise reduction –smoothing- filters

1 1 1
1 1 1
1 1 1
Filter types
• Edge detection filters
Filter types
0 -1 0
• Image sharpening filters -1 5 -1
0 -1 0
Image filtering in code

float[] data = {0f, -1f, 0f, -1f, 4f, Remark the ordering
-1f, 0f, -1f, 0f};
Kernel ker = new Kernel(3,3,data);
op = new ConvolveOp(ker);
dstImage = op.filter(sourceImage,
null);
Image processing
Color conversion
Image processing
Color conversion

ColorConvertOp performs pixel by pixel conversions of colors.

ColorSpace cs =
ColorSpace.getInstance(ColorSpace.CS_GRAY);
ColorConvertOp op = new ColorConvertOp(cs, null);
resImage=op.filter(im, null);
Image processing
Lookup operation
Image processing
LookupOp

LookupOp performs pixel by pixel conversion of pixel values based on lookup


table

short[] data = new short[256]; Prepare the values for lookup


for (short i = 0; i < 256; i++) {
data[i] = 255 - i;
}

Create the lookup LookupTable lookupTable = new ShortLookupTable(0, data);


LookupOp op = new LookupOp(lookupTable, null);
dstImage = op.filter(sourceImage, null);
Thank You

You might also like