DIP Lab.1 For Level 5th
DIP Lab.1 For Level 5th
Computer Human
vision Image analysis vision
• Human vision applications involve a human being in the visual loop. In other words, the images are to be
examined and acted upon by people (input is an image and output is a processed image).
• Computer vision applications do not involve a human being in the visual loop. In other words, the output
images are for computer use (input is an image and output are information).
➢ The major topics within the field of image processing for human vision applications include:
1- Image restoration: The process of taking an image with some known, or estimated, degradation (like
motion blur, noise and camera misfocus), and restoring it to its original appearance.
2- Image enhancement: Improving an image visually (like contrast enhancement, image sharpening)
3- Image compression: Reducing the amount of data needed to represent an image.
Where:
Each element of this array is called a pixel (picture element).
f(x,y) is proportional to the brightness(intensity) of the image at the point (x,y).
1
❖ Common Image Classes:
❖ Image Types:
1- Gray-scale Images:
A gray-scale image is a data matrix whose values represent black, white and shades of gray
It can be of class uint8, uint16, single or double.
2- Binary Images:
A binary image is a logical array of 0s and 1s (i.e. 0 for black and 1 for white)
3- RGB images
An RGB color image is an M X N X 3 array of color pixels, where each color pixel is a triplet
corresponding to the red, green, and blue components of an RGB image at a specific spatial location as
shown below:
The number of possible colors in an RGB image is (2b)3 where b is the number of bits in each component image.
For an 8-bit image, the number is 224 =16,777,216 colors.
2
4- Indexed Images:
An indexed image has two components: an image matrix of integers, X, and a color map matrix, map.
Matrix map is an m X 3 array of class double containing floating-point values in the range [0,1]. The
length (i.e. number of rows) of the map is equal to the number of colors it defines. Each row of map
specifies the red, green, and blue components of a single color. The color of each pixel is determined by
using the corresponding value of integer matrix X as an index (hence the name indexed image) into map.
These concepts are illustrated in Figure bellow:
Notes:
1- The key difference between the indexed image and RGB image is that the indexed image has a limited
number of colors.
2- If the three columns of map are equal, the color map becomes a gray-scale map.
Laboratory Tasks
3
Where
trees.tif is an indexed image.
I is the image matrix and Map is the color map matrix.
➢ [Task 2: Reading Images by using GUI]
Syntax:
[n p] =uigetfile( );
I=imread ([p n]);
Where
n is the image name
p is the full path
➢ [Task 3: Displaying Images]
Syntax:
imshow(f)
where f is an image array.
Imshow(I,Map)
where I is the image matrix and Map is the color map matrix.
Examples:
F= imread('peppers.png');
[I, Map] =imread ('trees.tif');
imshow(F)
figure,imshow(I, Map)
➢ [Task 4: writing Images]
Syntax:
imwrite (f, 'new_filename with path');
Example:
F= imread('rice.png');
[I, Map] =imread ('trees.tif'); % indexed image
F(50:100,50:150)=F(50:100,50:150)+100;
imshow(F)
imwrite(I,Map,'F:\trees.jpg') % writing indexed image
imwrite(F,'F:\rice2.tif')
➢ [Task 5: writing Images by using GUI]
Syntax:
[n p] =uiputfile( );
imwrite (I, [p n]);
4
Where
I is the image need to be written.
n is the new image name.
p is the full path.
➢ [Task 6: Toolbox functions for converting images from one class to another]
5
Example:
F= imread('peppers.png');
[I,Map]=rgb2ind(F,32); % reducing the number of colors to 32
D=imread('rice.png');
BW=im2bw(D,0.4);
figure,subplot(2,1,1)
imshow(F)
subplot(2,1,2)
imshow(I,Map)
figure,subplot(2,1,1)
imshow(D)
subplot(2,1,2)
imshow(BW)
➢ [Task 8: execute the following code with a MATLAB script then write your observations]
a=imread('pout.tif');
[r,c]=size(a);
for i=1:1:r
k=1;
for j=c:-1:1
temp=a(i,k);
result(i,k)=a(i,j);
result(i,j)=temp;
k=k+1;
end
end
subplot(1,2,1),imshow(a)
subplot(1,2,2),imshow(result)