Week11 (Image Processing)
Week11 (Image Processing)
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 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 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
• Rescaling
• Filtering
• Geometric transforms, ….
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
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
}
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
( , )= ( , )+
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
• Noise reduction
• Edge detection
• Image sharepening
• 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
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