Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

EE-333 Digital Image Processing

DIP in MATLAB - A Quick Overview!

Dr Tahir Nawaz
Website: https://www.tahirnawaz.com
Email: tahir.nawaz@ceme.nust.edu.pk
MATLAB environment
MATLAB Help and Documentation
MATLAB Help and Documentation
Writing script in m-file
Image skeleton
• Grayscale image
Image skeleton
• Color image
Image coordinate system used in MATLAB!
Reading and showing an image
• We can read an image in MATLAB using the imread
function
img = imread('face.jpg');
imshow(img);
Some image formats supported by imread()
Accessing image data
• Grayscale image
– We can access each pixel by using it’s respective row number (r)
and column number (c) as follows:

img(r,c)  accessing pixel at position (r,c)


Accessing image data
• Grayscale image
– We can loop through image accessing each pixel one by one:
Accessing image data
• Grayscale image
– We can access each pixel by using it’s respective row number (r)
and column number (c) as follows:
img(r,c)  accessing pixel at position (r,c)
img(:,1)  accessing first column
img(1,:)  accessing first row
Accessing image data
• Color image
– We can access each pixel by using it’s respective row number (r)
and column number (c) as follows:
img(r,c,1) Value at pos (r,c) in Red channel
img(r,c,2) Value at pos (r,c) in Green channel
img(r,c,3) Value at pos (r,c) in Blue channel
Manipulating image data
• Rotating image matrix!
Manipulating image data
• Flipping image matrix!
Creating/writing to an image file
• We can create an image by using the imwrite function
as follows:

imwrite(img, ‘out_image.png’);

• Supported image formats (all except GIF)


Brightening image data
• Scaling image data by a factor!
Segmenting foreground and background
• Applying thresholding to segment object of interest from background
Home Task
• Given the following image that is in grayscale format (8 bits, 256
levels), write MATLAB code to quantize it 1 bit (2 levels), 2 bits (4
levels), 3 bits (8 levels), 4 bits (16 levels), 5 bits (32 levels), 6 bits (64
levels) and 7 bits (128 levels). Original image file is uploaded on LMS
under /examples.

You might also like