UXDE dot Net

Traffic Warning Sign Recognition Matlab Code

By -

Matlab Demo Model 

Figure Below Shows the model to implement the Warning Sign Detection and Recognition Using Matlab (Version 7.5 or Above).

Matlab Demo Model

Matlab Demo Model

Traffic Warning Sign Templates 

Templates used for Matching sign recognition are build in present in Matlab you can access these templates using this command


There are total 9 templates which are shown as follows :

  • Detection templates are low in resolution to achieve high performance detection speed from video frames and Remember size of frame and size of image extracted from frame should be same.
  • Red pixel is a distinguish characteristic to detect the red traffic sign this demo uses this technique for sign detection.
  • There’s a problem of accuracy during detection so three templates are used for each sign detection which are oriented in different directions to detect the sign.


Detection of  Traffic Sign 

  • For the detection of sign each frame is analysed.
  • First the image is Converted into gray scale image and then threshold is performed.
  • Then by using blob analysis portion  of red part is extracted.
  • Then this extracted part is compared with each template.
  • If the template is matched with extracted part then a rectangle is drawn at the location of extracted part in that frame.
  • In this way rectangle is drawn at all the frames and at the end all frames are played using implay video command.

Recognition and display the Name of Traffic Sign 

  • Now when the template is  matched with extracted blob this is done by using correlation.
  • Each template is matched with extracted blob by correlating each template and extracted part.If there’s exactly or 50% match then a check is assigned that its completely matching with the extracted blob sign.
  • Now template is recognized Now the name of recognized sign is concatenated with the red sign.
  • Image of Sign is Deigned and will be provided With the Source Code.

traffic warning sign recognition

Matlab Code

function main
readerobj = mmreader(‘stoprd.avi‘);
vidFrames = read(readerobj);

numFrames = get(readerobj, ‘numberOfFrames’); %get number of frames
implay(vidFrames)                                        %Play Input Video Files
for k = 1 : numFrames-1
mov(k).cdata = vidFrames(:,:,:,k);      %Extract Frame & save in Struc
mov(k).colormap = [];
mov(k).cdata=blobAnalysis(mov(k).cdata);%Call Blob Analysis Function
vidFrames(:,:,:,k)=mov(k).cdata;           %Save Output Data

  • In the Main Function Video as input is read in readerobj  and then frames are extracted from video input.
  • These frames are passed into blobAnalysis function one by one
  • Output image after processed by blobAnalysis function is saved in vidFrames
  • And At last when all frames are received in vidFrames output video is played using implay which is last command in above code.


 Blob Analysis Function 

function x=blobAnalysis(a)
a(:,:,1) = medfilt2(a(:,:,1), [3 3]);
a(:,:,2) = medfilt2(a(:,:,2), [3 3]);
a(:,:,3) = medfilt2(a(:,:,3), [3 3]);
[r c d]=size(a);

for i=1:r
for j=1:c





if(i1<1) i1=1; end i2=i2+2; if(i2>r)


if(j1<1) j1=1; end j2=j2+20; if(j2>c)

[r1 c1 d1]=size(stptag);

[row col]=size(z);
if(row~=0 && col~=0)
z=imresize(z, [18 18], ‘nearest’);
load vipwarningsigns_templates.mat;
for k=1:9
for i=1:9
for l1=i1:i2


for l2=j1:j2




  • Now our frames are coming in variable a and from a to x.
  • Now applying median filter on the frame on all three dimensions that’s red blue and green using MEDFILT2  for smoothing as some frames are blurry.
  • Now doing BLOB ANALYSIS to extract red region from frame by by checking intensity values for red when intensity values for dimention1>125 && dimention2 <90 && dimention3<90 then its mean we are in red region so when loop enter into this red region we note this pixel in variable (i1,j1) and in the same way when loop leave this this red part we note this pixel in variables (i1,i2).
  • Now we know entry and ending points of this region now added a little offset in entry and end red pixel to extract that red part from the frame and now our extracted traffic sign is in variable z.
  • Now reading images that’s tags to display the recognized sign that’s yieldtag and stptag.
  • Now converting the extracted red sign which was in z variable into gray ,double and Thresholding  using RGB2GRAY , IM2DOUBLE , IM2BW Command.
  • Now resizing the extracted image size to the size template for matching using IMRESIZE command.
  • Now loading template sign to match with the extracted sign which is in variable z by this command load vipwarningsigns_templates.mat;
  • Now Reading each template in temp variable and finding correlation of each template with red extracted sign from frame which is in variable z.
  • Now s variable contains all correlation result now find max of correlation  now we found template which is matching with the traffic sign.
  • Now adding a image tag with the recognized sign.
  • Now finally drawing rectangle on the frame and frame is returned


traffic sign recognition video

traffic sign recognition video

traffic sign recognition video Results

traffic sign recognition video Results

Source Code

Like , share this post on Facebook , Twitter by using left moving Social Sharing block and follow us on Facebook Page , Twitter and do comment and enter your email. After you have done you will automatically get source code in your mail. Note : This will be auto generated mail you can’t get until you follow above method.




Farheen Bibi

You can find Farheen on , and .

161 Comments to Traffic Warning Sign Recognition Matlab Code

  1. Hai Khan,

    Thanks for the help.
    I would like to know more about the solution; especially on how to recognize more specific traffic signs.


    • Yea sure let me know if you need the source code i will send it to you in your mail and to recognize other object you have to make templates of that object but here i am just using Matlab built in templates using this commannd load vipwarningsigns_templates.mat;

      • thuong nguyen van

        hi ammadkhan
        do you have an code to detect and track color in live camera? I using matlab
        or do you have any suggestion.
        thank you very much

        • In this sign recognition I detected red color if you read the whole article you will get know how to detect red color. In the same way you can detect any color of your choice If you do effort to understand the algorithm. First try this on a video clip instead of testing it on live camera.

      • hi ammad
        i wanna find out the convex hull of any object as i took a palm picture in my project there was a code that i get from internet for impcon.bmp image when same code i m trying to run for my image it is giving an error of Index exceeds matrix dimensions so please help me to find the convex hull of any binary image using the set of structuring elements …..PLEASE

          • Mehmet Gür

            Hi khan. I need to study on money recognition on matlab. Could you give me your sign recognition’s source code ? And please let me know if you know anything about money recognition on matlab :)

      • Hi khan….
        Can you send me the same source code please. I want to use this for gesture recognition which is my research in final year…

  2. dhinagaran

    u done this project in good manner

    i need to understand it briefly

    could u send this source code ?…

    thanks in advance

    • Thanks for your Appreciation first i would suggest you to open matlab
      1) click on start on left below go into Blocksets —>Video And Image Processing —->Demo
      2) After this in this category click on Traffic warning sign recognition

      Now in this Demo first understand the whole procedure and then come towards the code section to understand authentically then let me know if you have any problem
      Check your mail for Source code

  3. Thanks for the source code. There is an error like
    Error using load
    Unable to read file vipwarningsigns_templates.mat: No such file or directory.

    How can I have “vipwarningsigns_templates.mat”?

    • Use this command to load these files First check this command on console command window to know the variables
      load vipwarningsigns_templates.mat

      variables will be as follows i am copying here OUTPUT OF Above Command

      Name Size Bytes Class Attributes

      template_detection 12x12x3 1728 single
      template_detection_display 12×36 1728 single
      template_ids 1×9 36 single
      template_names 3×12 36 uint8
      template_recognition 18x18x9 11664 single
      template_recognition_display 18×162 11664 single

  4. But it can not be loaded.
    the error is :
    Error using load
    Unable to read file vipwarningsigns_templates.mat: No such file or directory.
    You mean before running the code I should use this command?

    load vipwarningsigns_templates.mat

  5. Do you code processing image for Identify traffic signs using Support Vector Machines ?
    I need document and code.can you help me?
    Thank you very much!

    • Right Now i am very busy in my Engineering exams but soon i will do some research on Support Vector Machines and make a new tutorial regarding Recognition algorithm

  6. Do you code processing image for Identify traffic signs using Gabor Filter ?
    I need document and code. can you help me?
    Thank you very much!

    • It would take time now a days i am really busy i have to prepare my self for exams you can examine this code this is developed using blob analysis .If you can understand this just alter the code insert your technique and if do you need it ? i will mail you just inform me

  7. Could you please send me your project Traffic Warning Sign Recognition Matlab Code. I want to develope it on Android base on your project.
    Thank you so much.

  8. Shakhil Dhotah

    hi Mr Khan,
    Traffic sign detection and recognition is quite difficult to implement on matlab if one is not really familiar to this programming tool. well , actually part of my thesis is on that, and i will have to use that to make use of traffic speed signs detection. Can you please send me the code please.

        • IN blob analysis we need to extract red part from the image to see the RGB intensities of image Use IMTOOL command and move your mouse cursor over red area then you will get know intensities and these intensities you will use here
          now when this condition is true this means loop reaches to red part and you will insert a check on start of red part and when this condition becomes false we note these pixels in this we get know starting and ending pixels of red traffic sign which will be in variables
          starting = (i1,j) starting means start of red pixel in image
          ending = (i2,j2) ending means end of red pixel in image

          now we add an offset and insert a rect for more understanding please read all post and try to understand the flow and if you do not understand any logic comment about specific line to understand

    • first you have to make template just like template for the stop sign by extracting frame from the video and from frame crop the part which you want to recognize in the .avi video after then use that template in the code and apply the corresponding functions which were applied for the demo traffic warning sign Recognition

  9. Hello Ammad,
    I have detected a speed limit traffic sign but to recognised it i have to use OCR. My detected image contains some noise along with traffic sign. How can i completely detect the circular sign using “regionprops” command?

    • you can do blob analysis just like i did blob analysis recognizes round red part and coorelation is used to recognize sign that is coorelate with the template and for noise smooth the image by applying averaging filter

  10. Please explain for me why you use if(mx>0.15) in BlobFunction?
    How can you find 0.15?
    Thank you so much!

  11. Hi, could you forward me your source code? I’m also experiencing some difficulties on this topic. Thanks!

      • But we interest in only speed signs. First, we find red areas in the picture or video. Then we want detecting areas which are circle. In this way, we detect the traffic speed sign. Then we will detect amount of speed with using character recognition.

        • Yes you are at right place to find the red areas you have to do analysis to find that red part so i am sending you the source code in which used the same technique of detecting red areas which are in circle you can modify this source code but i want you to keep me updating about your project and also after completing this we will be thankful if you share this with us thanks keep visiting and if you want to keep your self upto date join this page https://www.facebook.com/MatlabProgramming @crunchmodo

          • thanks a lot :) we already found red areas before your project. Is this area circle, we couldn’t. Metric value or correlation, we tried but unfortunatelly. How can we detect circle areas, what do you tkink?

  12. I am working on a traffic sign board recognition system. It should perform canny edge detection, hough transform for circle detection and LDA for comparison of the input image with the images in the database. Can you please help me?

    • You should first check this project in this project we do analysis to detect edges of red circular board using blob analysis and then comparison is made with image using Co Relation do you need this code ?

      • I have completed the edge detection portion using Canny. Now I am working on Hough transform for detecting the circular shapes in the edge detected image. I know that your code will work. But I want to try some new combination of algorithm for the same problem. I want to use LDA instead of Co-relation. Is that possible? I am actually confused in case of LDA, how to give input, what will be the output etc. Can you help me on this?

  13. Elrick Terry

    I’m starting to research about traffic recognition.
    I’m very interested on your project to have an idea on how to start to study this.
    In the next two months I want to detect signales only on static images and tag the signal
    Thank you in advance!

  14. hi
    i am a computer and communication engineering student, i working on a project similar to yours i am trying to recognize road signs and compare them with saved ones in matlab so if you may send me the source code of your program i will be thankful.


      • what i am unable to do is to compare two pictures i have already succeeded to import picture from the web cam and turn in into the grey (intenstity) color what i missed is how to compare this picture with a saved ones on simuink

        • you can compare two pictures by using co-relation co-relation check the matchings of pixel use this
          R = CORR2(A,B) computes the correlation coefficient between A
          and B, where A and B are matrices or vectors of the same size.
          Example :
          if ur image is is not good apply median filter other wise its fine
          I = imread(‘anyimage.tif’);
          J = medfilt2(I);
          R = corr2(I,J)

  15. hi khan, im paresh. im trying to run this code, but get an error msg.

    a = imread(‘image1.jpg’); %reading images as array to variable ‘a’ & ‘b’.
    b = imread(‘image2.jpg’);
    c = corr2(a,b); %finding the correlation btwn two images
    if c==1
    disp(‘The images are same’)%output display
    disp(‘the images are not same’)

    Error using ==> mtimes
    Input arguments must be 2-D.

    Error in ==> corr2 at 26
    r = sum(sum(a.*b))/sqrt(sum(sum(a.*a))*sum(sum(b.*b)));

    Error in ==> correkation at 3
    c = corr2(a,b); %finding the correlation btwn two

    ??? Error using ==> mtimes
    Input arguments must be 2-D.

    Error in ==> corr2 at 26
    r = sum(sum(a.*b))/sqrt(sum(sum(a.*a))*sum(sum(b.*b)));

    Error in ==> correkation at 3
    c = corr2(a,b); %finding the correlation btwn two

    ??? Error using ==> mtimes
    Input arguments must be 2-D.

    Error in ==> corr2 at 26
    r = sum(sum(a.*b))/sqrt(sum(sum(a.*a))*sum(sum(b.*b)));

    Error in ==> correkation at 3
    c = corr2(a,b); %finding the correlation btwn two


  16. hey mate, hope you’re good.. well don’t you have any algorithm for Circular/ellipse hough transform for video processing… actually i’m trying to make a speed limit sign recognition, i did convert RGB to Grayscale ,also extract the red part (since i am planning to detect only the prohibition signs), performed morphological process, but now i’m stuck with the hough transform… Any help please

  17. Peter Chang

    Hello Khan,

    Excellent work! Would you kindly send me the source code? I am working on a similar problem.


    Peter Chang

  18. Hi, good work I’m interesting by the road signs detection and recognition. Could you send me the source code please ?

    Thank you,


  19. mide david

    Hi Khan, this is great to finally find some one using matlab for traffic sign recognition. My research has made me find mostly face recognitions and other types. I am a student of Information engineering and I am working on a project for ANN used for road sign recognition.Please canI have the source codes for the blob analysis method you used?..I was tryinng to work with the PCA for face recognition and tried to adjust for road signs, but because i am just learning matlab, its difficult. Could you help out?

  20. mide david

    Hi Khan, I am quite happy to find a place where someone talks about traffic sign recognition. Please can i get the source codes? I am a student on information engineering and I am working on a project on road sign recognition using NN’s.I am also very new to matlab but started getting my way around. could you help/

  21. i copied the code above and made it run but its not running giving errors such as
    Error: File: main.m Line: 5 Column: 28
    The input character is not valid in MATLAB statements or expressions.
    kindly help

  22. Hi Ammadkhan,

    First I want to help you for sharing your project and knowledge.
    I am very interested in this subject and I would like to know more about this.
    Can you please send me the source code and I would be very happy if you could tell me which tools do I need and which versions.

    Thank you in advance!

  23. Adeel Rafiq

    Hi Ammad Khan,

    Hopefully you are doing well.

    I did as u said. Kindly email me this source code.

    I am working on Foggy Sign board.
    In pre-processing i am working on MSRCR.
    After pre-processing your code will help to complete my task.

    Kindly email me and suggest me if u have pre-processing MSRCR source code.



  24. hello when i run this code i get an error saying
    File “yieldtag1.jpg” does not exist.
    and also
    Error in ==> project at 10
    mov(k).cdata=blobAnalysis(mov(k).cdata);%Call Blob Analysis Function

    what is the reason behind this?

  25. Hi ammad. Can you send me the source code of this. I am working on this kind of project. It will be very helpful if you send.

Leave a Reply