0% found this document useful (0 votes)
14 views6 pages

DIP Lab.1 For Level 5th

The document provides an introduction to digital image processing using MATLAB, focusing on the differences between human vision and computer vision applications. It covers key topics such as image restoration, enhancement, and compression, as well as common image classes and types. Additionally, it outlines various laboratory tasks related to reading, displaying, and writing images, along with functions for converting image types and classes.
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)
14 views6 pages

DIP Lab.1 For Level 5th

The document provides an introduction to digital image processing using MATLAB, focusing on the differences between human vision and computer vision applications. It covers key topics such as image restoration, enhancement, and compression, as well as common image classes and types. Additionally, it outlines various laboratory tasks related to reading, displaying, and writing images, along with functions for converting image types and classes.
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/ 6

Digital Image Processing Laboratory

Lab.1: Introduction to Digital Image Processing Using MATLAB.

Digital Image Processing (Computer Imaging)

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.

➢ A digital image can be represented as a 2-D array (i.e. matrix) as follow:

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:

Name Size per pixel Description


Double-precision, floating-point numbers in the range
double 8 bytes
[0,1]
Single-precision, floating-point numbers in the range
single 4 bytes
[0,1]
uint8 1 byte Unsigned integer in the range [0,255]
uint16 2 bytes Unsigned integer in the range [0,65535]
logical 1 byte Values are 0 or 1

❖ 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

➢ [Task 1: Reading Images]


Syntax:
imread ('filename with path')
where
filename is a string containing the complete name of the image file (including any applicable
extension).
Examples:
F= imread('peppers.png');
I= imread('D:\myimages\peppers.png');
[I, Map] =imread ('trees.tif');

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]

▪ The common functions used for this purpose are:


im2uint8(I)
im2uint16(I)
im2double(I)
im2single(I)
Where
I is the image need to be converted.
Example:
F= imread('cameraman.tif');
imtool(F)
[I,Map]=imread('trees.tif');
n=im2double(F);
imtool(n)
m=im2double(I,'indexed'); %for indexed images we add a second
argument ‘indexed’
➢ [Task 7: Toolbox functions for converting between image types]
Syntax:
1- [X, map] = gray2ind(gray_image, n);
Where n is the length of the colormap and its default value is 64.
2- gray_image = ind2gray(X, map);
3- [X, map] = rgb2ind(rgb_image, n);
where n determines the number of colors of map.
4- rgb_image = ind2rgb(X, map);
5- gray_image = rgb2gray(rgb_image);
6- bw_image = im2bw(f, T)
Where
- f is the image T is the threshold value
- T value must be in the range [0, 1], regardless of the class of the input. For example, if f is
uint8 and T is 0.4, then im2bw thresholds the pixels in f by comparing them to 255 * 0.4 = 102.
- Pixel values >= T turned to white while Pixel values < T turned to black.

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)

Eng./ Maged Albadany

You might also like