Image Processing Basics

Page 1

BASICS


Q: WHAT IS IMAGE PROCESSING??? Accessing the data stored in an image and working with it is called Image Processing.


Q: WHAT IS AN IMAGE??? It’s a 2 dimensional array of pixels with each pixel having an unsigned value between 0 and 255.


SOME BASIC TERMINOLOGY USED IN Image Processing Resolution: The resolution of an image defines how many pixels are there in the image, for example: if an image has the resolution of [ 800 X 600 ] it means that the image is a two dimensional array of size[800][600] that is 800 pixel in the horizontal direction for each of the 600 pixel in the vertical direction.


Pixel: Units which make up the image are called pixels. These contain some value depicting the shade of the particular cell.


Channel: It is the number of divisions in a particular pixel. Eg: In a single channel image, the pixel has one value between 0 and 255. Eg: Grayscale Image.


In a 3 channel image, each pixel will have 3 values between 0 and 255. The shade of that pixel will be the shade resulting from the combination of these 3 values. Eg: BGR image(Which is any coloured image we see) or and HSV Image.


Noise: Unwanted Part In an Image. Binary Image: An Image which has only 2 shades (generally black and white).

Grayscale Image

Binary Image


Threshold: Threshold in image processing is the

value of a particular channel set by the programmer which is the border line between the wanted and the unwanted pixels. The image below shows an image thresholded into a binary image.


Histogram : A Graphical representation of the value of pixels versus the frequency of each pixel.


Q: HOW TO WORK WITH ALL THESE??? A Library called openCV contains Functions which helps us in accessing the image elements and working with them.


How to Start Working Install Microsoft Visual Studio. Install OpenCV . Integrate OpenCV with Microsoft Visual Studio. (Procedure for linking given on our website : http://www.robotix.in/tutorials/ip ).


SAMPLE CODE

LOADING AN IMAGE STORED IN YOUR COMPUTER #include "stdafx.h" #include <stdio.h> #include <cv.h> #include<iostream> #include"conio.h" #include <cxcore.h> #include <highgui.h> #include <stdlib.h> #include <windows.h> int main( int argc, char **argv) { cvNamedWindow("bgr image", CV_WINDOW_AUTOSIZE);//creating a window for the image. cvMoveWindow("bgr image", 100, 100); //move it to 100, 100 position.


IplImage *frame=0; frame = cvLoadImage("1.jpg"); if( !frame ){ printf("frame not captured properly"); return 1; } cvShowImage("bgr image", frame); // display the image cvWaitKey(0); cvReleaseImage(&frame); return 0; }


LOADING AN IMAGE AND CONVERTING IT INTO A GRAYSCALE IMAGE. int main( int argc, char **argv) { cvNamedWindow("bgr image", CV_WINDOW_AUTOSIZE);//creating a window for the image. cvMoveWindow("bgr image", 100, 100); //move it to 100, 100 position. cvNamedWindow("grayscale img", CV_WINDOW_AUTOSIZE);//creating a window for the image. cvMoveWindow("grayscale img", 100, 100); //move it to 100, 100 position. IplImage *frame=0; IplImage *grayscale=0; frame = cvLoadImage("1.jpg"); if( !frame ){ printf("frame not captured properly"); return 1; }


cvShowImage("bgr image", frame); // display the image /* creating a single channel image of the same size as the original image*/ grayscale = cvCreateImage( cvSize(frame->width, frame->height), IPL_DEPTH_8U, 1 ); cvCvtColor(frame,grayscale,CV_RGB2GRAY);//for converting image into a grayscale image. cvShowImage("grayscale img", grayscale); // display the image cvWaitKey(0); cvReleaseImage(&frame); return 0; }


SOME USEFUL COMMANDS ACCESSING THE VALUE OF PIXELS: for(i=0;i<height;i++)//height is the image height { for(j=0;j<width;j++)//width is the image width { k=image->imageData[i*height+j*nChannels]=0; printf(“The value of pixel [%d][%d] is %d”,I,j,k); } } The above commands prints the values of all the pixels in the image one by one


CLONING AN IMAGE IplImage *img1=cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,1); IplImage* img2; img2=cvCloneImage(img1);// img2 is clone of img1


DO IT YOURSELF Take a grayscale image and make its histogram and display.


Sample Running Programs • Histogram. • Color Detection and Ball Following. • Movement Detection.


ROBOTIX ’12 Image Processing Event NUKE-CLEAR Problem Statement: Build an autonomous image processing robot which can traverse around rooms, locate and disarm bombs.


HOW TO APPROACH THE PROBLEM STATEMENT?


Resources  Codes can be found here.  Image Processing Tutorial can be found here  Nuke-Clear tutorial can be found here.


Hope You Enjoyed Learning Image Processing


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.