introduction to image processing with matlab
DESCRIPTION
The slides describes the fundamentals of image processing with MATLAB for beginners with sample MATLAB codesTRANSCRIPT
![Page 1: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/1.jpg)
A QUICK
INTRODUCTION TO IMAGE PROCESSING WITH MATLAB
Presenter,Sriram Emarose
Follow me @ : http://sriramemarose.blogspot.in/&
linkedin/sriramemarose
![Page 2: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/2.jpg)
Vision?Every technology comes from Nature:
Eye - Sensor to acquire photons Brain - Processor to process photoelectric signals from eye
![Page 3: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/3.jpg)
Step 1. Light(white light) falling on objects
Step 2. Eye lens focuses the light on retina
Step 3. Image formation on retina, and
Step 4. Developing electric potential on retina (Photoelectric effect)
Step 5. Optical nerves transmitting developed potentials to brain (Processor)
Natural Sensor (EYE) – Working mechanism
![Page 4: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/4.jpg)
Natural Processor (Brain) – Perception of image
Optic nerves – Transmission medium
Hey, I got potentials of X
values(Temporal lobe)
Yes, I know what does it mean(Frontal lobe)
To frontal lobe,From Temporal
lobe
![Page 5: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/5.jpg)
Neuronal Communication and logical analysing in brain
![Page 6: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/6.jpg)
Different species absorbs different spectral wavelength
Which implies different sensors(eye) have different reception abilities
Light Spectra
![Page 7: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/7.jpg)
Color of the images depends on the type photo receptors
Primary color images – RGB Photoreceptor – Cones
Image colors
Gray scale images (commonly known as black and white ) Photoreceptor - Rods
Guess why it takes time to see objects in dark after being in bright light?
![Page 8: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/8.jpg)
Enough understanding nature?
![Page 9: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/9.jpg)
Camera Man made technology that mimics operation of an eye
Array of photoreceptors and film (to act as retina - cones and rods)
Lens to focus light from surrounding/objects on the photoreceptors (mimics Iris and eye lens)
![Page 10: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/10.jpg)
Camera with CCD sensors
![Page 11: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/11.jpg)
Camera with CMOS sensors
![Page 12: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/12.jpg)
Computer perception of an image
)1,1()1,1()0,1(
)1,1()1,1()0,1(
)1,0()1,0()0,0(
),(
NMfMfMf
Nfff
Nfff
yxf
Gray line – Continuous analog signals from sensors
Dotted lines – Sampling time
Red line – Quantized signal
Digital representation of image obtained from the quantized signal
![Page 13: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/13.jpg)
Got the image matrix, what next?Different types of images often used,
Color – RGB -> remember cones in eyes? R –> 0-255 G –> 0-255 B –> 0-255
Grayscale -> remember rods in eyes? 0 – Pure black/white 1-254 – Shades of black and white(gray) 255 – Pure black/white
Boolean 0- Pure black/white 1- Pure white/black
![Page 14: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/14.jpg)
What do you see?
Single pixel with respective RGB values
RGB Image
![Page 15: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/15.jpg)
Lets zoom out
Combination of RGB values of each pixel contributing to form an image
![Page 16: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/16.jpg)
Grayscale image
Pure black->0Shades of black&white -> 1-254White-> 255
![Page 17: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/17.jpg)
Grayscale image
![Page 18: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/18.jpg)
Binary image
![Page 19: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/19.jpg)
Bored with fundamentals?
LETS DO SOMETHING INTERESTING!
![Page 20: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/20.jpg)
Things to keep in mind,
Image -> 2 dimensional matrix of size(mxn) Image processing -> Manipulating the values of each element of the matrix
)1,1()1,1()0,1(
)1,1()1,1()0,1(
)1,0()1,0()0,0(
),(
NMfMfMf
Nfff
Nfff
yxf
From the above representation, f is an image f(0,0) -> single pixel of an image (similarly for all values of f(x,y)
f(0,0) = 0-255 for grayscale 0/1 for binary 0-255 for each of R,G and B
SIMPLE ISN`T IT!
![Page 21: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/21.jpg)
Extracting objects of specific colors from an imageFrom the image given below, how specific color(say blue) can be extracted?
![Page 22: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/22.jpg)
Algorithm:
Load an RGB image
Get the size(mxn) of the image
Create a new matrix of zeros of size mxn
Read the values of R,G,B in each pixel while traversing through every pixels of the image
Restore pixels with required color to 1 and rest to 0 to the newly created matrix
Display the newly created matrix and the resultant image would be the filtered image of specific color
![Page 23: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/23.jpg)
Solution!Input image:
Output image(Extracted blue objects):
Snippet:
c=imread('F:\matlab sample images\1.png');[m,n,t]=size(c); tmp=zeros(m,n);for i=1:m for j=1:n if(c(i,j,1)==0 && c(i,j,2)==0 && c(i,j,3)==255) tmp(i,j)=1; end endendimshow(tmp);
![Page 24: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/24.jpg)
Count Number of objects in red colorFrom the image, count number of red objects,
![Page 25: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/25.jpg)
Algorithm:
Load the image
Get the size of the image
Find appropriate threshold level for red color
Traverse through every pixel,
Replace pixels with red threshold to 1 and remaining pixels to 0
Find the objects with enclosed boundaries in the new image
Count the boundaries to know number of objects
![Page 26: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/26.jpg)
Solution!Input image:
Output image(Extracted red objects):
Snippet:c=imread('F:\matlab sample images\1.png');[m,n,t]=size(c);tmp=zeros(m,n);for i=1:m for j=1:n if(c(i,j,1)==255 && c(i,j,2)==0 && c(i,j,3)==0) tmp(i,j)=1; end endendimshow(tmp);ss=bwboundaries(tmp);num=length(ss);Output: num = 3
![Page 27: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/27.jpg)
How to count all objects irrespective of color?
Thresholding is used to segment an image by setting all pixels whose intensity values are above a threshold to a foreground value and all the remaining pixels to a background value.
The pixels are partitioned depending on their intensity value
Global Thresholding,g(x,y) = 0, if f(x,y)<=Tg(x,y) = 1, if f(x,y)>T
THRESHOLDING!
g(x,y) = a, if f(x,y)>T2g(x,y) = b, if T1<f(x,y)<=T2 g(x,y) = c, if f(x,y)<=T1
Multiple thresholding,
![Page 28: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/28.jpg)
From the given image, Find the total number of objects present?
![Page 29: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/29.jpg)
Algorithm:
Load the image
Convert the image into grayscale(incase of an RGB image)
Fix a certain threshold level to be applied to the image
Convert the image into binary by applying the threshold level
Count the boundaries to count the number of objects
![Page 30: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/30.jpg)
Solution!
At 0.25 threshold At 0.5 threshold
At 0.6 thresholdAt 0.75 threshold
![Page 31: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/31.jpg)
Snippet:
img=imread('F:\matlab sample images\color.png');img1=rgb2gray(img);Thresholdvalue=0.75;img2=im2bw(img1,Thresholdvalue);figure,imshow(img2); % to detect num of objectsB=bwboundaries(img2);num=length(B);
![Page 32: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/32.jpg)
Drawing bounding box over objects
![Page 33: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/33.jpg)
Snippet:
img=imread('F:\matlab sample images\color.png');img1=rgb2gray(img);Thresholdvalue=0.75;img2=im2bw(img1,Thresholdvalue);figure,imshow(img2); % to detect num of objectsB=bwboundaries(img2);num=length(B);
% to draw bow over objectsfigure,imshow(img2);hold on;for k=1:length(B), boundary = B{k}; plot(boundary(:,2), boundary(:,1), 'r','LineWidth',2);end
![Page 34: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/34.jpg)
Image segmentation
Given an image of English alphabets, segment each and every alphabets
Perform basic morphological operations on the letters
Detect edges
Filter the noises if any
Replace the pixel with maximum value found in the defined pixel set (dilate)
Fill the holes in the images
Label every blob in the image
Draw the bounding box over each detected blob
![Page 35: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/35.jpg)
output
![Page 36: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/36.jpg)
Snippet:
a=imread('F:\matlab sample images\MYWORDS.png');im=rgb2gray(a);c=edge(im);se = strel('square',8); I= imdilate(c, se); img=imfill(I,'holes');figure,imshow(img); [Ilabel num] = bwlabel(img);disp(num);Iprops = regionprops(Ilabel);Ibox = [Iprops.BoundingBox]; Ibox = reshape(Ibox,[4 num]);imshow(I) hold on;for cnt = 1:num rectangle('position',Ibox(:,cnt),'edgecolor','r');end
![Page 37: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/37.jpg)
Finding length of an object in an image
Algorithm:
Calibration:
Draw a line over the object of known length
Find the number of pixels contributing to the line
No of pixels in line =
Divide the known length in real world value by measured distance in pixel.
Distance per pixel= (Distance in real world unit)/ (no of pixels in line)
This gives value of single pixel to the value of real world unit
![Page 38: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/38.jpg)
![Page 39: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/39.jpg)
Algorithm:
Measurement:
Draw a line over the object of unknown length
Find the number of pixels contributing to the line
No of pixels in line =
Distance in real world units= (Distance per pixel)* (no of pixels in line)
![Page 40: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/40.jpg)
Looking for code?
1. Write a program that solves the given equations calibration and measurement
Hint: for manual calculation, to get values of x1,x2,y1 and y2 use imtool in matlab
![Page 41: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/41.jpg)
Simple image matching using edges
Algorithm:
Load two images to be matched
Detect edges of both images
Traverse through each pixel and count number of black and white points in one image (total value)
Compare value of each pixels of both the images (matched value)
Find the match percentage,
Match percentage= ((matched value)/total value)*100)
if match percentage exceeds certain threshold(say 90%), display, ‘image matches’
![Page 42: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/42.jpg)
Input Image:
Output Image after edge detection:
Note: This method works for identical images and can be used for finger print and IRIS matching
![Page 43: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/43.jpg)
Detecting washers/nuts in an image
From the given image, find the nuts and washers based on its features
![Page 44: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/44.jpg)
Algorithm:
Analyze the image
Look for detectable features of nuts/washers
Preprocess the image to enhance the detectable feature
Hint - Use morphological operations
Create a detector to detect the feature
Mark the detected results
![Page 45: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/45.jpg)
Detected washers
![Page 46: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/46.jpg)
Mathematical operation on two functions f and g, producing a third function that is a modified version of one of the original functions
Example:
• Feature detection
Creating a convolution kernel for detecting edges:
• Analyze the logic to detect edges
• Choose a kernel with appropriate values to detect the lines
• Create a sliding window for the convolution kernel
• Slide the window through every pixel of the image
Convolution
![Page 47: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/47.jpg)
Input image Output imageAfter convolution
![Page 48: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/48.jpg)
FILTERING VERTICAL AND HORIZONTAL COMPONENTS
![Page 49: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/49.jpg)
Algorithm:
• Load an image
• Create a kernel to detect horizontal edges• Eg:
• Find the transpose of the kernel to obtain the vertical edges
• Apply the kernels to the image to filter the horizontal and vertical components
![Page 50: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/50.jpg)
Resultant image after applying horizontal filter kernel
![Page 51: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/51.jpg)
Resultant image after applying vertical filter kernel
![Page 52: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/52.jpg)
Snippet:
Using convolution:
rgb = imread('F:\matlab sample images\2.png');I = rgb2gray(rgb);imshow(I)hy = fspecial('sobel');hx = hy';hrFilt=conv2(I,hy);vrFilt=conv2(I,hx);
Using Fiters:
rgb = imread('F:\matlab sample images\2.png');I = rgb2gray(rgb);hy = fspecial('sobel');hx = hy';Iy = imfilter(double(I), hy, 'replicate');Ix = imfilter(double(I), hx, 'replicate');
![Page 53: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/53.jpg)
Image preprocessing to detect/enhance features
Often includes,
Image color conversion
Histogram equalization
Edge detection
Morphological operations
Erode
Dilate
Open
Close
![Page 54: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/54.jpg)
Example
To detect the required feature in an image,
• First subtract the unwanted features
• Enhance the required feature
• Create a detector to detect the feature
![Page 55: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/55.jpg)
Gray scale
Histogram equalization
![Page 56: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/56.jpg)
Edge detection:
![Page 57: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/57.jpg)
Morphological close:
![Page 58: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/58.jpg)
Image dilation:
![Page 59: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/59.jpg)
OUTPUT
Detect the feature in the preprocessed image
![Page 60: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/60.jpg)
IMAGE FUSION AND REGISTRATION
• Fusion: putting information together coming from different sources/data
• Registration: computing the geometrical transformation between two data
Applications:
• Medical Imaging
• Remote sensing
• Augmented Reality etc
![Page 61: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/61.jpg)
Courtesy: G. Malandain, PhD, Senior Scientist, INRA
![Page 62: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/62.jpg)
Courtesy: G. Malandain, PhD, Senior Scientist, INRA
![Page 63: Introduction to Image Processing with MATLAB](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6f1954a79590d5e8b45a1/html5/thumbnails/63.jpg)
BRAIN IMAGE REGISTERING
PET scan of Brain MRI scan of Brain
+ =
Output of multimodal registration( Different scanners)