A Controlling Traffic Light system using Fuzzy logic

Automatic control systems are a new advanced system uses computers and hardware controllers to act as a driving system. Increasing in cars numbers while we have the same infrastructure caused a large traffic problem so we need automatic adaptive controllers to control the open and close tasks of traffic light system. Fuzzy Logic is a conversation from classical logic with values of 0 for false and 1 for true to a range of values between 0 and 1. 
This study aims to create an adaptive traffic control system using fuzzy logic and image processing, we have a camera on each traffic light to calculate the number of cars there and then we feed the number of cars to a fuzzy logic system to decide which traffic light must become on


Introduction
Artificial intelligent is one of the most advanced computing sciences which is searching for advanced ways to result solutions so the computer can simulate intelligent of human brain so it can solve problems and make decisions in a logic manner.
Artificial intelligent is used in many applications like theory presentation and image and voice recognition and machine learning [1].
There are many ways to get an artificial intelligent system like: • Neural Networks: which are systems to analyze data in such manner like what neurons does in humans.The neural network consists of a large number of neurons used for data processing which contains a mathematical model.
• Fuzzy Logic: Fuzzy logic was created in 1965 and was used for description of multiple sum's where the fuzzy group was used to define multiple vales for its items, Fuzzy Logic is a conversation from classical logic with values of 0 for false and 1 for true to a range of values between 0 and 1 [2].
• Genetic Algorithm: any living creature consists of cells and every cell consists of chromosomes which instruct a DNA.Every gene has a specific data of a description in the creature (e.g., color of eyes).The first step in reproduction activity is the merging between these chromosomes to create a new child one.
The search is divided into four sections [2], [3].Section 1 gives a global view about the fuzzy logic, fuzzy logic sets, using the fuzzy logic in traffic systems.Section 2 gives an interview about the Gaussian mixture algorithm.Section 3 introduces the method used to control the traffic light system.And section 4 shows the results and discussions about the research.The search aims to control the traffic lights by detecting the cars on each way using the fuzzy logic [4], [5].This method can enable an automatic light control system not a static one as the traffic lights will open depending on the number of cars not a specific time for each traffic light which can decrease the jam problem on the ways.

RELATED WORKS
Many studies were used to control the traffic light system.Some of these methods where static using hardware like controllers and logic circuits.These systems depend mainly on static constant time to open and close the traffic light without taking into account the traffic situation.Other systems were developed to predicate the number of the cars or the traffic jam situation on each way [6].Study [7] gives an introduction of using fuzzy logic to control the traffic lights where the researchers decide to manage the cars as a queue with priorities, where the criteria chosen was the number of the cars, the length of the queue and the width of the road that decides how many cars are accepted.When building the fuzzy system, the green lights when the queue is empty where removed.The result was better comparing with the ordinary light control systems.In study [8], researchers give a close interview about the methodologies used in traffic light systems control.Many of the searches main scope was TST and TSC.Some of searches depends on one parameter where others depend on a collection of parameters.Main parameters used in these systems where the traffic light condition, time duration of each light, the green color required time, how cars are queuing, calibration between these cars, and many other important conditions.The search detects that over 77% from the total searches are working using simulation tools.Main timing constants were green time, cycle length, phase sequence, change interval, offset.Study [9] gives an interview about using artificial intelligent to build a smart traffic light system.This system depends mainly on the car weight if it is larger or less than 80 tones.This research uses the traffic data collected by Google earth, the higher intensity of traffic means a larger pass time.Where cameras were used for an emergency situation.The system proposed was evaluated using logic simulation modeling software tool.This system was able to reduce the number of cars in a specific time into 55% and increase the speed of cars into 55%.Decreasing the number of cars which have to take a while into 29% and decrease the waiting time for the cars to pass the intersections by 38%.Study [7] researchers try to solve the problem of intersections passing in 4-way roads.This research takes into account in addition to normal parameters the vehicles connectivity and autonomous vehicles.Detecting of cars was done by sensors and computing and prediction of the future way of the cars.Research found that defining the traffic as a network was good solution for decreasing the traffic problems and gives a good control for the traffic lights.In study [9] researches used the reinforcement training for traffic signal control, all studies in this scope depends on two intersections or more.This study uses the natural languages processing to give the best solution.More than 160 articles were shown in this study to give the best result using RL techniques.

COMPARATIVE ANALYSIS
All previous researches aim to use several techniques for the traffic light control.In this research Fuzzy Logic was used to predicate the timing system by calculating the cars using a camera on the traffic lights on four-way intersection.Image processing techniques were used to isolate the cars and count them in each cross.These four values were passed to the fuzzy rules to control the traffic lightening behavior with a duration of 1 second for each data feeding task [10], [11].The system performed gives an accuracy 85.4% which was higher than previous studies but our search did not take into account the type of cars or the autonomous cars.Research uses MATLAB application to program the method proposed.Where the main problem was to get the actual number of cars.Normal techniques failed to give a good result using image processing.So, in this search gaussian mixture algorithm were used to solve the problem and gives a high accuracy to isolate and count the cars from the camera frames [12], [13].

FUZZY LOGIC
Fuzzy Logic is such a manner to describe approximated information, where it tries to give solutions using language sentences like long or short or youngest which are called linguistic or fuzzy variables [14].Fuzzy logic was created to solve problems in classical logic where it depends on quantities to analyze systems and make decisions.In classical logic there are two values, 0 for false and 1 for true, so if there is a global group X and a subset A, the element in A must belong to group A or not.In Fuzzy Logic it differs because of having a belong to group as a degree or probability, here an object can belong to the subset A with a probability of 0.9 and no belonging with probability of 0.1 [15], [16].

Bposition of
Cfurther nomenclature continues down the page inside the text box \

Fuzzy Set
In classical logic, the decision that the object belongs to a set is an exact value, so it is clear that the negative number is -2, -13.etcwhere the numbers +2, +14 does not belong to that group, that is, belong or not to a subset.In another hand, the fuzzy set differs from classical one that it can allow partial membership, Membership degree in fuzzy set is defined as, any member  ∈  has a numeric value between 0 and 1, the bigger of this value means more membership to that subset.And the member is full membership when membership degree is 1 [17], [18].In another hand, the member does not belong to a group when membership degree is 0.Fuzzy sets are written as pairs of numbers, first one is a member of set and the second is the membership degree.For example, if there is a global set X with members [18], [19]: Then set A is a fuzzy set: ,0.25), (3,0.5),(4,0.7),(5,0.8),(6,0.9),(7,1)} There are several types of membership functions defined in Fig. 1 Fig. 1. membership functions in fuzzy logic

Logical operations using fuzzy logic
To build a system depends on fuzzy logic, there are some logical operations to deal with, fuzzy variables which are [20]: • Intersection .
The intersection between two fuzzy groups is defined as: The union between two fuzzy sets with membership degrees   ,   is the biggest membership between the two: for the same example: Complementation between two fuzzy groups is the part that belongs to a global set X but still out the fuzzy logic set A. the membership degree of any member in a global set equal to: Fuzzy Implication is a group of rules and conditional statements.For example, if the temperature is medium and humidity is low the weather is good [21], [22].

4.3.Resulting technique
This is the full operations used to take decisions using fuzzy logic which contains all the requirements wanted which are [23], [24]: • Fuzzification: this is the first step in resulting technique, here the numerical inputs are converted to fuzzy sets to became able to use in fuzzy system.
• Knowledge base: knowledge base contains fuzzy rules in the form of conditional statements, the first part of the law may contain more than one condition, it can used to define how the conditions can performed and used by evaluating the primary parts of all laws using indicational operation which uses all logic operations available.
• Decision making:This part of fuzzy logic is an imitation for human way in resulting, although it is a very important step, it is simple using a rule "if the condition is true in a special degree, then the condition result will be true in the same percentage".
• Defuzzification: here the conversation of the linguistic fuzzy values to a numerical value • can be used by computers and another device.One of the most important ways used here is Center of Area (COA), that means calculating areas of possible decisions.So, if the fuzzy system chooses two decisions, then the final decision will be using the center of area law [25]: Where: : fuzzy logic set the decision belongs to.

GAUSSIAN MIXTURE MODEL
Gaussian mixture model is a model that uses a dense Gaussian probability function to define objects correctly, it divides all the features in several models using Gaussian probability function.Fig. (2) shows an example of Gaussian function.and a result of classification where data is classified by training the nonclassified data using machine learning.The result will be described with probability, so the result which have the bigger probability will classified in a special class [26], [27].

Mathematical description for the Gaussian mixture model
Gaussian models are described in multiple dimensions, two or three or even N dimension but it can approximate to any surface using a gaussian function, in case of 2D Gaussian function , equation ( 4) describes the Gaussian function [28]:

Fig.2. constructing of Gaussian mixture model
Where  is standard deviation,  is the average, and  the studied sample,see Fig. 3 Fig.

2D Gaussian function
In the case of 3D function equation ( 5) became more complicated using equation [29]: In the case of N-Dimension Gaussian function the equation becomes [30]: Where the correlation matrix is:

MODELING AND FLOWCHARTS
For modeling the system of traffic light control system; the first important part is building a fuzzy temples for the network studying, and then decide the accurate times for on and off times for each of traffic light lights of the four traffic lights on the cross of the street.Fig. 4. shows a flowchart how our system works: Fig. 4. Flowchart of the system First of all, a previous data will be set for the three main times of green, yellow, and red line which are equal for the first time.Another fuzzy set will be defined with the number of the cars in each corner of the street.These two fuzzy sets will be changed then as the number of the cars changed.A decision matrix is performed to set the main characteristics of the system.The fuzzy rules then are set on the decision matrix which contain for example (red 1, yellow 0.5, green 0) which means that the red color is on, the yellow will light for a half time, and the green is turned off.The time of light-on is a number between 0 and 1 which defines the time the traffic will light on depending on the number of cars.Fig. (5) shows a flowchart of counting cars in the system, this is done by getting a video of a group of cameras on each traffic light, I could be a normal camera or a CCTV camera.the first step was the need to get a number of frames, each frame is processed alone with a sequenced steps starts with Gaussian mixture algorithm.This algorithm is able to isolate and detect the number of the cars by defining the maximum probability of being a car in the video.The max values above the threshold are defined as cars so counting these values mean that having the number of the cars.
The resulted image after gaussian mixture will suffer from noise, this noise appears as a white and black spot which can cross the threshold and counted as a car which may cause an error in the system, to solve this problem, the morphological operations were used.Here, the opening operation where done that deletes the values that crosses the threshold but has a small size in the image (e.g., small number of pixels).The image resulted from the previous step needs smoothing which were done using the blob filter, the blob filter is a filter that has a circular structure and able to sharpen important edges in the image.This filter is able to classify cars areas from non-cars ones so it is possible to get the region of interests (ROI) and calculate the centers of each area as a car position.This trained model is fed then to the fuzzy sets to decide which traffic light will turns on an for how much of time.

RESULTS AND RECOMMENDATION
First of all, the main task was creating a fuzzy set and rules, two fuzzy sets where defined, first one for changing between lights and the second is the time required for the green light to switch on.The application used in the research was Math Works MATLAB as a simulation application.Rules in the study is divided into two groups.First one is the fuzzy select which has to control the rules on each cross in the street and the second is the green light select which has the task of controlling red, yellow, and green lights in the system.
Fig. (6) shows the rules controlling the system as string statements, as we can see in the Fig.the priority of opening any street is the jam situation.If all the cross sides are equal then there is no problem which street will opened, the high has the top priority then the medium and at last the low.In the same manner, when the system decides which street will open, the green light is turned on in a constant time for each light in one traffic sign.So, a membership function was created with three states derived from the previous states in fuzzy select rules.Fig. 6. shows the membership function of the green time.

Fig.6. membership function of green time
After that a prepare of the image processing system was created to detect and count cars in video.the system will try decide the number of cars on each way of the cross, this number of cars will be got from a camera that counting the cars using background subtract.It is important that the studied system must work in real time, MATLAB was used as mentioned before as programing language for image processing

Get frames from camera
Define GMM Morphological operations

Blob filtering
Isolate the cars and count them

Save trained model
Run the model on all cameras system too, first of all isolating of the background was done using Foreground Detector with three areas.choosing a primary 50 frames to create three Gaussian areas was enough, and then the step command was used to get the frames as images.Fig. 7. shows a frame of the video where the traffic sign is grounded. .

Figure.7. video frame got by step command
After training task, the detector starts to give a high accuracy output, which helps to detect all the cars in the image, but the result suffers of bad accuracy because of high noise, so to remove the noise morphological opening was important to remove the noise and fill all the gaps in founded objects, a decision to use an experimental square morphology structure with a size 3 was taken too.To create the morphological object, the "strel" command and "imopen" for the opening operation where done..After that, a blob analyze filter was performed around all connected objects in the image which used to give a more accurate output to define the car from the output by deleting all the areas less than 150 pixel.The structure of the command is: The blob detector is able to detect the cars structures and plot a rectangle around them, then counting how many rectangles is there which means the number of cars detected.Fig. 9. shows the result of this step.

Fig.9. detecting and counting cars in an image
The number of cars will be fed to an array of one row and four columns where each column belongs to the number of cars on each street in the cross.There is a need to create another fuzzy set which contains four members indicates each way, and the values inside it will take 1 for green and 0 for red and 0.5 for yellow.
There is a problem if one of the traffic signs keeps red (e.g., the number of cars here is less than the number of cars on other traffic signs for a long time).So it must kept sure that any traffic sign must opened green after 4 epochs to keep the traffic moving in a good manner.To keep the proposed system is working fine, it is important to define the time required for cars departure out of any cross, and the number of these cars.The fuzzy logic will decide which traffic sign could became green, if the number of cars is large then the control operation would be out of fuzzy logic and will be evaluated then we will count the number of cars leaving the street after the green light has turned on and that must be for a constant number of cars.

CONCLUSIONS
Many methods were used to control the traffic light systems, depending on several methods like deep learning and machine learning.The main advantage of the fuzzy logic method is its high speed compared with neural networks that needs a high processing power and may not work in real time, neural networks try to predicate the number of the cars depending on the previous data.While fuzzy logic is able to work with real time data fed by the image processing system.
As a result of the proposed, the system was working in a real time showing how the number of cars were changing and how the traffic light is responding each change in cars numbers, and how the streets directions are moving.
In the same manner, the Image processing system increases the value of the system specially in traffic in jam cities which can decrease the accidents situation and the time delay too.

)
(2.75) = 0.25   (2.75) = 0.75  (∩) (2.75) = min(0.25,0.75)= 0.25 Fig.5.sequential steps of counting cars Fig.(8) shows the result of this operation and apply blob analyze filter to clean the foreground the function as MAX function.By evaluating the fuzzy select rule we will decide which street will open first as four values:[street1, street2, street3, street4] =[3,6,9,12].Else select in next epochs the max function.As we say before each traffic light must turn on every interval for a required time.And after opening a traffic sign for the required time we must reset all the records in this sign to get a new number of cars in the next epoch and so on.So it is possible to define the green time fuzzy membership set where the time required to open the green light is selected, this opening must connect with the number of cars getting out of the specific way this can be written by: is possible to calculate the green time of each way after getting the cars numbers on every cross.greentime(ii)=ceil(((x(b(ii)) +(.7*entercar))/exitcar)*timeconstantfuzzy);