If you like this article, please share it with your friends and like our facebook page for future updates. Subscribe to our newsletter to get notifications about our updates via email. If you have any queries, feel free to ask in the comments section below. Have a nice day!

Before understanding the concept behind image reading and recognition, you should understand “Fourier Transform” and basic matrix operations in Matlab.

1) Let’s consider we have captured below the picture of the vehicle, in which number plate and its font is clear with the surrounding contrast.

2) To locate the car license plate and identify the characters, we use the Matlab platform to provide some image processing functions to Fourier transform the character template and the image to be processed as the core idea. The basic method is as follows:

Read the image to be processed and convert it to a binary image. After converting, using the threshold of 0.2 near the license plate characters most clearly, the least points (as shown below)

I = imread('car.jpg');
I2 = rgb2gray(I);
I4 = im2bw(I2, 0.2);

Remove the area where the image is too small to be sure of the license plate.

bw = bwareaopen(I4, 500);

To locate the license plate, inflate the white area, corrode to unrelated small objects, including the license plate characters.

se = strel('disk',15);
bw = imclose(bw,se);

At this point the number plate where the white connectivity domain is clearly visible, but outside the black area, there is a larger white connectivity domain and the license plate where the domain surrounded by. It is necessary to fill it.

bw = imfill(bw,[1 1]);

Now, let’s find the connectivity domain boundary. While retaining this graphic for later to mark it on it.

[B,L] = bwboundaries(bw,4);
imshow(label2rgb(L, @jet, [.5 .5 .5]))
hold on

Finding the one that is most likely to be the number plate in all connected domains. The standard of judgment is that the aspect ratio of the license plate is about 4.5: 1, and its area is related to the circumference:(4.5 × L × L) / (2 × (4.5 + 1) × L) 2 ≈ 1/27 ,Which is characterized by,metric = 27 * area / perimeter ^ 2as the matching degree of the connected domain, the closer it is to 1, the more likely that the corresponding connected domain is 4.5: 1.

MATLAB Program

stats = regionprops(L,'Area','Centroid');
for k = 1:length(B)
boundary = B{k};
delta_sq = diff(boundary).^2;
perimeter = sum(sqrt(sum(delta_sq,2)));
area = stats(k).Area;
metric = 27*area/perimeter^2;
metric_string = sprintf('%2.2f',metric);
if metric >= 0.9 && metric <= 1.1
centroid = stats(k).Centroid;
plot(centroid(1),centroid(2),'ko');
goalboundary = boundary;
s = min(goalboundary, [], 1);
e = max(goalboundary, [], 1);
goal = imcrop(I4,[s(2) s(1) e(2)-s(2) e(1)-s(1)]);
end
text(boundary(1,2)-35,boundary(1,1)+13,...
metric_string,'Color','g',...
'FontSize',14,'FontWeight','bold');
end
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2),boundary(:,1),'w','LineWidth',2)
end

The rectangular matching degree is 0.99, which is the most probable area. Below is the license plate area in the binary image determined by it:

The license plate image is highlighted and expanded to a square of 256 × 256 (left as shown below) so that the matrix rotation operation is performed in the following “Fourier transform”.

Read a character template from the file (with “P” as an example, the template image is taken directly from the above binary image). Calculate the Fourier descriptor for the image and calculate the descriptor with a predefined decision function. In the transformed image, the level of brightness indicates the degree to which the corresponding region matches the template (as shown in the figure below).

w = imread('P.bmp');
w = ~w;
C= real(ifft2(fft2(goal).*fft2(rot90(w,2),256,256)));

By checking the maximum value of C, the test determines a suitable threshold (where 240 is appropriate), showing the point where the brightness is greater than the threshold, that is, the highest degree of matching to the template (see below).

thresh = 240;
figure;
imshow(C > thresh);

In contrast to the left and right graphs, it can be shown that the character “P” is recognized and positioned. The same way that you can identify and locate other characters.

3) This method is generally easier to understand, Matlab function hides the Fourier transform and other complex calculations. Disadvantages: In the positioning of the license plate, the program specifically according to the characteristics of the given image design, there is no universality. In character recognition, only characters that are substantially consistent with a given template are recognized. License plate size, angle, light, integrity, clarity changes, it can not be identified. At the same time for “8” and “B” similar characters, recognition is often confused.

Download

Click here to download MATLAB program and related files.

If you like this article, please share it with your friends and like or facebook page for future updates. Subscribe to our newsletter to get notifications about our updates via email. If you have any queries, feel free to ask in the comments section below. Have a nice day!

Hi friends, in this MATLAB tutorial we are going to calculate Maclaurin Series of order n. We know that A Maclaurin series is a Taylor series expansion of a function about 0,

Let’s see a MATLAB program to calculate Maclaurin Series of order n.

MATLAB Program for Maclaurin Series

Initially, it will take input x as theta of cos. Then it will ask how many terms the series should expand. By using for loop and Maclurin Series formula it will generate the series up to the terms required.

%Maclurine series%
x = input('enter value of cosx :');
n=input('enter last value:');
for i=1:n
series=(((-1)^n)/(factorial(2*n)))*(x^(2*n));
series=series+series;
end
series

This article is written by Gohar Jamal. I hope you liked this article. Like our facebook page and subscribe to our newsletter for future updates. If you have any queries feel free to ask in the comment section below. Have a nice day!

Hi friends, today we are going to discuss discrete time signals and how to plot graphs of different discrete time signals such as step signal, a ramp signal, impulse function, exponential, sine and cosine signals using MATLAB.

Before going towards actual programming part, let us recall the definition of the discrete time signal.

“In discrete time signal, the value of the signal is specified only at a specific time. So signal represented at “discrete interval of time” is called as a discrete time signal.”

MATLAB Program:

clc;
clear all;
close all;
x=[0:15];
for i=1:16
y(i)=1;
end
subplot(2,3,1)
stem(x,y)
title('Discrete time Step Function')
xlabel('Samples')
ylabel('Step function')
for i=1:16
y(i)=x(i);
end
subplot(2,3,2)
stem(x,y)
title('Discrete time Ramp Function')
xlabel('Samples')
ylabel('Ramp signal')
y=[zeros(1,4),1,zeros(1,11)];
subplot(2,3,3)
stem(x,y)
title('Discrete time Impulse Function')
xlabel('Samples')
ylabel('Impulse function')
for i=1:16
y(i)=exp(-0.22*i);
end
subplot(2,3,4)
stem(x,y)
title('Discrete time Exponential Function')
xlabel('Samples')
ylabel('Exponential function')
z=[1:35]
for i=1:35
y(i)=sin(2*pi*0.1*i)
end
subplot(2,3,5)
stem(z,y)
title('Discrete time Sine Function')
xlabel('Samples')
ylabel('Sine function')
z=[1:35]
for i=1:35
y(i)=cos(2*pi*0.1*i)
end
subplot(2,3,6)
stem(z,y)
title('Discrete time Cosine Function')
xlabel('Samples')
ylabel('Cosine function')

Explanation:

Representation of discrete time step function:

x=[0:15];
for i=1:16
y(i)=1;
end
subplot(2,3,1)
stem(x,y)
title('Discrete time Step Function')
xlabel('Samples')
ylabel('Step function')

For representing discrete time step function, let us consider x-axis represents a number of samples and y-axis represents corresponding values of the signal. Here we use two matrix x and y. x=[0:15] represents matrix ‘x’ contains 16 elements from 0 to 15. Then we used one for loop from 1:16 (16 times) in which we define matrix y, which stores ‘1’ entire the matrix. Then we give command subplot(2,3,1). Here we used subplot command because we want all the basic signals on a single display. (2,3,1) represents there are 2 rows and 3 columns of graphs (it means 2*3=6 graphs are possible) 1 indicates that we want this graph at first position.

As we know for continuous signal plotting we use plot command but for a discrete time signal, we have to use stem command.

Similarly, for discrete time ramp signal, we use y(i)=x(i) keeping all the program same.

For impulse function we use y=[zeros(1,4),1,zeros(1,11)] that means first 4 elements of the matrix are ‘0(zeros)’ 5th element is ‘1’ and from 6th to 16th it is again ‘0’. Thus y becomes 16 element matrix. Thus we can plot a graph of impulse function using Matlab.

For exponential signal, we have used exp(-0.22*i). Here negative sign indicates that the nature of the exponential signal is decreasing. But if you remove the negative sign it will become a simple increasing exponential signal.

Similarly, we can plot discrete time sine and cosine functions using MATLAB

If you like this article, please share it with your friends and like or facebook page for future updates. Subscribe to our newsletter to get notifications about our updates via email. If you have any queries, feel free to ask in the comments section below. Have a nice day!

The preceding methods of solving simultaneous linear equations are known as direct methods as they yield an exact solution. On the other hand, an iterative method is that in which we start from an approximation to the true solution and obtain better and better approximation from a computation cycle repeated as often as may be necessary for achieving the desired accuracy. Simple iteration methods can be devised for systems in which the coefficient of leading diagonal is large compared to others.

There are two iterative methods as follows:

1) Jacobi’s iteration method.

2) Gauss-Seidel iteration method.

Today we are just concentrating on the first method that is Jacobi’s iteration method. We will see second method (Gauss-Seidel iteration method) for solving simultaneous equations in next post. After that, I will show you how to write a MATLAB program for solving roots of simultaneous equations using Jacobi’s Iterative method.

Jacobi’s Iteration Method:

Let us consider set of simultaneous equations as follows:

a1x+b1y+c1z=d1…………………1)

a2x+b2y+c2z=d2…………………1)

a3x+b3y+c3z=d3…………………1)

If a1, b2, c3 are large as compare to other coefficient then solving these for x,y, and z respectively. Then the system can be written in the form:

x = (k1) – (l1)y – (m1)z…………..2)

y = (k2) – (l2)x – (m2)z…………….2)

z = (k3) – (l3)x – (m3)y…………….2)

Let us starts with the initial approximations x0=k1, y0=k2 and z0=k3.(by putting x=y=z=0 in right hand side above equation)

Then the second approximation is given by,

x1 = (k1) – (l1)y0 – (m1)z0…………..3)

y1= (k2) – (l2)x0 – (m2)z0…………….3)

z1 = (k3) – (l3)x0 – (m3)y0…………….3)

Third approximation is given by,

x2 = (k1) – (l1)y1 – (m1)z1…………..4)

y2= (k2) – (l2)x1 – (m2)z1…………….4)

z2 = (k3) – (l3)x1 – (m3)y1…………….4)

This process is repeated till difference between two consecutive approximations is negligible.

Let us understand this method in detail by solving one simple example.

Example

Solve following set of simultaneous equations using Jacobi’s iterative method.

20x+y-2z=17

3x+20y-z=-18

2x-3y+20z=25

Solution

We write the given equations in the following form:

x = (1/20)(17-y+2z)……………..1)

y = (1/20)(-18-3x+z)…………….1)

z = (1/20)(25-2x+3y)……………1)

Substitute x0=y0=z0=0 in above equation we get,

x1 = (1/20)(17); y1 = (1/20)(-18); z1=(1/20)(25).

Or x1=0.85; y1=-0.90; z1=1.25

Put x1, y1 and z1 in equation (1)

x2 = 1.02; y2 = -0.965; z2 = 1.03.

Put x2, y2 and z2 in equation (1)

x3 = 1.001; y3 = -1.001; z3 = 1.003.

Put x3, y3 and z3 in equation (1)

x4 = 1.0004; y4 = -1; z4=0.99975

Put x4, y4 and z4 in equation (1)

x5 = 1; y5 = -1; z5=1

Now it is sufficient. If you observe above two sets of roots, they are almost same.

Hence the roots of given simultaneous equations using Jacobi’s iterative method are:

If you like this article, please share it with your friends and like or facebook page for future updates. Subscribe to our newsletter to get notifications about our updates via email. If you have any queries, feel free to ask in the comments section below. Have a nice day!

Lagrange’s Interpolation Formula is used to determine the value of any function f(x), which is known at discrete points. That is if we have any function with its value at different points such as, at x=0, 1, 2… So using Lagrange’s Interpolation Formula, we can determine the value of that function at any point.

Derivation

We can derive the Lagrange’s Interpolation formula by using Newton’s divided difference formula. If f(x) is approximated with a Nth degree polynomial then the Nth divided difference of f(x) constant and (N+1)th divided difference is zero. That is

as we know Lagrange’s interpolation is a Nth degree polynomial approximation to f(x) and the Nth degree polynomial passing through (N+1) points is unique hence the Lagrange’s and Newton’s divided difference approximations are one and the same. However, Lagrange’s interpolation formula is very useful for the computer programming while Newton’s difference formula is convenient for the hand calculations.

Question: Given set of values of x and y (5,12),(6,13),(9,14),(11,16)
Find the value of x corresponding to y=15 using lagrange interpolation

Solution

Tabular the given data:

y: 12 13 14 16

x: 5 6 9 11

Applying lagrange interpolation formula,

x(y)=(y-13)(y-14)(y-16)*5/(12-13)(12-14)(12-16)+

(y-12)(y-14)(y-16)*6/(13-12)(13-14)(13-16)+

(y-12)(y-13)(y-16)*9/(14-12)(14-13)(14-16)+

(y-12)(y-13)(y-14)*11/(16-12)(16-13)(16-14).

By putting y=15 we get x(15)=11.5

MATLAB Code for Lagrange Interpolation Formula

%Created by myclassbook.org
%Created on 26 May 2013
%lagrange interpolation formula
% Question: Given set of values of x and y (5,12),(6,13),(9,14),(11,16)
% Find the value of x corresponding to y=15 using lagrange interpolation
clc;
clear all;
close all;
y=[12 13 14 16]; %Change here for different function
x=[5 6 9 11];
a=15;
%Applying Lagrange's Interpolation:
ans1=((a-y(2))*(a-y(3))*(a-y(4)))*x(1)/((y(1)-y(2))*(y(1)-y(3))*(y(1)-y(4)));
ans2=((a-y(1))*(a-y(3))*(a-y(4)))*x(2)/((y(2)-y(1))*(y(2)-y(3))*(y(2)-y(4)));
ans3=((a-y(1))*(a-y(2))*(a-y(4)))*x(3)/((y(3)-y(1))*(y(3)-y(2))*(y(3)-y(4)));
ans4=((a-y(1))*(a-y(2))*(a-y(3)))*x(4)/((y(4)-y(1))*(y(4)-y(2))*(y(4)-y(3)));
m=ans1+ans2+ans3+ans4;
y
x
fprintf('the value of x corresponding to y=15 is %f',m);

Image Format

If you like this article, please share it with your friends and like or facebook page for future updates. Subscribe to our newsletter to get notifications about our updates via email. If you have any queries, feel free to ask in the comments section below. Have a nice day!

Evaluate the integral x^4 within limits -3 to 3 using Simpson’s 3/8th Rule.

Solution

Let y(x)=x^4

here a=-3 and b=3

therefore (b-a)=6

let ‘n’ be the number of intervals. assume n=6 in this case.

also h=(b-a)/n = 6/6 =1

x: -3 -2 -1 0 1 2 3

y: 81 16 1 0 1 16 81

According to Simpson’s 3/8th Rule:

answer= (3h/8)*[(y1+y7)+3*(y2+y3+y5+y6)+2*(y4)]

answer=(3/8)*[(81+81)+3*(16+1+1+16)+2*(0)]

answer=99.

MATLAB Code for Simpson’s 3/8th Rule

%Created by myclassbook.org (Mayuresh)
%Created on 24 May 2013
%Question: Evaluate the integral x^4 within limits -3 to 3
clc;
clear all;
close all;
[email protected](x)x^4; %Change here for different function
a=-3;b=3; %Given limits
n=b-a; %Number of intervals
h=(b-a)/n;
p=0;
for i=a:b
p=p+1;
x(p)=i;
y(p)=i^4; %Change here for different function
end
l=length(x);
x
y
answer=(3*h/8)*((y(1)+y(l))+3*(y(2)+y(3)+y(5)+y(6))+2*(y(4)))

Image Format

Second Example

Evaluate the integral 1/(1+x) within limits 0 to 6 using Simpson’s 3/8th rule.

Solution

Let y(x)=1/(1+x)

here a=0 and b=6

therefore (b-a)=6

let ‘n’ be the number of intervals. assume n=6 in this case.

%Created by myclassbook.org (Mayuresh)
%Created on 24 May 2013
%Question: Evaluate the integral 1/(1+x) within limits 0 to 6
clc;
clear all;
close all;
[email protected](x)1/(1+x); %Change here for different function
a=0;b=6; %Given limits
n=b-a; %Number of intervals
h=(b-a)/n;
p=0;
for i=a:b
p=p+1;
x(p)=i;
y(p)=1/(1+i); %Change here for different function
end
l=length(x);
x
y
answer=(3*h/8)*((y(1)+y(l))+3*(y(2)+y(3)+y(5)+y(6))+2*(y(4)))

If you like this article, please share it with your friends and like or facebook page for future updates. Subscribe to our newsletter to get notifications about our updates via email. If you have any queries, feel free to ask in the comments section below. Have a nice day!

Evaluate the integral x^4 within limits -3 to 3 using Simpson’s 1/3 rd rule.

Solution

Let y(x)=x^4

here a=-3 and b=3

therefore (b-a)=6

let ‘n’ be the number of intervals. assume n=6 in this case.

also h=(b-a)/n = 6/6 =1

x: -3 -2 -1 0 1 2 3

y: 81 16 1 0 1 16 81

According to Simpson’s 1/3rd rule:

answer= (h/3)*[(y1+y7)+2*(y3+y5)+4*(y2+y4+y6)]

answer=(1/2)*[(81+81)+2*(1+1)+4*(16+0+16)]

answer=98.

MATLAB Program For Simpson’s 1/3rd Rule

%Created by myclassbook.org (Mayuresh)
%Created on 24 May 2013
%Question: Evaluate the integral X^4 within limits 3 to -3
clc;
clear all;
close all;
[email protected](x)x^4; %Change here for different function
a=-3;b=3; %Given limits
n=b-a; %Number of intervals
h=(b-a)/n;
p=0;
for i=a:b
p=p+1;
x(p)=i;
y(p)=i^4; %Change here for different function
end
l=length(x);
x
y
answer=(h/3)*((y(1)+y(l))+2*(y(3)+y(5))+4*(y(2)+y(4)+y(6)))

Image Format

Second Example

Evaluate the integral 1/(1+x) within limits 0 to 6 using Simpson’s 1/3 rd rule.

Solution

Let y(x)=1/(1+x)

here a=0 and b=6

therefore (b-a)=6

let ‘n’ be the number of intervals. assume n=6 in this case.

%Created by myclassbook.org (Mayuresh)
%Created on 24 May 2013
%Question: Evaluate the integral 1/(1+x) within limits 0 to 6
clc;
clear all;
close all;
[email protected](x)1/(1+x); %Change here for different function
a=0;b=6; %Given limits
n=b-a; %Number of intervals
h=(b-a)/n;
p=0;
for i=a:b
p=p+1;
x(p)=i;
y(p)=1/(1+i); %Change here for different function
end
l=length(x);
x
y
answer=(h/3)*((y(1)+y(l))+2*(y(3)+y(5))+4*(y(2)+y(4)+y(6)))

Image Format

If you like this article, please share it with your friends and like or facebook page for future updates. Subscribe to our newsletter to get notifications about our updates via email. If you have any queries, feel free to ask in the comments section below. Have a nice day!

The derivation for obtaining formula for Trapezoidal rule is given by,

Example

Evaluate the integral x^4 within limits -3 to 3 using Trapezoidal rule.

Solution

Let y(x)=x^4

here a=-3 and b=3

therefore (b-a)=6

let ‘n’ be the number of intervals. assume n=6 in this case.

also h=(b-a)/n = 6/6 =1

x: -3 -2 -1 0 1 2 3

y: 81 16 1 0 1 16 81

According to trapezoidal rule:

answer= (h/2)*[(y1+y7)+2*(y2+y3+y4+y5+y6)]

answer=(1/2)*[(81+81)+2*(16+1+0+1+16)]

answer=115.

MATLAB Program for Trapezoidal Rule

%Created by myclassbook.org (Mayuresh)
%Created on 24 May 2013
%Question: Evaluate the integral X^4 within limits 3 to -3
clc;
clear all;
close all;
[email protected](x)x^4; %Change here for different function
a=-3;b=3; %Given limits
n=b-a; %Number of intervals
h=(b-a)/n;
p=0;
for i=a:b
p=p+1;
x(p)=i;
y(p)=i^4; %Change here for different function
end
l=length(x);
x
y
answer=(h/2)*((y(1)+y(l))+2*(sum(y)-y(1)-y(l)))

Image format

Example

Evaluate the integral 1/(1+x) within limits 0 to 6 using Trapezoidal rule.

Solution

Let y(x)=1/(1+x)

here a=0 and b=6

therefore (b-a)=6

let ‘n’ be the number of intervals. assume n=6 in this case.

%Created by myclassbook.org (Mayuresh)
%Created on 24 May 2013
%Question: Evaluate the integral 1/(1+x) within limits 0 to 6
clc;
clear all;
close all;
[email protected](x)1/(1+x); %Change here for different function
a=0;b=6; %Given limits
n=b-a; %Number of intervals
h=(b-a)/n;
p=0;
for i=a:b
p=p+1;
x(p)=i;
y(p)=1/(1+i); %Change here for different function
end
l=length(x);
x
y
answer=(h/2)*((y(1)+y(l))+2*(sum(y)-y(1)-y(l)))

Image Format

If you like this article, please share it with your friends and like or facebook page for future updates. Subscribe to our newsletter to get notifications about our updates via email. If you have any queries, feel free to ask in the comments section below. Have a nice day!

In this tutorial, you will learn how to add two images. Yes, it is possible in MATLAB. You can add i.e. superimpose two images. Following are the steps to add two images using MATLAB image processing:

The only requirement for superimposition (or addition) of two images is that the two matrices that you have defined for two images should have the same size (as we know MATLAB totally works with matrices and the addition of two matrices is possible only when they are of the same size).

Let us consider two images

H: New photorock 1.jpg

H: New photoImagesPhoto1561.jpg

(These are two images that I have chosen, but for your case, it may be different. For copying the image path visit my previous post)

MATLAB Program for Addition of Two Images:

%Addition of two images
%Created by : myclassbook.org (mayuresh)
%Created on : 21 May 2013
A=imread('H:New photorock 1.jpg'); %define A as a first image
B=imread('H:New photoImagesPhoto1561.jpg'); %define B as a second image
C=imresize(A,[400 400]); % image resize of A as 400*400 matrix
D=imresize(B,[400 400]); % image resize of B as 400*400 matrix
E=imadd(C,D); % image addtion of C and D
imshow(E) % display of image E

Output

If you like this article, please share it with your friends and like or facebook page for future updates. Subscribe to our newsletter to get notifications about our updates via email. If you have any queries, feel free to ask in the comments section below. Have a nice day!