SlideShare une entreprise Scribd logo
1  sur  27
Télécharger pour lire hors ligne
April 21, 2010




   Varun K. Nagaraja
Final Year, Dept of ECE
    NITK Surathkal
Basics of Image Processing using MATLAB




Computer Vision and Related Fields
Basics of Image Processing using MATLAB
Basics of Image Processing using MATLAB



                  Activity Recognition




Image Stitching
Basics of Image Processing using MATLAB



    Medical Image Enhancement




            Image Morphing
Basics of Image Processing using MATLAB




                           Basic operation with Matrices

% Use colon at the end to suppress               % Transpose of a matrix
% output                                         A_trans = A’

% To enter a matrix with real elements           A_trans =
A = [5 3 7; 8 9 2; 1 4.2 6e-2]
                                                        5.0000        8.0000    1.0000
A =                                                     3.0000        9.0000    4.2000
                                                        7.0000        2.0000    0.0600
      5.0000   3.0000     7.0000
      8.0000   9.0000     2.0000                 % Matrix addition
      1.0000   4.2000     0.0600                 C = A + A_trans

% To enter a matrix with complex                 C =
% elements
X = [5+3*j 7+8j; 9+2j 1+4j;]                          10.0000         11.0000   8.0000
                                                      11.0000         18.0000   6.2000
X =                                                    8.0000          6.2000   0.1200

   5.0000 + 3.0000i     7.0000 + 8.0000i
   9.0000 + 2.0000i     1.0000 + 4.0000i
Basics of Image Processing using MATLAB




                           Basic operation with Matrices

% Matrix multiplication (element wise)
C = A .* A_trans

C =

   25.0000   24.0000      7.0000
                                                 These commands or functions can be run in the
   24.0000   81.0000      8.4000
                                                 MATLAB command prompt or as Script files (.m)
    7.0000    8.4000      0.0036
                                                 Either
% Matrix multiplication                          • type edit <filename>.m in MATLAB command
C = A * A_trans
                                                   prompt to open the editor or
                                                 • go File - New - Blank M File
C =

   83.0000    81.0000   18.0200
   81.0000   149.0000   45.9200
   18.0200    45.9200   18.6436
Basics of Image Processing using MATLAB




A Simple Character Recognition Code




               • Detect only particular characters and
                 numbers in an image.
               • Characters are in white and of a fixed
                 size.
               • Background is black in color.
               • The image is in binary format.

               We will explore various concepts as we
               implement this.
Basics of Image Processing using MATLAB




                         Reading images in MATLAB

% Set working directory to directory
% containing this tutorial

% Reading an image
% A = IMREAD(FILENAME,FMT) or
% A = IMREAD('FILENAME.FMT')
im=imread('.char recogtestimage.bmp');

% It is better to suppress outputs when
% reading images. Try once without the
% colon at the end of command

% Displaying an image
imshow(im)

% To open a separate window for the
% figure and not overwrite in the
% existing window
figure
imshow(im)

figure, imshow(im)
Basics of Image Processing using MATLAB




                               Reading images in MATLAB

Now read the image ‘same color.jpg’ and display it on a window.

Once the image is displayed in the window, select Tools – Data Cursor or select the shortcut      on the
toolbar.

Click on point A as shown, on the image. It displays three values (RGB) since it is a color image. You
can try reading pixel values for the previous image. It will be either 0/1 since it is binary image.

Hold Alt and Click on point B. This creates something called as a new datatip.

Now for some fun

                                                                                  B


                                                                                 A
Basics of Image Processing using MATLAB




                                   Reading images in MATLAB

Now read the image ‘same color.jpg’ and display it on a window.

Once the image is displayed in the window, select Tools – Data Cursor or select the shortcut      on the
toolbar.

Click on point A as shown, on the image. It displays three values (RGB) since it is a color image. You
can try reading pixel values for the previous image. It will be either 0/1 since it is binary image.

Hold Alt and Click on point B. This creates something called as a new datatip.

Now for some fun

What are the RGB values at the two points?                                              B


                                                                                        A




 Adelson's checker shadow illusion (http://en.wikipedia.org/wiki/Same_color_illusion)
Basics of Image Processing using MATLAB




                     Writing functions in MATLAB

Let’s write a function charrec(im)which when called with an image file, will
display the characters as shown earlier

>> im=imread('.char recogtestimage.bmp');
>> imshow(im);
>> charrec(im);

The digits found in the image are:
0
3
5
The letters found in the image are:
L
N
Basics of Image Processing using MATLAB




       Writing functions in MATLAB

      Few examples of functions in MATLAB

% Function returning no output
function sample(ip1,ip2,ip3,…)
.
.
.
end

% Function with outputs
function [op1,op2,…]=sample(ip1,ip2,ip3,…)
.
.
.
End

% save the code as sample.m. Function name
% and m-file name should be the same
Basics of Image Processing using MATLAB




                                  The Algorithm

Dilation

• adds pixels to the boundaries of objects in an image.
• number of pixels added from the objects in an image
  depends on the size and shape of the structuring element
• function strel(…) can be used to generate the SEs.

>> SE = strel('diamond', 1)

SE =

Flat STREL object containing 5 neighbors.

Neighborhood:
     0     1          0
     1     1          1
     0     1          0
Basics of Image Processing using MATLAB




>> SE = strel('square',3)

SE =

Flat STREL object containing 9 neighbors.

Neighborhood:
     1     1     1
     1     1     1
     1     1     1
                                                               Check out help on strel for
>> SE = strel('line', 7, 45)                                   various combinations

SE =

Flat STREL object containing 5 neighbors.

Neighborhood:
     0     0     0      0        1
     0     0     0      1        0
     0     0     1      0        0
     0     1     0      0        0
     1     0     0      0        0
Basics of Image Processing using MATLAB




Dilation does not necessarily mean dilation of the holes also. The holes get
contracted as shown above.

Also try image erosion. Use MATLAB’s help.
Basics of Image Processing using MATLAB




                    Continuing with The Algorithm




When the dilated image of the character us subtracted from the original we get
something like…


                      Next we create such images for all the characters that we
                      want to recognize. (For all those individual character
                      images in the folder)

                       >>   N = imread ('.char recogN.bmp');
                       >>   SE = strel('square',3);
                       >>   N1 = imdilate(N,SE);
                       >>   N2 = N1 - N;
                       >>   figure,imshow(N2)
Basics of Image Processing using MATLAB




                    Continuing with The Algorithm

Function, bwhitmiss is employed to check if a particular character is present in
the given image.

bwhitmiss(BW1,SE1,SE2) performs the hit‐miss operation defined by the
structuring elements SE1 and SE2. The hit‐miss operation preserves pixels
whose neighborhoods match the shape of SE1 and don't match the shape of SE2.

If the matrix returned by bwhitmiss contains non zero elements, then the
character is found in the image.


          >> if ~isempty(nonzeros(bwhitmiss(im,N,N2)))
          disp('N');
          end



Also note the use of functions isempty and nonzeros

You can now use charrec.m to recognize few characters in a crude way.
Basics of Image Processing using MATLAB




                                 Image Segmentation

Global Thresholding Method


>> im=imread('automata.jpg');
>> im_gray=rgb2gray(im);

% im2bw converts grayscale image to binary
% image using a global threshold
>> bw1=im2bw(im_gray);
>> bw2=im2bw(im_gray, threshold);

%   if no threshold is specified, it uses a
%   function graythresh to calculate the
%   threshold. Otsu’s method is implemented in
%   graythresh function.
Basics of Image Processing using MATLAB




                                   Image Segmentation

Global Thresholding Method

Disadvantage is when there are multiple colors for objects and backgrounds.




                    Result with global thresholding – one of the blocks is lost
Basics of Image Processing using MATLAB




                                     Image Segmentation

    Local Thresholding Method: Niblack’s Method


                                                     >>   im=imread('blocks.jpg');
            255 if I( x, y )  T ( x, y )         >>   im_gray=rgb2gray(im);
                                          
R( x, y )  100 if I( x, y )  T ( x, y )         >>   imt=niblack(im_gray,0.5,201);
                                                     >>   figure,imshow(imt,[])
             0                            
                       otherwise          
                                                     % Here k=0.5 and N=201(preferably odd)
        T ( x, y)   N  k   N
                                                     % think about effects of values of N on
                                                     % processing time and k on thresholding
                                                     % level
 k and N are to be empirically determined
Basics of Image Processing using MATLAB




                                Image Segmentation

  Local Thresholding Method: Niblack’s Method

% Since our objects of interest are white pixels,
% we will consider those equal to 255
>> imwhite=(imt==255);

% observe how the above command works. It checks
% pixel by pixel for the condition and returns a
% matrix
>> figure, imshow(imwhite)

% Now we need to clear the noisier regions. We
% use an erosion process followed by reconstruction
>> im_eroded=imerode(imwhite,strel('square',51));
>> im_recon=imreconstruct(im_eroded,imwhite);
>> figure, imshow(im_recon)
Basics of Image Processing using MATLAB




                             Connected Components



%   You can see pixels connected to each other
%   form objects in the image. These are
%   called connected components. Read more
%   about 4-connectivity and 8-connectivity

% Label the connected components i.e. assign
% a particular number as pixel value to one CC
>> [bw_labelled num]=bwlabel(im_recon);
>> figure,imshow(bw_labelled,[])

% We can use regionprops() to extract some
% properties of the CCs
>> areas = regionprops(bw_labelled,'Area')

% Here areas is a struct variable

% Try experimenting with other properties and
% explore what property can be used to
% distinguish between CCs
Basics of Image Processing using MATLAB




% We will convert to struct to a normal array for easy operation
>> areas1=[];
>> for i=1:length(areas)
areas1=[areas1; areas(i,1).Area];
end
>> areas1

areas1 =

      415711
       26440
       10350
        8630
       17971
        8282
        5243

% We are interested in objects (the squares) with area in range 8000-
% 9000

>> index=find(areas1>8000 & areas1<9000);
>> finalimg=zeros(size(bw_labelled));
>> for i=1:length(index)
finalimg=finalimg+(bw_labelled==index(i));
end
Basics of Image Processing using MATLAB




>> figure,imshow(finalimg,[])




This was again a very crude way, since we are depending only on value of
area which might not remain constant if camera changes position.

Most of the times the standard features available with regionprops() is
not sufficient. We will have to write our own code to extract features.

Also we used hard thresholds for areas to classify CCs. Again most of the
times, this is not followed. Classifiers using Pattern Recognition techniques
are employed.
Basics of Image Processing using MATLAB




                           Few Other Stuff

You can try
Edge detection
>>   im=imread('ouch.jpg');
>>   im_gray=rgb2gray(im);
>>   imedge=edge(im_gray,'canny',[0.1 0.2]);
>>   figure,imshow(imedge)

% Try different edge operators and
% threshold levels


and
Removing Noise By Median Filtering
(MATLAB Help)




         There is more to learn in Image Processing. All the Best
Basics of Image Processing using MATLAB

Contenu connexe

Tendances

Image Enhancement in Spatial Domain
Image Enhancement in Spatial DomainImage Enhancement in Spatial Domain
Image Enhancement in Spatial DomainA B Shinde
 
Image proceesing with matlab
Image proceesing with matlabImage proceesing with matlab
Image proceesing with matlabAshutosh Shahi
 
Image compression in digital image processing
Image compression in digital image processingImage compression in digital image processing
Image compression in digital image processingDHIVYADEVAKI
 
Image processing spatialfiltering
Image processing spatialfilteringImage processing spatialfiltering
Image processing spatialfilteringJohn Williams
 
Digital image processing using matlab
Digital image processing using matlab Digital image processing using matlab
Digital image processing using matlab Amr Rashed
 
Chapter 3 image enhancement (spatial domain)
Chapter 3 image enhancement (spatial domain)Chapter 3 image enhancement (spatial domain)
Chapter 3 image enhancement (spatial domain)asodariyabhavesh
 
Matlab and Image Processing Workshop-SKERG
Matlab and Image Processing Workshop-SKERG Matlab and Image Processing Workshop-SKERG
Matlab and Image Processing Workshop-SKERG Sulaf Almagooshi
 
Morphological Image Processing
Morphological Image ProcessingMorphological Image Processing
Morphological Image Processingkumari36
 
Chapter 8 image compression
Chapter 8 image compressionChapter 8 image compression
Chapter 8 image compressionasodariyabhavesh
 
Fundamentals and image compression models
Fundamentals and image compression modelsFundamentals and image compression models
Fundamentals and image compression modelslavanya marichamy
 
Comparative study on image segmentation techniques
Comparative study on image segmentation techniquesComparative study on image segmentation techniques
Comparative study on image segmentation techniquesgmidhubala
 
03 digital image fundamentals DIP
03 digital image fundamentals DIP03 digital image fundamentals DIP
03 digital image fundamentals DIPbabak danyal
 
Comparison of image segmentation
Comparison of image segmentationComparison of image segmentation
Comparison of image segmentationHaitham Ahmed
 
Lect 03 - first portion
Lect 03 - first portionLect 03 - first portion
Lect 03 - first portionMoe Moe Myint
 
DIGITAL IMAGE PROCESSING - LECTURE NOTES
DIGITAL IMAGE PROCESSING - LECTURE NOTESDIGITAL IMAGE PROCESSING - LECTURE NOTES
DIGITAL IMAGE PROCESSING - LECTURE NOTESEzhilya venkat
 

Tendances (20)

Image Enhancement in Spatial Domain
Image Enhancement in Spatial DomainImage Enhancement in Spatial Domain
Image Enhancement in Spatial Domain
 
Image proceesing with matlab
Image proceesing with matlabImage proceesing with matlab
Image proceesing with matlab
 
Image compression in digital image processing
Image compression in digital image processingImage compression in digital image processing
Image compression in digital image processing
 
Image processing spatialfiltering
Image processing spatialfilteringImage processing spatialfiltering
Image processing spatialfiltering
 
Digital image processing using matlab
Digital image processing using matlab Digital image processing using matlab
Digital image processing using matlab
 
Chapter 3 image enhancement (spatial domain)
Chapter 3 image enhancement (spatial domain)Chapter 3 image enhancement (spatial domain)
Chapter 3 image enhancement (spatial domain)
 
Matlab and Image Processing Workshop-SKERG
Matlab and Image Processing Workshop-SKERG Matlab and Image Processing Workshop-SKERG
Matlab and Image Processing Workshop-SKERG
 
Morphological Image Processing
Morphological Image ProcessingMorphological Image Processing
Morphological Image Processing
 
Data Redundacy
Data RedundacyData Redundacy
Data Redundacy
 
Hit and-miss transform
Hit and-miss transformHit and-miss transform
Hit and-miss transform
 
Image Compression
Image CompressionImage Compression
Image Compression
 
Image compression
Image compression Image compression
Image compression
 
Chapter 8 image compression
Chapter 8 image compressionChapter 8 image compression
Chapter 8 image compression
 
Fundamentals and image compression models
Fundamentals and image compression modelsFundamentals and image compression models
Fundamentals and image compression models
 
Comparative study on image segmentation techniques
Comparative study on image segmentation techniquesComparative study on image segmentation techniques
Comparative study on image segmentation techniques
 
Image compression Algorithms
Image compression AlgorithmsImage compression Algorithms
Image compression Algorithms
 
03 digital image fundamentals DIP
03 digital image fundamentals DIP03 digital image fundamentals DIP
03 digital image fundamentals DIP
 
Comparison of image segmentation
Comparison of image segmentationComparison of image segmentation
Comparison of image segmentation
 
Lect 03 - first portion
Lect 03 - first portionLect 03 - first portion
Lect 03 - first portion
 
DIGITAL IMAGE PROCESSING - LECTURE NOTES
DIGITAL IMAGE PROCESSING - LECTURE NOTESDIGITAL IMAGE PROCESSING - LECTURE NOTES
DIGITAL IMAGE PROCESSING - LECTURE NOTES
 

En vedette

Information visualization: information dashboards
Information visualization: information dashboardsInformation visualization: information dashboards
Information visualization: information dashboardsKatrien Verbert
 
TESTIMAGES - a large-scale archive for testing visual devices and basic image...
TESTIMAGES - a large-scale archive for testing visual devices and basic image...TESTIMAGES - a large-scale archive for testing visual devices and basic image...
TESTIMAGES - a large-scale archive for testing visual devices and basic image...Tecnick.com LTD
 
Introduction of image processing
Introduction of image processingIntroduction of image processing
Introduction of image processingAvani Shah
 
基礎影像處理
基礎影像處理基礎影像處理
基礎影像處理weihan cheng
 
Digital image processing using matlab (fundamentals)
Digital image processing using matlab (fundamentals)Digital image processing using matlab (fundamentals)
Digital image processing using matlab (fundamentals)Taimur Adil
 
Basic image processing
Basic image processingBasic image processing
Basic image processingJay Thakkar
 
Image Processing Basics
Image Processing BasicsImage Processing Basics
Image Processing BasicsNam Le
 
Introduction to Digital Image Processing Using MATLAB
Introduction to Digital Image Processing Using MATLABIntroduction to Digital Image Processing Using MATLAB
Introduction to Digital Image Processing Using MATLABRay Phan
 
Automatic speech recognition
Automatic speech recognitionAutomatic speech recognition
Automatic speech recognitionRichie
 
Face recognition using neural network
Face recognition using neural networkFace recognition using neural network
Face recognition using neural networkIndira Nayak
 
Speech recognition
Speech recognitionSpeech recognition
Speech recognitionCharu Joshi
 
Voice Recognition
Voice RecognitionVoice Recognition
Voice RecognitionAmrita More
 
Digital Image Processing
Digital Image ProcessingDigital Image Processing
Digital Image ProcessingSahil Biswas
 

En vedette (14)

Information visualization: information dashboards
Information visualization: information dashboardsInformation visualization: information dashboards
Information visualization: information dashboards
 
TESTIMAGES - a large-scale archive for testing visual devices and basic image...
TESTIMAGES - a large-scale archive for testing visual devices and basic image...TESTIMAGES - a large-scale archive for testing visual devices and basic image...
TESTIMAGES - a large-scale archive for testing visual devices and basic image...
 
Introduction of image processing
Introduction of image processingIntroduction of image processing
Introduction of image processing
 
基礎影像處理
基礎影像處理基礎影像處理
基礎影像處理
 
Digital image processing using matlab (fundamentals)
Digital image processing using matlab (fundamentals)Digital image processing using matlab (fundamentals)
Digital image processing using matlab (fundamentals)
 
Basic image processing
Basic image processingBasic image processing
Basic image processing
 
Image Processing Basics
Image Processing BasicsImage Processing Basics
Image Processing Basics
 
Introduction to Digital Image Processing Using MATLAB
Introduction to Digital Image Processing Using MATLABIntroduction to Digital Image Processing Using MATLAB
Introduction to Digital Image Processing Using MATLAB
 
Automatic speech recognition
Automatic speech recognitionAutomatic speech recognition
Automatic speech recognition
 
Face recognition using neural network
Face recognition using neural networkFace recognition using neural network
Face recognition using neural network
 
Image processing ppt
Image processing pptImage processing ppt
Image processing ppt
 
Speech recognition
Speech recognitionSpeech recognition
Speech recognition
 
Voice Recognition
Voice RecognitionVoice Recognition
Voice Recognition
 
Digital Image Processing
Digital Image ProcessingDigital Image Processing
Digital Image Processing
 

Similaire à Basics of Image Processing using MATLAB

BMVA summer school MATLAB programming tutorial
BMVA summer school MATLAB programming tutorialBMVA summer school MATLAB programming tutorial
BMVA summer school MATLAB programming tutorialpotaters
 
Programming in matlab lesson5
Programming in matlab lesson5Programming in matlab lesson5
Programming in matlab lesson5najmah17
 
Image processing using matlab
Image processing using matlabImage processing using matlab
Image processing using matlabdedik dafiyanto
 
ImageProcessingWithMatlab(HasithaEdiriweera)
ImageProcessingWithMatlab(HasithaEdiriweera)ImageProcessingWithMatlab(HasithaEdiriweera)
ImageProcessingWithMatlab(HasithaEdiriweera)Hasitha Ediriweera
 
Image processing using matlab
Image processing using matlab Image processing using matlab
Image processing using matlab SangeethaSasi1
 
Image processing with matlab
Image processing with matlabImage processing with matlab
Image processing with matlabminhtaispkt
 
Image processing with matlab
Image processing with matlabImage processing with matlab
Image processing with matlabAman Gupta
 
Image processing with matlab
Image processing with matlabImage processing with matlab
Image processing with matlabneetirajsinh
 
Image Processing using Matlab . Useful for beginners to learn Image Processing
Image Processing using Matlab . Useful for beginners to learn Image ProcessingImage Processing using Matlab . Useful for beginners to learn Image Processing
Image Processing using Matlab . Useful for beginners to learn Image ProcessingAshok Kumar
 
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptxMATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptxprashantkumarchinama
 
Intro matlab and convolution islam
Intro matlab and convolution islamIntro matlab and convolution islam
Intro matlab and convolution islamIslam Alabbasy
 
Image_Processing_LECTURE_c#_programming.ppt
Image_Processing_LECTURE_c#_programming.pptImage_Processing_LECTURE_c#_programming.ppt
Image_Processing_LECTURE_c#_programming.pptLOUISSEVERINOROMANO
 

Similaire à Basics of Image Processing using MATLAB (20)

MATLAB.pptx
MATLAB.pptxMATLAB.pptx
MATLAB.pptx
 
BMVA summer school MATLAB programming tutorial
BMVA summer school MATLAB programming tutorialBMVA summer school MATLAB programming tutorial
BMVA summer school MATLAB programming tutorial
 
Programming in matlab lesson5
Programming in matlab lesson5Programming in matlab lesson5
Programming in matlab lesson5
 
Image processing using matlab
Image processing using matlabImage processing using matlab
Image processing using matlab
 
Matlab dip
Matlab dipMatlab dip
Matlab dip
 
ImageProcessingWithMatlab(HasithaEdiriweera)
ImageProcessingWithMatlab(HasithaEdiriweera)ImageProcessingWithMatlab(HasithaEdiriweera)
ImageProcessingWithMatlab(HasithaEdiriweera)
 
Image processing using matlab
Image processing using matlab Image processing using matlab
Image processing using matlab
 
Intro matlab
Intro matlabIntro matlab
Intro matlab
 
Image processing with matlab
Image processing with matlabImage processing with matlab
Image processing with matlab
 
Image processing with matlab
Image processing with matlabImage processing with matlab
Image processing with matlab
 
Image processing with matlab
Image processing with matlabImage processing with matlab
Image processing with matlab
 
Image Processing using Matlab . Useful for beginners to learn Image Processing
Image Processing using Matlab . Useful for beginners to learn Image ProcessingImage Processing using Matlab . Useful for beginners to learn Image Processing
Image Processing using Matlab . Useful for beginners to learn Image Processing
 
Matlab Practical-- 12.pdf
Matlab Practical-- 12.pdfMatlab Practical-- 12.pdf
Matlab Practical-- 12.pdf
 
Image processing
Image processingImage processing
Image processing
 
Dip day1&2
Dip day1&2Dip day1&2
Dip day1&2
 
Matlab anilkumar
Matlab  anilkumarMatlab  anilkumar
Matlab anilkumar
 
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptxMATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
 
Intro matlab and convolution islam
Intro matlab and convolution islamIntro matlab and convolution islam
Intro matlab and convolution islam
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
Image_Processing_LECTURE_c#_programming.ppt
Image_Processing_LECTURE_c#_programming.pptImage_Processing_LECTURE_c#_programming.ppt
Image_Processing_LECTURE_c#_programming.ppt
 

Dernier

Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 

Dernier (20)

E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 

Basics of Image Processing using MATLAB

  • 1. April 21, 2010 Varun K. Nagaraja Final Year, Dept of ECE NITK Surathkal
  • 2. Basics of Image Processing using MATLAB Computer Vision and Related Fields
  • 3. Basics of Image Processing using MATLAB
  • 4. Basics of Image Processing using MATLAB Activity Recognition Image Stitching
  • 5. Basics of Image Processing using MATLAB Medical Image Enhancement Image Morphing
  • 6. Basics of Image Processing using MATLAB Basic operation with Matrices % Use colon at the end to suppress % Transpose of a matrix % output A_trans = A’ % To enter a matrix with real elements A_trans = A = [5 3 7; 8 9 2; 1 4.2 6e-2] 5.0000 8.0000 1.0000 A = 3.0000 9.0000 4.2000 7.0000 2.0000 0.0600 5.0000 3.0000 7.0000 8.0000 9.0000 2.0000 % Matrix addition 1.0000 4.2000 0.0600 C = A + A_trans % To enter a matrix with complex C = % elements X = [5+3*j 7+8j; 9+2j 1+4j;] 10.0000 11.0000 8.0000 11.0000 18.0000 6.2000 X = 8.0000 6.2000 0.1200 5.0000 + 3.0000i 7.0000 + 8.0000i 9.0000 + 2.0000i 1.0000 + 4.0000i
  • 7. Basics of Image Processing using MATLAB Basic operation with Matrices % Matrix multiplication (element wise) C = A .* A_trans C = 25.0000 24.0000 7.0000 These commands or functions can be run in the 24.0000 81.0000 8.4000 MATLAB command prompt or as Script files (.m) 7.0000 8.4000 0.0036 Either % Matrix multiplication • type edit <filename>.m in MATLAB command C = A * A_trans prompt to open the editor or • go File - New - Blank M File C = 83.0000 81.0000 18.0200 81.0000 149.0000 45.9200 18.0200 45.9200 18.6436
  • 8. Basics of Image Processing using MATLAB A Simple Character Recognition Code • Detect only particular characters and numbers in an image. • Characters are in white and of a fixed size. • Background is black in color. • The image is in binary format. We will explore various concepts as we implement this.
  • 9. Basics of Image Processing using MATLAB Reading images in MATLAB % Set working directory to directory % containing this tutorial % Reading an image % A = IMREAD(FILENAME,FMT) or % A = IMREAD('FILENAME.FMT') im=imread('.char recogtestimage.bmp'); % It is better to suppress outputs when % reading images. Try once without the % colon at the end of command % Displaying an image imshow(im) % To open a separate window for the % figure and not overwrite in the % existing window figure imshow(im) figure, imshow(im)
  • 10. Basics of Image Processing using MATLAB Reading images in MATLAB Now read the image ‘same color.jpg’ and display it on a window. Once the image is displayed in the window, select Tools – Data Cursor or select the shortcut on the toolbar. Click on point A as shown, on the image. It displays three values (RGB) since it is a color image. You can try reading pixel values for the previous image. It will be either 0/1 since it is binary image. Hold Alt and Click on point B. This creates something called as a new datatip. Now for some fun B A
  • 11. Basics of Image Processing using MATLAB Reading images in MATLAB Now read the image ‘same color.jpg’ and display it on a window. Once the image is displayed in the window, select Tools – Data Cursor or select the shortcut on the toolbar. Click on point A as shown, on the image. It displays three values (RGB) since it is a color image. You can try reading pixel values for the previous image. It will be either 0/1 since it is binary image. Hold Alt and Click on point B. This creates something called as a new datatip. Now for some fun What are the RGB values at the two points? B A Adelson's checker shadow illusion (http://en.wikipedia.org/wiki/Same_color_illusion)
  • 12. Basics of Image Processing using MATLAB Writing functions in MATLAB Let’s write a function charrec(im)which when called with an image file, will display the characters as shown earlier >> im=imread('.char recogtestimage.bmp'); >> imshow(im); >> charrec(im); The digits found in the image are: 0 3 5 The letters found in the image are: L N
  • 13. Basics of Image Processing using MATLAB Writing functions in MATLAB Few examples of functions in MATLAB % Function returning no output function sample(ip1,ip2,ip3,…) . . . end % Function with outputs function [op1,op2,…]=sample(ip1,ip2,ip3,…) . . . End % save the code as sample.m. Function name % and m-file name should be the same
  • 14. Basics of Image Processing using MATLAB The Algorithm Dilation • adds pixels to the boundaries of objects in an image. • number of pixels added from the objects in an image depends on the size and shape of the structuring element • function strel(…) can be used to generate the SEs. >> SE = strel('diamond', 1) SE = Flat STREL object containing 5 neighbors. Neighborhood: 0 1 0 1 1 1 0 1 0
  • 15. Basics of Image Processing using MATLAB >> SE = strel('square',3) SE = Flat STREL object containing 9 neighbors. Neighborhood: 1 1 1 1 1 1 1 1 1 Check out help on strel for >> SE = strel('line', 7, 45) various combinations SE = Flat STREL object containing 5 neighbors. Neighborhood: 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0
  • 16. Basics of Image Processing using MATLAB Dilation does not necessarily mean dilation of the holes also. The holes get contracted as shown above. Also try image erosion. Use MATLAB’s help.
  • 17. Basics of Image Processing using MATLAB Continuing with The Algorithm When the dilated image of the character us subtracted from the original we get something like… Next we create such images for all the characters that we want to recognize. (For all those individual character images in the folder) >> N = imread ('.char recogN.bmp'); >> SE = strel('square',3); >> N1 = imdilate(N,SE); >> N2 = N1 - N; >> figure,imshow(N2)
  • 18. Basics of Image Processing using MATLAB Continuing with The Algorithm Function, bwhitmiss is employed to check if a particular character is present in the given image. bwhitmiss(BW1,SE1,SE2) performs the hit‐miss operation defined by the structuring elements SE1 and SE2. The hit‐miss operation preserves pixels whose neighborhoods match the shape of SE1 and don't match the shape of SE2. If the matrix returned by bwhitmiss contains non zero elements, then the character is found in the image. >> if ~isempty(nonzeros(bwhitmiss(im,N,N2))) disp('N'); end Also note the use of functions isempty and nonzeros You can now use charrec.m to recognize few characters in a crude way.
  • 19. Basics of Image Processing using MATLAB Image Segmentation Global Thresholding Method >> im=imread('automata.jpg'); >> im_gray=rgb2gray(im); % im2bw converts grayscale image to binary % image using a global threshold >> bw1=im2bw(im_gray); >> bw2=im2bw(im_gray, threshold); % if no threshold is specified, it uses a % function graythresh to calculate the % threshold. Otsu’s method is implemented in % graythresh function.
  • 20. Basics of Image Processing using MATLAB Image Segmentation Global Thresholding Method Disadvantage is when there are multiple colors for objects and backgrounds. Result with global thresholding – one of the blocks is lost
  • 21. Basics of Image Processing using MATLAB Image Segmentation Local Thresholding Method: Niblack’s Method >> im=imread('blocks.jpg'); 255 if I( x, y )  T ( x, y ) >> im_gray=rgb2gray(im);   R( x, y )  100 if I( x, y )  T ( x, y ) >> imt=niblack(im_gray,0.5,201); >> figure,imshow(imt,[])  0   otherwise  % Here k=0.5 and N=201(preferably odd) T ( x, y)   N  k   N % think about effects of values of N on % processing time and k on thresholding % level k and N are to be empirically determined
  • 22. Basics of Image Processing using MATLAB Image Segmentation Local Thresholding Method: Niblack’s Method % Since our objects of interest are white pixels, % we will consider those equal to 255 >> imwhite=(imt==255); % observe how the above command works. It checks % pixel by pixel for the condition and returns a % matrix >> figure, imshow(imwhite) % Now we need to clear the noisier regions. We % use an erosion process followed by reconstruction >> im_eroded=imerode(imwhite,strel('square',51)); >> im_recon=imreconstruct(im_eroded,imwhite); >> figure, imshow(im_recon)
  • 23. Basics of Image Processing using MATLAB Connected Components % You can see pixels connected to each other % form objects in the image. These are % called connected components. Read more % about 4-connectivity and 8-connectivity % Label the connected components i.e. assign % a particular number as pixel value to one CC >> [bw_labelled num]=bwlabel(im_recon); >> figure,imshow(bw_labelled,[]) % We can use regionprops() to extract some % properties of the CCs >> areas = regionprops(bw_labelled,'Area') % Here areas is a struct variable % Try experimenting with other properties and % explore what property can be used to % distinguish between CCs
  • 24. Basics of Image Processing using MATLAB % We will convert to struct to a normal array for easy operation >> areas1=[]; >> for i=1:length(areas) areas1=[areas1; areas(i,1).Area]; end >> areas1 areas1 = 415711 26440 10350 8630 17971 8282 5243 % We are interested in objects (the squares) with area in range 8000- % 9000 >> index=find(areas1>8000 & areas1<9000); >> finalimg=zeros(size(bw_labelled)); >> for i=1:length(index) finalimg=finalimg+(bw_labelled==index(i)); end
  • 25. Basics of Image Processing using MATLAB >> figure,imshow(finalimg,[]) This was again a very crude way, since we are depending only on value of area which might not remain constant if camera changes position. Most of the times the standard features available with regionprops() is not sufficient. We will have to write our own code to extract features. Also we used hard thresholds for areas to classify CCs. Again most of the times, this is not followed. Classifiers using Pattern Recognition techniques are employed.
  • 26. Basics of Image Processing using MATLAB Few Other Stuff You can try Edge detection >> im=imread('ouch.jpg'); >> im_gray=rgb2gray(im); >> imedge=edge(im_gray,'canny',[0.1 0.2]); >> figure,imshow(imedge) % Try different edge operators and % threshold levels and Removing Noise By Median Filtering (MATLAB Help) There is more to learn in Image Processing. All the Best
  • 27. Basics of Image Processing using MATLAB