Sunday, August 7, 2011

Image Processing with MATLAB (Basic)


In this section: We processing the image with MATLAB code.
We will start with the basic and to make progress to advance level together.

MATLAB: lesson1 "load image to MATLAB"
Getting Start
Don't forget "The file must be in the current directory or on the MA
TLAB path"
(In this blog Comment are green texts start after %(comment))
Function
:imread
Description
:reads a greyscale or color image from the file specified by the string 'filename'

Note: Please download bubbles.jpg to your computer first (ex. E:\Blog)


Example 1
read image
>>M=imread('bubbles.jpg'); %(imread returns the image-file data in the array 'M')

View this image with

>>imshow(M); 
%(displays the intensity image M)
or
>>imview(M); 
%(displays the intensity image M)


like this Fig.












Example 2

read image sequence
download This File to your computer first
(this contain image01.tif-image05.tif & Read_image_Series.m)
%%%%%%%%%%
clear all

b = 1; 
%(first image)
npic = 5; 
%( last image)
for i=b:npic;

str = num2str(i); %(convert number 'i' to string)
name = strcat('','image0',str,'.tif'); 
%(('','image0',str,'.tif') :''=directory contain file.'image0'=incomplete file name. str = string mean that 1.'.tif'= file format all of this mean that name is image0str.tif=image01.tif)
MAT = imread(name);
figure() 
%( reserve figure)
imshow(name); 
%(display image name)
title(i); 
%( show title in each image with the no.)
end

%%%%%%%%%%

Function
:aviread
Description
:Read an Audio/Video Interleaved (AVI) file
Example 3read avi file
download avi file to your computer
%%%%%%%%%%

>>Ar=aviread('movie01.avi');

Example 4make avi file
download Image Series to your computer%%%%%%%%%%

clear all


b = 16;

npic = 60;
mov = avifile('MakeVi01.avi') %MakeVi01.avi name of avi-file save to your comp.
for i=b:npic;
str = num2str(i);
name = strcat('ImageSe/','SPT200',str,'.tif'); % ex. image1.tiff : (file name= 'SPT200')
MAT = imread(name); 
imshow(MAT);
axis off;
title(i);

F(i) = getframe(gca);
mov = addframe(mov,F(i));
end
mov = close(mov)

=============================================================

MATLAB: lesson2
"Filtering in MATLAB"
Function
:Y= filter2(filter,image,shape)
Description
:returns the part of Y specified by the shape parameter. shape is a string
with one of these values:

'full' Returns the full two-dimensional correlation. In this case, Y is larger than X.

'same' (default) Returns the central part of the correlation. In this case, Y is the same size as X.

'valid' Returns only those parts of the correlation that are computed without zero-padded edges. In this case, Y is smaller than X
Example 1download file
%%%%%%%%%%

>> clear all
>> a=imread('cute01.tif');
>> imshow(a);

>> Fil=fspecial('average');% function f
special is one(3,3)/9
>> aFilter=filter2(Fil,a);
>> imshow(aFilter/255);













Image Series


Saturday, August 6, 2011

Sherlock Holmes 2 : A Game of Shadows trailor



Sherlock Holmes 2: A Game of Shadows Trailer 2011 HD


In theaters: December 16th, 2011
Genre: Action and Adventure, Thriller
Official Site: http://www.sherlockholmes2.com
Director: Guy Ritchie
Cast: Robert Downey Jr., Jude Law, Noomi Rapace, Jared Harris, Eddie Marsan, Stephen Fry, Gilles Lellouche
Writers: Kieran Mulroney, Michele Mulroney

Storyline:
Sherlock Holmes and his sidekick Dr. Watson join forces to outwit and bring down their fiercest adversary, Professor Moriarty.

Face Access : A Portable Face Recognition System


faceaccess
"A standalone face recognition access control system"
project soundbyte
We created a standalone face recognition system for access control. Users enroll in the system with the push of a button and can then log in with a different button. Face recognition uses an eigenface method. Initial testing indicates an 88% successful login rate with no false positives.
There are currently commercially available systems for face recognition, but they are bulky, expensive, and proprietary. Our goal was to create a portable low-cost system. Our design consists of an Atmel ATmega644 8-bit microcontroller, a C3088 camera module with an OmniVision OV6620 CMOS image sensor, Atmel's AT45DB321D Serial Dataflash, a Varitronix MDLS16264 LCD module for output, a 9-volt battery, and a small wooden structure for chin support.

LED-Following K'NEX Car


Introduction

In a Nutshell

What We Did

Why We Did It

The initial inspiration for this project came from the movie TRON: Legacy. In the movie, there are trains called "Solar Sailers" whose destinations are directed by a beam of light. Here is an image of a solar sailer: 

After some brainstorming, we came up with the idea of a car that could drive by itself by following a path of light. We thought this could be a practical and cool project. We initially envisioned the road to be made of two LED paths: one on the left and one on the right of the car. This would be like the lane markers on a road that we see today. A transportation system like this has several benefits: 
For example, LEDs consume much less power than lightbulbs. Therefore, we can save power by switching to LED lit roads from regular streetlamps. We an also implement traffic systems by having multicolor LEDs. Green LEDs mean the car can go at the speed limit. Red LEDs mean the car will stop. The lights can change to yellow to make the car slow down. The lights can dynamically change so that a certain distance before and after a car is yellow. This could prevent bumper-to-bumper accidents. This system can also combat drunk driving and other traffic accidents, since the driver is no longer a human. 


High Level Design

Background Math

Logical Structure

Our hardware logic structure looks as follows: 

High level design      
In our project, the phototransistors sent their outputs to the ATMEL Mega644 microcontroller. The MCU then calculates which motors should move based on the phototransistors and sends a signal to the optoisolators telling which motors to turn on. Depending on which optoisolator is turned on, the motor control will tell which motor to move. We used optoisolators to separate the MCU from the motor circuitry. Optoisolators isolate the LED side of the circuit from the phototransistor side of the circuit, ideally protecting the MCU from any unknown outputs from the motor controller.

Hardware/software Tradeoffs

Snce we used K'NEX to build our car, we had to deal with an imperfect steering system. This steering system had a very limited turning angle. However, since the parts were preowned, it was free, as opposed to buying a toy car. 

Another tradeoff we had to make was the LED strip color and photodetector. In our project description, we talked about how we wanted green LEDs to mean go and red LEDs to mean stop. We found that multicolor LEDs were more expensive than single color LED strips. We also had trouble finding LED strips that were sideways flexible, long, and cheap. We did not want orange LEDs, but orange LEDs were the cheapest available option. Additionally, there were phototransistors in stock that were sensitive to the dominant wavelength of the LED strip. Therefore, we chose the orange LED strip.

Standards

Patents, Copyrights, Trademarks

K'NEX is a trademark of K'NEX LP Group


Hardware Design

K'NEX Car Design

Motor Circuitry

Our project used two motors, which were encased in a K'NEX fitting and were connected to a motor controller (also from K'NEX). Since the motors were from a set that had three motors, the motors are numbered on the K'NEX fitting. We used motors 2 and 3, because they are connected to the same controller (motor 1 has its own controller). The motor controller had 6-pin port which one could use to drive the motors. This is because the K'NEX set has a parent controller that sends instructions to the motor controller through these pins. We experimented with low voltages to see how we could interact with the pins to make the motors turn. The following diagram shows the pin diagram of the motor controller: 

Motor control pin diagram
The following table maps the motor control pins to their function:

Motor Cotroller Pin # Voltage Required (V) Function
1 Unknown Unknown
2 3 Turn Motor 3 Clockwise
3 3 Turn Motor 3 Counter-Clockwise
4 0 Ground
5 3 Turn Motor 2 Counter-clockwise
6 3 Turn Motor 2 Clockwise
To tell if a motor is spinning clockwise or counter-clockwise, we put the wire on the left side and position the motor casing so that we can read the number on it. 

Our initial tests found that Pin 1 is ground, and a voltage of -1.5V was required on Pin 4 for the motors to turn in the opposite direction. However, when we raised the pin voltages to 3, we found that we did not need Pin 1 to drive the motors. Thus, we left Pin 1 empty, since we were able to control the motors fine using only pins 2-6. 

The circuitry for the motor control is in the appendix. We measured the resistance of the motor controllers and it turned out to be around 47kOhms. To be safe, we used an optoisolator (4N35) to separate the microcontroller from the motor controller. We used 330Ohm resistors in series with the input of the optoisolator to prevent the microcontroller side of the circuit from shorting when the internal LED was on. The actual resistor values were 331Ohms, 328Ohms, 326Ohms, and 324Ohms. We drove the optoisolators from Port B0 to B3 on the microcontroller. If we put an active high on the port, the motor would spin. 

On the motor control side of the optoisolator, we connected the collecter to a 3V battery source and the emitter of each optoisolator to the motor control pin. We did not bias the base, because the light from the internal LED was enough to drive the optoisolator. 

Motor 2 controls the front steering wheels and motor 3 controls the back driving wheels.

Sensor Circuitry

Microcontroller

Since our project was a car, we could not use the STK500 for our final design.  However, we left out the MAX233 and RS232 because we did not need a serial interface on our final board. This posed some difficulties in debugging in the later phases, but saved money, since our final design did not need a serial interface. 

We used an ATMEL Mega644 with a 16MHz crystal because this is what we used throughout the semester. Although we probably could have used a less-powerful MCU, we decided to stick with what we knew best. 

For the project, we used ports A0 and A1 for analog inputs from the phototransistor circuit. We used ports B0 to B3 to control the motors, and port D2 to control the test LED on the custom PC board.

Test track

We made our test track using the LED strip and some cardboard boxes we had lying around in our dorm. We flattened the cardboard and put the LED strip in the center. To make sure that we can still configure the track in different paths, we only tied down one end of the LED strip. This side was attached to a 9V battery. Even though the LED strip required a 12V source, 9V was enough to light the LEDs, so we used one 9V battery. 


Software Design

Our software consisted of test components and the final design. We started off with code to turn the motors after we figured out how the K'NEX motors worked. This test code spun the two motors in two different directions. We used PORT B to do this, since PORT A was reserved for the ADC necessary for the phototransistors. We used C macros to keep track of which port was assigned to which motor/direction. 

Once we got the motors working, we switched over to the phototransistors. After we got the hardware prepared, we put one output of the phototransistor into PORT A0 and the other into PORT A1. We initiallized the ADC like we did in lab 3 for the trimpot controller . To test if the phototransistors worked, we used uart.c and uart.h to communicate with PuTTY. We printed out the ADC output from one phototransistor, and then the other. Since the conversions take time, we found that in order to do two conversions, we needed to wait several cycles between reading and starting the conversions. Therefore, we created a task adc() which runs every 10ms to read one output (so it takes 20ms to read both). This was more than enough time to read the outputs and since our car was not very fast, we did not ned to sample the phototransistors any faster. 

One thing we needed to take care of was to make sure the ADC did not respond to ambient light. Since the phototransistors were underneath the car, ambient light did not pose a large problem. Underneath our car, the phototransistors only outputted between 3 and 10 when the LED was turned off. When the lights were turned on, it detected between 3 and 230, depending on where the LED strip was. If the phototransistor was only detecting 3, it meant that the LED strip went out of the phototransistor's detection range (which falls after around >30 degrees). To kill ambient noise, we set a threshold so that if the output of the ADC was less than the threshold, the software did nothing with the motors. This threshold was set to 20, since it was signifcantly greater than 10 and it worked well.

The greatest challenge was putting the two parts of our hardware together in software. First, we made a simple test program that would spin only one motor in only one direction. By doing so, we were able to test whether or not the phototransistors and the motors were still working properly. This test was important, because we decided not to add a USB connection to our custom PC board to save money. Thus, once our hardware was soldered together and placed on the car, we could no longer communicate through PuTTY for easier debugging. 

While testing our car, we noticed that the motors did not have enough power from the batteries to spin two motors at a time. To get around this, we made our software such that only one motor could spin at any given time. We first checked if the value in Ain0 or Ain1 were greater than the ambient light threshold. We then took the difference of the two outputs. If the difference was between right_bound and left_bound, then the LED strip was centered with the car. Therefore, we drove the back wheels to go forward. If the difference was greater than right_bound, then we made the car turn its front wheels right. If the difference was less than left_bound, we made the car turn its front wheels left. To make sure the steering motor did not keep spinning (since this would cause our car to break) we limited how long the motor was allowed to spin by using a counter. If the steering motor spun for its limit, we made the car drive the back wheels again. We tried spinning both the steering motor and the driving motors at the same time but it did not work. We also tried alternating between steering and driving, but this failed as well. 

Much later in the debugging stage, we replaced the batteries in the K'NEX battery pack and noticed that fresh batteries could spin two motors at the same time. 

**DO NOT USE BATTERIES FROM WHEN YOU WERE 10 YEARS OLD!!!** 

The fresh batteries spun the motors much faster, so we had to change some of the timings in our code. Additionally, we could now apin both motors at the same time, allowing us some freedom. However, since we already had something that was remotely working, we decided to keep the only-one-motor-at-a-time setup. 

One problem that rose with the new batteries was speed. The car motors ran much faster with new batteries. This was fine if the car was going straight, but on turns, the car would drive too fast and it would often go off the LED strip. To fix this, we implemented a simple software Pulse-Width Modulator (PWM) to control the driving wheel speed. If the car was going straight, it would drive at full speed. On turns, we made the car drive at 25% of full speed, meaning the PWM was on for 1/4 of the time. This causes the car to move slowly and to look like it is stuttering. However, we could not drive the motors too slowly because the motor control circuit and the motors react slowly. 

Now that we could drive two motors at the same time, we added in a function that would recenter the wheels when the car was coming out of a turn while still driving. This made some turns smoother but also added some limitations on S-shaped tracks because the car would now go straight a tiny bit more before turning in the opposite direction. 

Lastly, we made our car recenter its steering wheels and stop driving when the phototransistors detected less than the ambient threshold. If the phototransistors detected less than ambient, it meant that the car was off the LED strip for whatever reason. By recentering the wheels, it allowed us to test our car again without manually centering the wheels. We were able to do this by using the turning limits we used on the wheels mentioned earlier. We simply made the steering counter go back to 0 if it was not at zero. If the counter was less than 0, we made the steering motor turn right. If the counter was greater than 0, we made the steering motor turn left.        

Results

Speed of Execution

Accuracy

Our car, due to its design, had a very limited turning range. The phototransistors would detect the light, but if a turn was too sharp, the car would drive off the road, often hooking the LED strip and dragging it. However, for turns within its range, the car would be able to make the turn properly. 

Another problem was a straight line. Again, because of it's design, the car would never actually drive perfectly straight. It would always be biased a bit to the left or right. This caused some problems on straight paths, because it would still not drive straight. On straight paths, sometimes, the path is short enough, or the car is straight enough that it would drive fine. However, the car would sometimes oscillate on the straight path.

Safety Enforcement

Interference with Other People's Designs

Our car had two motors that could have created some noise for other people. However, since our circuit was right over the motors and it was running fine, we highly doubt it was causing problems for others. 

We also used an LED strip that emiited orange light, which may have caused problems for other people if they had projects operating on a similar wavelength. If we were to interfere, it was probably the amount of space our car required. The LED strip was 38" long. We were able to test it underneath our workbench, but we may have gotten in the way of other people. Later in testing, we took our project outside the lab room and tested in the hallway.

Usability

Our project is usable, but the limited turning angle may pose a problem. If the LED strip turns too sharply, the car will react, but not be able turn sharply enough. This turning angle is approximately 30 degrees. 

Another thing we realized is that the car can catch the LED strip and drag it if it got close enough. To fix this flaw, we would need the LED strip to be embedded into the path so that it is on the same elevation as the road. That way, the car can drive over it easily. We couldn't really do that with this project while keeping the road configurable. One option we had was to take a large sheet of glass (or some other stiff, transparent sheet) and put it over the LED strip. However, this would take time and money to get. According to google, a large sheet of glass goes for at least $100. 

Conclusion

Expectations

Our project met our expectations fairly well. After building our K'NEX car, we realized that it would have a limited turning angle. The final design only reinforced this, because our car would go off the LED strip path for sharp turns. However, if the angles were within the car's turning angle, the car would behave as expected. 

One thing we did not account for was the height of the LED strip. The LED strips we used in other classes were rounded and low, so our car would be able to go right over it. However, those strips are not designed to bend left and right. Thus, we bought an LED strip that was flexible in the left and right directions. This LED strip ended up being tall and were straight, so the car could not go over the light. Instead, the car would end up grabbing the LED strip and dragging it.

Conform to Applicable Standards


Ethical Considerations

We followed the IEEE Code of Ethics to the best of our knowledge. Since our project was a moving object, we had to make sure it would not endanger the well-being of the public and environment. We made sure that if the car was not detecting light significantly above the ambient threshold, it would not move. If the car was moving previously, but stopped detecting light, it would stop moving as well. That way, our car was guaranteed to stay within our testing area, which we made sure people would not enter. 

The motors were from a K'NEX set that was meant for ages 10+, meaning our car is not suited for children under the age of 10. Our car also has small parts, meaning it poses choking hazard for small children. We made sure there were no small children nearby when working on our project. If our car is to be replicated by some other party, they must make sure to follow the age restrictions. 

Our car and LED strip required 9 Volts, which is within safe range. Our components can produce low amounts of heat and magnetic fields, both of which cannot be helped and should be safe. The LED strip should not be stared at for long periods of time, for the light emitted are quite bright. However, there are no health warnings for the LED strip on the vendor website. 

All of our claims in this report are honest and realistic. We are quite inexperienced, with this project being the first real ECE design project. We tried our best to do our best while keeping any legal restrictions, ethics, and standards in mind. If our project did not follow any rules, it would be because we were unaware of them, even after our research. 

We did not accept any bribery in any form, nor did we bribe others in any form. We tried to learn as much as we could from this lab. We thought of appropriate applications of our project. Modern cars can be very dangerous if misused, so a car that could drive itself could be beneficial to the world. LEDs are much more energy efficient than street lamps, so LED-lit roads would be much more energy efficient. Furthermore, LED-lit roads can be placed on any road, where as street lamps would have to be placed next to roads, requiring more space. If cars could follow LED strips, then people would no longer have to worry about drunk driving or reckless drivers. These cars would also benefit disabled people who cannot drive as well. 

We have also considered the limitations of our project. For instance, we have to make sure our project is weather-proof. The LED strip we bought was IP67, which means that it is "Totally protected against dust" and "Protected against the effect of immersion between 15cm and 1m" Ingress Protection However, we have to make sure the lights would not be covered by physical objects such as rocks and snow. 

Since we are still inexperienced ECE majors, we are still in the process of learning much about the field. We are working hard to improve our technical competence and will only take on tasks when we are fully qualified. We are willing to take any constructive criticism and will acknowledge and correct any errors we have made. We will also credit all who have contributed to our project. 

We will not discriminate based on race, religion, gender, disability, age, or national origin. Our product is for all to use and learn from, as long as they are above the age of 10. Any real-world implementation of our project will be for all groups of people. We will not endanger the physical, mental or social well-being of others and will support all of our colleagues and co-workers.

We made sure to follow any legal restrictions we found that applied to our lab. We researched if there were any limitations on using the dominant 615nm wevelength of light that our LED strip emitted. We also researched if there were any restrictions for toy cars, such as maximum toy car speed. We were unable to find any legal restrictions that limited either of these. 

The K'NEX pieces we used are for ages 10+ so our project is for ages at least 10+ as well. If we were to scale our project to a real car, we must follow the legal speed limits imposed on streets. 



Appendix: Images

Appendix: Code

Custom PC Board

Motor Control

Sensor Circuit

Complete Circuit

References

Google : The top most search engine

Google : MAGIC BOX

nRelate - Posts and Homepage

LinkWithin

Related Posts Plugin for WordPress, Blogger...

Which is the toughest subject ?