A taste of Image Processing

Image processing involves extracting information from images and using the information so obtained for various operations and tasks. Don’t confuse image processing image processing with image manipulation that involves adjusting the images. Photoshop and similar software are used for image manipulation.

Application areas

  • Medical Applications
  • Industrial Applications
  • Military Applications: Some of the most challenging and performance-critical scenarios for image processing solutions have been developed for military needs, ranging from detection of soldiers or vehicles to missile guidance and object recognition and reconnaissance tasks using unmanned aerial vehicles (UAVs). In addition, military applications often require the use of different imaging sensors, such as range cameras and thermo-graphic forward-looking infrared (FLIR) cameras.
  • Law Enforcement and Security: Surveillance applications have become one of the most intensely researched areas within the video processing community. Biometric techniques (e.g., fingerprint, face, iris, and hand recognition), which have been the subject of image processing research for more than a decade, have recently become commercially available.
  • Consumer Electronics
  • The World Wide Web

So as we can see image processing has wide areas of application.

That being said you need some software or programming language for making this image processing possible. There are various ways by which this can be done. You can use c, NI LabVIEW, MATLAB etc. for image processing. For this post I’ll be using MATLAB. Now we did this just so as to understand the concepts of image processing. So if you feel that its meagre you can build on this.

Code

clc;
close all;
clear all;
video = videoinput('winvideo');%Create video variable

set(video,'FramesPerTrigger',1); % Setting frames per trigger
preview(video);%Preview the video
rgb_image = getsnapshot(video); % Storing Image in an array variable
[y x c]= size(rgb_image); % Determining the size of the captured frame.
x1 = (x/2)-(0.2*x);
x2 = (x/2)+(0.2*x);
y1 = (y/2)-(0.25*y);
y2 = (y/2)+(0.25*y);
global s;
s = serial('COM4')
fopen(s)
while(1)
image = getsnapshot(video);
fR = image(:,:,1);
fG = image(:,:,2);
fB = image(:,:,3);
I = fR>200;
se=strel('disk',5);
B=imopen(I,se);
final=imclose(B,se);
[L,n]=bwlabel(final);
for k=1:n
    [r,c]=find(L==k);
    rbar=mean(r);
    cbar=mean(c);
end
rbar
cbar
if x1<cbar<x2 &&  rbar<y1
    disp('Move forward');
    global s;
    fwrite(s,'w')
elseif cbar<x1 && y1<rbar<y2
    disp('Move right');
    global s;
    fwrite(s,'d')
elseif cbar>x2 && y1<rbar<y2
    disp('Move left');
    global s;
    fwrite(s,'a')
elseif x1<cbar<x2 && rbar>y2
    disp('Move back');    
    global s;
    fwrite(s,'s')
elseif x1<cbar<x2 && y1<rbar<y2
    disp('Move stop');
    global s;
    fwrite(s,'f')
end
end

Now this is the code. I am thinking I’ll just explain the logic and then you can use MATLAB help for the rest. Seriously the help provides is simply awesome. You can understand how the functions word using the help and then there is the world wide net. So I am assuming that those of you who has interest will read further.

Now let’s begin understanding the code.

video = videoinput(‘winvideo’);

This will create a video object from the available cameras. You can check the available ones by using imaqhwinfo

image

So for the windows winvideo is installed adapter.

image

Next give winvideo as the agrument to the imaqhwinfo(). Now if you have an external webcam connected to your computer you will se two device ID’s. So now suppose you want to know about the device with ID=1 all you need to do is pass device ID as second argument.

image

You can see the properties you the webcam.

So just use the videoinput() for creating a variable attached to the particular webcam in MATLAB. In our case video is the variable.

Next you set the frames per trigger i.e. whenever you give the capture commands how many frames will be captured every time.

Then you see a preview of the video feed so that you come to know what exactly is the camera viewing.

Next up you take a sample shot so as to determine the dimensions of the camera.

You will get a 3D matrix of the image. Extract the x and y resolution.

Now for this application what we will do is divide the webcam field into 9 quadrants and take decision depending on position of the image of the object to be detected.

Now since we wanted to learn the basic we used white light such as a torch as the source. If you have a proper webcam and good lighting conditions you can detect normal coloured balls using this program. All you need to do is some thresholding.

Now as usual open the serial port and send a particular character depending upon the quadrant in which the object lies.

So you basically take a snapshot again and again and manipulate that snap. So each image is made of 3 components red, blue and green. Since we are using white light as the object it does not matter which component you choose. But if there is a particular colour that the object has take that particular matrix. Now do the thresholding so that you get only the torch circle on the screen.

Then you remove the noise and coalesce the remaining parts to form a single body.

Then you calculate the centroid and take decision.

image

This is a sample of what the image will look like after thresholding. So as you can see it lies in the middle quadrant.

We had written the code such that it will transmit w,a,s,d,f depending on the quadrant. Do top middle corresponds to w and so on you can figure that yourself.

On the controller side we manipulate the data to control the bot.

I’ll be uploading the video soon. Thank you for reading. Hope this was useful.