Digital Image Processing Dr. Eng. Abdellatif BABA )2(
4/14/2017
Dr.Eng. A.BABA,
[email protected]
1
Once an image is acquired, and read into the computer’s memory as a matrix.
Based on the storage types standards, the most commonly used imaging formats are as follows: • Bitmap (.bmp) • Joint Photographic Experts Group (.jpg) • Graphics Interchange Format (.gif) • Tagged Image File Format (.tif) 4/14/2017
Dr.Eng. A.BABA,
[email protected]
2
Bitmap format is the standard for a Windows environment. • Used to store bitmap digital images, independently of the display device (Oparating System) • It is capable of storing two-dimensional, grayscale or colored images of any size and resolution. • Usually it does not compress images; but sometimes it may use compression. • The image data itself can contain pointers to some specific values in a color table. JPEG format is a standardized algorithm (not an image format) to compress natural images such as .bmp files or .tiff files using mathematical transformations. • The degree of compression is adjustable, allowing a selectable tradeoff between storage size and image quality. • Typically, it achieves 10:1 compression with little perceptible loss in image quality. 4/14/2017
Dr.Eng. A.BABA,
[email protected]
3
GIF format It defines a protocol intended for online transmission and interchange a matrix of pixels in a way that is independent of the hardware used in their creation or display. • GIF images are compressed using a lossless data compression technique to reduce the file size without degrading its visual quality. • GIF files cannot be used for high-precision color because only 8 bits are used to encode pixels.
TIFF format It handles images and data within a single file, by including: Image File Header (IFH), Image File Directory (IFD),
and Directory Entry (DE). • TIFF images are compressed using the same lossless data compression technique used for GIF format 4/14/2017
Dr.Eng. A.BABA,
[email protected]
4
Image arithmetic Usually, the following image operators are used as the building
blocks for complex processing: 1. Image addition
2. Image subtraction 3. Image multiplication
4. Image division 5. Image blending
4/14/2017
Dr.Eng. A.BABA,
[email protected]
5
Image arithmetic Image addition: Input: two or more images of the same size Output: an image of the same size, in which each pixel value is the sum of the values of the corresponding pixel from each of the input images. O(m,n) = I1(m,n) + I2(m,n),.........+Ik(m,n) Saturation efect: The overflowing pixel values are usually set to the maximum allowed value; Ex. (255). Blending:
O(m,n) = C X I1(m,n) + (1-C) X I2(m,n)
The output is a linear combination of the corresponding pixel values in the input images. C is the blending ratio by which the images must be scaled before combining them. (the influence of each input image in the output)
If it is desired to add a constant value C to a single image, then: O(m,n) = I(m,n) + C 4/14/2017
Dr.Eng. A.BABA,
[email protected]
6
Image arithmetic Image addition: I1 = imread ('rice.png'); size (I1) I2 = imread('coins.png'); size (I2) I1 = I1(1:246,1:246); imshow(I1) I2 = I2(1:246,1:246); figure; imshow(I2) O = imadd(I1,I2); figure; imshow(O) figure; imshow(O+50) 4/14/2017
Dr.Eng. A.BABA,
[email protected]
7
Image arithmetic Image addition: I = imread('peppers.png'); Iplus = imadd(I, 100);
figure ; imshow(I); figure ; imshow(Iplus);
4/14/2017
Dr.Eng. A.BABA,
[email protected]
8
Image arithmetic Image blending: I1 = imread('circles.png') ; I1 = im2uint8(I1); I1 = I1 (1:246,1:246); figure ; imshow(I1) I2 = imread('coins.png') ; I2 = I2 (1:246,1:246); figure ; imshow(I2) C = 0.8 ; O = imlincomb(C,I1,1-C,I2); figure ; imshow(O) C = 0.2 ; O = imlincomb (C,I1,1-C,I2); 4/14/2017 ; imshow (O) Dr.Eng. A.BABA,
[email protected] figure
9
Image arithmetic Image subtraction: Input: two or more images of the same size Output: an image of the same size, in which each pixel value is the subtraction of the values of the corresponding pixel from each of the input images. O(m,n) = I1(m,n) - I2(m,n),.........- Ik(m,n)
If it is desired to computes absolute differences, then: O(m,n) = I1(m,n) − I2(m,n),.........− Ik(m,n) In this case it is impossible for the output pixel values to be outside the range that may be represented by the input pixel values
If it is desired to subtract a constant value C to a single image, O(m,n) = I(m,n) - C then: 4/14/2017
Dr.Eng. A.BABA,
[email protected]
10
Image arithmetic Image subtraction : I1 = imread('Board 1.png'); I2 = imread('Board 2.png'); [rowsI1, colsI1, rgbI1]=size(I1); [rowsI2, colsI2, rgbI2]=size(I2); I2=imresize(I2,[rowsI1, colsI1]); O1 = imabsdiff(I1,I2) ; figure ; imshow(O1) O2 = 255-O1 ; figure ; imshow(O2)
4/14/2017
Dr.Eng. A.BABA,
[email protected]
11
Image arithmetic Pixel Multiplication and scaling Input: two images of the same size Output: a third image of the same size, in which each pixel value is just that of the first image, multiplied by the value of the corresponding pixel in the second image. O(m,n) = I1(m,n) X I2(m,n)
immultiply performs an element-by-element multiplication (.*)
Scaling by a constant is performed using O(m,n) = I(m,n) X C • If the output values are calculated to be larger than the maximum allowed pixel value, then they are usually truncated at that maximum value. • The same is also true for values less than the minimum allowed pixel values, in which case the truncation is done at the minimum value. 4/14/2017
Dr.Eng. A.BABA,
[email protected]
12
Image arithmetic Pixel multiplication : I1 = imread('coins.png') ; figure ; imshow(I1) f = fspecial('unsharp',0.2) ; figure ; mesh(f) O = conv2(I1,f) ; figure ; imshow(O)
The resulting matrix has values that are very high.
figure ; imshow(O*0.005) To be disscussed later: % fspecial('unsharp',α) creates the 3-by-3 unsharp filter from the negative of the Laplacian filter with parameter α that controls the shape of the Laplacian and must be in the range 0.0 to 1.0. Its default is 0.2. % conv2=(A, B) performs the 2-D convolution of matrices A and B. 4/14/2017
Dr.Eng. A.BABA,
[email protected]
13
Image arithmetic Pixel division Input: two images of the same size Output: a third image of the same size, in which each pixel value is the result of dividing the pixel’s intensity of the first image by the corresponding pixel value of the second image. O(m,n) = I1(m,n) / I2(m,n)
imdivide performs an element-by-element division (./)
Division by a constant is performed using O(m,n) = I(m,n) / C • Results are typically rounded down to the next lowest number for output • The ability to use images with pixel value types other than 8-bit integers becomes usefull when doing division. 4/14/2017
Dr.Eng. A.BABA,
[email protected]
14
Image arithmetic Pixel division : % repreated manip.
I1 = imread('coins.png') ; figure ; imshow(I1) f = fspecial('unsharp',0.2) ; figure ; mesh(f) O = conv2(I1,f) ; figure ; imshow(O)
The resulting matrix needs to be normalized
%%%%%%%%%% Division
figure ; imshow(O/max(max(O))) 4/14/2017
Dr.Eng. A.BABA,
[email protected]
15