Vous êtes sur la page 1sur 32

REPORT ON DEVELOPMENT OF CODES IN C++ FOR A FEW IMAGE PROCESSING TOOLBOX FUNCTIONS OF MATLAB

Submitted by, RISHIRAJ HAZARIKA 09-1-5-008 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING NATIONAL INSTITUTE OF TECHNOLOGY, SILCHAR

DEPARTMENT OF ELECTRONICS AND ELECTRICAL ENGINEERING INDIAN INSTITUTE OF TECHNOLOGY GUWAHATI MAY-JUNE, 2011

ACKNOWLEDGEMENT

I take this opportunity to express my sincere gratitude to my guide Dr. Prabin kr. Bora, Professor, Dept. Of Electronics and Electrical Engineering and Dean of Faculty Affairs, Indian Institute of Technology, Guwahati for his continuous inspiration and guidance to me during the course of the project. I am thankful to Bora sir, for his constant help in management and coding the programs(lab work) as well as in providing me with suggestions for improvement. I would also like to thank Mrs Jharna Rani Rabha, Junior Technical Superintendent and all those who helped me during the whole period in the successful completion of the project.

Rishiraj Hazarika Department of Computer Science and Engineering National Institute of Technology, Silchar

Abstract

Image processing projects help in learning many things in computer sciences. Involvement in a project provides direct exposure to the technology and the students can learn faster and effectively. In institutions which teach computer science the image processing can be incorporated in the introductory modules of the course. There are several benefits of image processing projects. These projects give a real exposure of the subject matter and practical experience of how projects are done. In electrical engineering and computer science, image processing is any form of signal processing for which the input is an image, such as a photograph or video frame; the output of image processing may be either an image or, a set of characteristics or parameters related to the image. Most image-processing techniques involve treating the image as a two-dimensional signal and applying standard signal-processing techniques to it. Image processing usually refers to digital image processing, but optical and analog image processing also are possible.

CONTENTS

1. INTRODUCTION 1.1 Overview 1.2 Matlab Platform 1.3 C++ platform 2. IMAGE PROCESSING TOOLBOX 2.1 Introduction 2.2 Fundamentals 2.3 Image Formats Supported 2.4 Applications 2.5 Key Features 3. FUNCTIONS DEVELOPED 3.1 Read a File 3.2 Display a File 3.3 Edge Detection 4. DOCUMENTATION (7) (7) (8) (8) (6) (6) (6) (7) (7) (5) (5) (6)

5. CODE

(8-30)

6. MERITS/DEMERIT OF C++PLATFORM 6.1 Advantages of C++ Platform 6.2 Disadvantages of C++ Platform 7. APPLICATIONS OF C++ PLATFORM (30) (32) (32)

8. CONCLUSION 9. BIBLIOGRAPHY

(32) (32)

CODE DEVELOPMENT IN C++ FOR SOME OF THE IMAGE PROCESSING TOOL BOX FUNCTIONS
1. An Introduction 1.1 Overview
Digital image processing is the use of computer algorithms to perform image processing on digital images. It allows a much wider range of algorithms to be applied to the input data and can avoid problems such as the build-up of noise and signal distortion during processing. IN my project over here, I have tried to develop in C++ (HLL) a few of the image processing tool box functions from Matlab platform. Functions like reading, giving pixel colour, size of image, displaying are being developed in the project.

1.2 Matlab Platform


MATLAB (matrix laboratory) is a numerical computing environment and fourth-generation programming language. MATLAB is a high-level language and interactive environment that enables you to perform computationally intensive tasks faster than with traditional programming languages such as C, C++, and FORTRAN. It is a program that was originally designed to simplify the implementation of numerical linear algebra routines. It has since grown into something much bigger, and it is used to implement numerical algorithms for a wide range of applications. The basic language used is very similar to standard linear algebra notation, but there are a few extensions that will likely cause you some problems at first. You can use MATLAB in a wide range of applications, including signal and image processing, communications, control design, test and measurement, financial modelling and analysis, and computational biology. Add-on toolboxes (collections of special-purpose MATLAB functions, available separately) extend the MATLAB environment to solve particular classes of problems in these application areas.

Key Features

High-level language for technical computing Development environment for managing code, files, and data Interactive tools for iterative exploration, design, and problem solving Mathematical functions for linear algebra, statistics, Fourier analysis, filtering, optimization, and numerical integration 2-D and 3-D graphics functions for visualizing data Tools for building custom graphical user interfaces Functions for integrating MATLAB based algorithms with external applications and languages, such as C, C++, Fortran, Java, COM, and Microsoft Excel

1.3 C++ Platform


C++ (pronounced "see plus plus") is a statically typed, free-form, multi-paradigm, compiled, generalpurpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell Labs as an enhancement to the C language and originally named C with Classes. It was renamed C++ in 1983. The language began as enhancements to C, first adding classes, then virtual functions, operator overloading, multiple inheritance, templates, and exception handling among other features.

Key Features

Data Encapsulation Data Inheritance Data Abstraction Function Overloading Objects Message Passing

2. Image Processing Toolbox


2.1 Introduction Image Processing Toolbox provides a comprehensive set of reference-standard algorithms and graphical tools for image processing, analysis, visualization, and algorithm development. You can perform image enhancement, image deblurring, feature detection, noise reduction, image segmentation, spatial transformations, and image registration. Many functions in the toolbox are multithreaded to take advantage of multicore and multiprocessor computers. 2.2 Fundamentals A digital image is composed of pixels which can be thought of as small dots on the screen. A digital image is an instruction of how to color each pixel. A typical size of an image is 512-by-512 pixels. In the general case we say that an image is of size m-by-n if it is composed of m pixels in the vertical direction and n pixels in the horizontal direction. Let us say that we have an image on the format 512-by-1024 pixels. This means that the data for the image must contain information about 524288 pixels, which requires a lot of memory! Hence, compressing images is essential for efficient image processing. 2.3 Image Formats Supported By The Toolbox The following image formats are supported by Matlab:

BMP HDF JPEG 6

PCX TIFF XWB

2.4 Applications The core MATLAB package comes with several rudimentary functions (to be described later) that can be used to load, save, and perform custom functions on images. However, it is often necessary to perform more complicated operations on images. The image processing toolbox allows such manipulations as:

Direct visualization of images in MATLAB Color space conversions Object grouping and data collection Filtering and fast convolution Fourier analysis of images Image arithmetic Morphological operations

and many others. 2.5 Key Features


Importing and Exporting Images Displaying and Exploring Images Preprocessing and Post processing Images Analyzing Images Spatial Transformations and Image Registration Working with Large Images

3. Functions Developed 3.1 Reading a File


imread - Read image from graphics file Syntax
A = imread(filename, fmt)

In the code given below the function loadbitmap performs the following work of reading a file.

3.2 Displaying a File


imshow - Display image Syntax imshow(I) In the code given below the function loadbitmap performs the following work of reading a file.

3.3 Edge Detection


edge - Find edges in gray scale image Syntax BW = edge(I) In the code given below the function sobel performs the following work of reading a file.

4. Documentation
Header Files Used <stdio.h> - For standard input output of files or names. <stdlib.h> - For functions like randomize, abs etc. <conio.h> - For functions like clrscr, getch etc. <graphics.h> - For graphics related function. <dos.h> - For functions like delay, sleep etc. <math.h> - For mathematical functions. User Defined Functions void loadbitmap(char*) To read and display the image files. int getcol(int) To give the respective colour codes in c++ graphics. void call() Function to display the last page. void size(char*) Functio to give the size of the image void load(char*) Function to give the colour of each pixel void sobel(char*) Function to give the edge detection.

5. Code /******************************************************************** ********/ /* Input: BMP file /* Output:BMP file + Size of the image + Color pixelwise + edge detetion. */ /* Author: Rishiraj Hazarika */ /* Date: 29/06/2011 */
8

/******************************************************************** *********/

#include<stdio.h> #include<stdlib.h> #include<conio.h> #include<graphics.> #include<iostream.h> #include<dos.h> #include<math.h>

//HEADER FILES

void loadbitmap(char*); //READS AND DISPLAYS THE FILE. int getcol(int); //GETTING COLOUR VALUES. void call(); //DISPLAYING LAST PAGE. void size(char*); //GIVING THE SIZE OF THE IMAGE. void load(char*); //GIVING COLOR PIXEL VALUES. void sobel(char*); //SOBEL EDGE DETECTION.

//MAIN STARTS HERE.

void main () { clrscr(); char buffer[50]; int gd,gm; detectgraph(&gd,&gm); initgraph(&gd,&gm,"c:/t/bgi"); int top=100; int left=100; int bottom=getmaxy()-100; int right=getmaxx()-100; setbkcolor(RED); setcolor(WHITE); rectangle(0,0,getmaxx(),getmaxy()); setfillstyle(SOLID_FILL,BROWN); int i,j;
9

for(i=10,j=20;i<221,j<201;i++,j++) { fillellipse(325,270,i,j); delay(10); } char buffer11[]="(1)To Enter The Name Of The Image To Be Read."; char buffer12[]="(2)Exit."; char buffer13[]="Enter Your Choice......"; setcolor(GREEN); int cx=(right+left-textwidth(buffer11))/2+10; int cy=(top+bottom-textheight(buffer11))/2-40; settextstyle(DEFAULT_FONT,HORIZ_DIR,1); outtextxy(cx,cy,buffer11); setcolor(GREEN); cx=(right+left-textwidth(buffer12))/2-140; cy=(top+bottom-textheight(buffer12))/2-10; settextstyle(DEFAULT_FONT,HORIZ_DIR,1); outtextxy(cx,cy,buffer12); setcolor(YELLOW); cx=(right+left-textwidth(buffer13))/2; cy=(top+bottom-textheight(buffer13))/2+70; settextstyle(DEFAULT_FONT,HORIZ_DIR,1); outtextxy(cx,cy,buffer13); for(i=65;i>34;i--) { gotoxy(i,4); cout<<"@#WELCOME#@ "; delay(50); } int k; setcolor(LIGHTBLUE); rectangle(267,44,365,64); cin>>k; switch(k) { case(1) : { clrscr(); cleardevice(); setbkcolor(MAGENTA);
10

cout<<"\n\n\tEnter the name of the Image..: "; gets(buffer); clrscr(); cleardevice(); while(!kbhit()) { randomize(); setfillstyle(SOLID_FILL,LIGHTCYAN); bar(225,225,getmaxx()-225,getmaxy()-225); setcolor(RED); char buffer0[]="READING BITMAP FILE...."; int cx=(100+(getmaxx()-100)-textwidth(buffer))/2; int cy=(100+(getmaxy()-100)-textheight(buffer))/2; settextstyle(DEFAULT_FONT,HORIZ_DIR,1); outtextxy(cx-55,cy,buffer0); delay(300); setfillstyle(SOLID_FILL,WHITE); bar(0,0,getmaxx(),getmaxy()); for(int i=0;i<300;i++) { setcolor(rand()%10); circle(rand()%640,rand()%480,rand()%25); delay(1); } } char h1; do { cleardevice(); setbkcolor(BLUE); setcolor(WHITE); rectangle(0,0,getmaxx(),getmaxy()); int top=100; int left=100; int bottom=getmaxy()-100; int right=getmaxx()-100; char buffer1[]="***********MENU**********"; char buffer2[]="(1) Give The Size Of The Image."; char buffer3[]="(2) Store the image."; char buffer4[]="(3) Display The Image."; char buffer7[]="(4) Color Of The Pixel.";
11

char buffer8[]="(5) Sobel Edge detection."; char buffer5[]="(6) Exit."; char buffer6[]="Enter your choice........"; setfillstyle(SOLID_FILL,RED); bar(left,top,right,bottom); setcolor(GREEN); rectangle(left,top,right,bottom); setcolor(WHITE); int cx=(right+left-textwidth(buffer1))/2-7; int cy=(top+bottom-textheight(buffer1))/2-70; settextstyle(DEFAULT_FONT,HORIZ_DIR,1); outtextxy(cx,cy,buffer1); setcolor(WHITE); cx=(right+left-textwidth(buffer2))/2+38; cy=(top+bottom-textheight(buffer2))/2-40; settextstyle(DEFAULT_FONT,HORIZ_DIR,1); outtextxy(cx,cy,buffer2); setcolor(WHITE); cx=(right+left-textwidth(buffer3))/2-6; cy=(top+bottom-textheight(buffer3))/2-20; settextstyle(DEFAULT_FONT,HORIZ_DIR,1); outtextxy(cx,cy,buffer3); setcolor(WHITE); cx=(right+left-textwidth(buffer4))/2+2; cy=(top+bottom-textheight(buffer4))/2; settextstyle(DEFAULT_FONT,HORIZ_DIR,1); outtextxy(cx,cy,buffer4); setcolor(WHITE); cx=(right+left-textwidth(buffer7))/2+6; cy=(top+bottom-textheight(buffer7))/2+20; settextstyle(DEFAULT_FONT,HORIZ_DIR,1); outtextxy(cx,cy,buffer7); setcolor(WHITE); cx=(right+left-textwidth(buffer8))/2+14; cy=(top+bottom-textheight(buffer8))/2+40; settextstyle(DEFAULT_FONT,HORIZ_DIR,1); outtextxy(cx,cy,buffer8); setcolor(WHITE); cx=(right+left-textwidth(buffer5))/2-50; cy=(top+bottom-textheight(buffer5))/2+60; settextstyle(DEFAULT_FONT,HORIZ_DIR,1); outtextxy(cx,cy,buffer5); setcolor(WHITE); cx=(right+left-textwidth(buffer6))/2;
12

cy=(top+bottom-textheight(buffer6))/2+100; settextstyle(DEFAULT_FONT,HORIZ_DIR,1); outtextxy(cx,cy,buffer6); int i; for(i=47;i>28;i--) { gotoxy(i,4); cout<<"@#IMAGE PROCESSING OPTIONS@# "; delay(50); } int h; cin>>h; if(h==1) { cleardevice(); size(buffer); } if(h==2) { cleardevice(); cout<<"\t\tFile stored.."; } if(h==3) { cleardevice(); loadbitmap(buffer); delay(2000); cleardevice(); } if(h==4) { cleardevice(); load(buffer); } if(h==5) { cleardevice();
13

sobel(buffer); delay(2000); cleardevice(); } if(h==6) { call(); exit(0); } cout<<"\n\n\n\t\tDo You Want To Continue..(Y/N) : "; cin>>h1; }while((h1=='y')||(h1=='Y')); } case (2): { call(); exit(0); } default : { cleardevice(); setbkcolor(YELLOW); cout<<"\n\n\n\t\t\t\tSorry Wrong Choice...."; } } getch(); closegraph(); }

//END OF MAIN. //DISPLAY FUNCTION STARTS HERE void loadbitmap(char *filename) { FILE *ptr=NULL; int width,height;
14

unsigned long temp=0,i=0,j=0; unsigned long ww; ptr=fopen(filename,"rb"); if(!ptr) { cout<<"\n\n\n\t\tFile Not Read..."; delay(1000); exit(0); } width=0;height=0; fseek(ptr,18,SEEK_SET); for(i=0x1;i<=0x10000;i*=0x100) { temp=fgetc(ptr); width+=(temp*i); } fseek(ptr,22,SEEK_SET); for(i=0x1;i<=0x10000;i*=0x100) { temp=fgetc(ptr); height+=(temp*i); } int **arr; arr=new int*[height]; for(i=0;i<height;i++) { arr[i]=new int[ww]; } ww=width; fseek(ptr,1078,SEEK_SET); int ch,ch1,ch2; for(i=0;i<height;i++) for(j=0;j<ww;j++) { ch=fgetc(ptr); arr[i][j]=ch;
15

ch1=ch;//ch2=ch; ch1=ch1&(0xf0);ch1=ch1>>4; putpixel(j,(height-i),getcol(ch1));

} delete arr; } //DISPLAY ENDS HERE.

//COLOR FUNCTIONS STARTS HERE>

int getcol(int col) { switch(col) { case 0: return 0; case 1: return 4; case 2: return 2; case 3: return 6; case 4: return 1; case 5: return 5; case 6: return 3; case 7: return 7; case 8: return 8; case 9: return 12; case 10:return 10; case 11:return 14; case 12:return 9; case 13:return 13; case 14:return 11; case 15:return 15; } return col; }

//BLACK; //RED; //GREEN //BROWN //BLUE; //MAGENTA; //CYAN; //LIGHTGRAY; //DARKGRAY; //LIGHTRED; //LIGHTGREEN //YELLOW; //LIGHTBLUE; //LIGHTMAGENTA //LIGHTCYAN; //WHITE;

//COLOR FUNTIONS ENDS HERE.

16

//DISPLAYING LASTPAGE FUNCTION STARTS HERE.

void call() { cleardevice(); int top=100; int left=100; int bottom=getmaxy()-100; int right=getmaxx()-100; setbkcolor(BROWN); setcolor(RED); rectangle(0,0,getmaxx(),getmaxy()); setcolor(LIGHTBLUE); int i,j; for(i=120;i<(getmaxx()-120);i++) { rectangle(120,120,i,getmaxy()-120); delay(4); } char buf[]="THANKS FOR USING..."; setcolor(CYAN); int cx=(right+left-textwidth(buf))/2-6; int cy=(top+bottom-textheight(buf))/2-20; settextstyle(DEFAULT_FONT,HORIZ_DIR,1); outtextxy(cx,cy,buf); delay(4000); }

//DISPLAY FUNCTION ENDS HERE

//SIZE FUNCTION STARTS HERE

void size(char *file)


17

{ FILE *ptr=NULL; int width,height; unsigned long temp=0,i=0; unsigned long ww; ptr=fopen(file,"rb"); if(!ptr) { cout<<"\n\n\t\t\tSorry File Not Read...."; delay(1000); exit(0); } width=0;height=0; fseek(ptr,18,SEEK_SET); for(i=0x1;i<=0x10000;i*=0x100) { temp=fgetc(ptr); width+=(temp*i); } fseek(ptr,22,SEEK_SET); for(i=0x1;i<=0x10000;i*=0x100) { temp=fgetc(ptr); height+=(temp*i); } cout<<"\n\n\n\tThe size is : "<<width<<"X"<<height; }

//SIZE FUNCTIONS ENDS HERE

//PIXEL SIZE STARTS HERE

void load(char *f) {


18

cleardevice(); FILE *ptr=NULL; int width,height; unsigned long temp=0,i=0,j=0; unsigned long ww; ptr=fopen(f,"rb"); if(!ptr) { cout<<"\n\n\n\t\tFile Not Read..."; delay(1000); exit(0); } width=0;height=0; fseek(ptr,18,SEEK_SET); for(i=0x1;i<=0x10000;i*=0x100) { temp=fgetc(ptr); width+=(temp*i); } fseek(ptr,22,SEEK_SET); for(i=0x1;i<=0x10000;i*=0x100) { temp=fgetc(ptr); height+=(temp*i); } int **arr; arr=new int*[height]; for(i=0;i<height;i++) { arr[i]=new int[ww]; } ww=width; fseek(ptr,1078,SEEK_SET); int ch,ch1,ch2; for(i=0;i<height;i++) for(j=0;j<ww;j++) {
19

ch=fgetc(ptr); arr[i][j]=ch; } cout<<"\n\n\t\tEnter the pixel coordinates : "; cin>>ch1; cout<<"X"; cin>>ch2; ch=arr[ch1][ch2]; ch=ch&(0xf0);ch=ch>>4; int col=getcol(ch); switch(col) { case 0: { cout<<"\n\n\n\n\t\tThe color of the pixel is BLACK"; break; } case 4: { cout<<"\n\n\n\n\t\tThe color of the pixel is RED"; break; } case 2: { cout<<"\n\n\n\n\t\tThe color of the pixel is GREEN"; break; } case 6: { cout<<"\n\n\n\n\t\tThe color of the pixel is BROWN"; break; } case 1: { cout<<"\n\n\n\n\t\tThe color of the pixel is BLUE"; break; }
20

case 5: { cout<<"\n\n\n\n\t\tThe color of the pixel is MAGENTA"; break; } case 3: { cout<<"\n\n\n\n\t\tThe color of the pixel is CYAN"; break; } case 7: { cout<<"\n\n\n\n\t\tThe color of the pixel is LIGHT GRAY"; break; } case 8: { cout<<"\n\n\n\n\t\tThe color of the pixel is DARK GRAY"; break; } case 12: { cout<<"\n\n\n\n\t\tThe color of the pixel is LIGHT RED"; break; } case 10: { cout<<"\n\n\n\n\t\tThe color of the pixel is LIGHT GREEN"; break; } case 14: { cout<<"\n\n\n\n\t\tThe color of the pixel is YELLOW"; break; } case 9: {
21

cout<<"\n\n\n\n\t\tThe color of the pixel is LIGHT BLUE"; break; } case 13: { cout<<"\n\n\n\n\t\tThe color of the pixel is LIGHT MAGENTA"; break; } case 11: { cout<<"\n\n\n\n\t\tThe color of the pixel is LIGHT CYAN"; break; } case 15: { cout<<"\n\n\n\n\t\tThe color of the pixel is WHITE"; break; } } delete arr; }

//PIXEL ENDS HERE.

//EDGE DETECTION STARTS HERE.

void sobel(char *fl) { FILE *ptr=NULL; int width,height; unsigned long temp=0,i=0,j=0; unsigned long ww; ptr=fopen(fl,"rb");
22

if(!ptr) { cout<<"\n\n\n\t\tFile Not Read..."; delay(1000); exit(0); } width=0;height=0; fseek(ptr,18,SEEK_SET); for(i=0x1;i<=0x10000;i*=0x100) //read the width { temp=fgetc(ptr); width+=(temp*i); } fseek(ptr,22,SEEK_SET); for(i=0x1;i<=0x10000;i*=0x100) //read the height { temp=fgetc(ptr); height+=(temp*i); } int **arr; arr=new int*[height]; for(i=0;i<height;i++) { arr[i]=new int[ww]; } ww=width; fseek(ptr,1078,SEEK_SET); int ch; for(i=0;i<height;i++) for(j=0;j<ww;j++) { ch=fgetc(ptr); arr[i][j]=ch; }
23

int gx,gy; for(int x=-1;x<(height-1);x++) { for(int y=-1;y<(ww-1);y++) { gx=(arr[x+2][y]+2*arr[x+2][y+1]+arr[x+2][y+2])(arr[x][y]+2*arr[x][y+1]+arr[x][y+2]); gy=(arr[x][y+2]+2*arr[x+1][y+2]+arr[x+2][y+2])(arr[x][y]+2*arr[x+1][y]+arr[x+2][y]); int sum=abs(gx)+abs(gy); if(sum==0) arr[x+1][y+1]=255; else arr[x+1][y+1]=1; } } fseek(ptr,1078,SEEK_SET); for(i=0;i<height;i++) { for(j=0;j<ww;j++) { ch=arr[i][j]; int ch1=ch; ch1=ch1&(0xf0);ch1=ch1>>4;

putpixel(j,(height-i),getcol(ch1));

} } delete arr; }

//EDGE DETECTION ENDS HERE.


24

//SOME ADDITIONAL CODES FOR SOBEL EDGE DETECTION.

/*void sobel(char *fl) { FILE *ptr=NULL; //file handle to open bitmap file int width,height; //width and height of the bitmap unsigned long temp=0,i=0,j=0; //some variables i need unsigned long ww; ptr=fopen(fl,"rb"); //open the bitmap file if(!ptr) return 0; //if its not there return width=0;height=0; //initialise wisth and height to zero fseek(ptr,18,SEEK_SET); //got to offset 18 in file for(i=0x1;i<=0x10000;i*=0x100) //read the width { temp=fgetc(ptr); width+=(temp*i); } fseek(ptr,22,SEEK_SET); //go to offset 22 in file for(i=0x1;i<=0x10000;i*=0x100) //read the height { temp=fgetc(ptr); height+=(temp*i); } int **arr; arr=new int*[height]; for(i=0;i<height;i++) { arr[i]=new int[width]; } ww=width; fseek(ptr,1078,SEEK_SET); //Ok! offset 119 - lets read the pixels //remember the bitmap is stroed up - side - down int ch,ch1,ch2,k; for(i=0;i<height;i++) for(j=0;j<ww;j++) { ch=fgetc(ptr); arr[i][j]=ch;
25

// ~~ // ch2=ch2&(0x0f); //if(j*2<width)

// ~~ //ok so put the first pixel read on screen

//if(j*2+1<width) //put the second pixel read on screen //putpixel((j)*2+1,(height-1-i),getcol(ch2)); } int *a,*o;

a=new int[height*ww]; o=new int[height*ww]; int ctr=0; for(i=0,k=0;i<height;i++,k+=ww) { for(j=0;j<ww;j++) { a[k]=arr[i][j]; k++; } int *p1,*p2,*p3; p1=a;p2=p1+ww;p3=p2+ww; for(j=0;j<(height-2);++j) { for(i=0;i<(ww-2);++i) { o[ctr++]=(abs((p1[0]+2*p1[1]+p1[2])(p3[0]+2*p3[1]+p3[2]))+abs((p1[2]+2*p2[2]+p3[2])-(p1[0]+2*p2[0]+p3[0])))/6; ++p1;++p2;++p3; } p1+=2; p2+=2; p3+=2; }} for(i=0,k=0;i<height;i++,k+=ww) for(j=0;j<ww;j++) { // ch=fgetc(ptr); ch=o[k]; //each character read is 2 pixels - yes 4 bits per pixel - so 16 colors
26

ch1=ch;//ch2=ch; //find those colors using bitwise ops ch1=ch1&(0xf0);ch1=ch1>>4; // ~~ // ch2=ch2&(0x0f); // ~~ //if(j*2<width) //ok so put the first pixel read on screen putpixel(j,(height-i),getcol(ch1)); //if(j*2+1<width) //put the second pixel read on screen //putpixel((j)*2+1,(height-1-i),getcol(ch2)); k++; }

delete arr,a,o; fclose(ptr); }*/ /* void sobel(char *fl) { FILE *ptr=NULL; //file handle to open bitmap file int width,height; //width and height of the bitmap unsigned long temp=0,i=0,j=0; //some variables i need unsigned long ww; ptr=fopen(filename,"rb"); //open the bitmap file if(!ptr) return 0; //if its not there return width=0;height=0; //initialise wisth and height to zero fseek(ptr,18,SEEK_SET); //got to offset 18 in file for(i=0x1;i<=0x10000;i*=0x100) //read the width { temp=fgetc(ptr); width+=(temp*i); } fseek(ptr,22,SEEK_SET); //go to offset 22 in file for(i=0x1;i<=0x10000;i*=0x100) //read the height { temp=fgetc(ptr); height+=(temp*i); } int **arr; arr=new int*[height]; for(i=0;i<height;i++) {
27

arr[i]=new int[width]; } ww=width; fseek(ptr,1078,SEEK_SET); //Ok! offset 119 - lets read the pixels //remember the bitmap is stroed up - side - down int ch,ch1,ch2; for(i=0;i<height;i++) for(j=0;j<ww;j++) { ch=fgetc(ptr); arr[i][j]=ch; //each character read is 2 pixels - yes 4 bits per pixel - so 16 colors //ch2=ch; //find those colors using bitwise ops // ~~ // ch2=ch2&(0x0f); // ~~ //if(j*2<width) //ok so put the first pixel read on screen //if(j*2+1<width) //put the second pixel read on screen //putpixel((j)*2+1,(height-1-i),getcol(ch2)); } int gx[3][3],gy[3][3]; gx[0][0]=-1;gx[0][1]=-2;gx[0][2]=-1; gx[1][0]=0;gx[1][1]=0;gx[1][2]=0; gx[2][0]=1;gx[2][1]=2;gx[2][2]=1; gy[0][0]=-1;gy[0][1]=0;gy[0][2]=1; gy[1][0]=-2;gy[1][1]=0;gy[1][2]=2; gy[2][0]=-1;gy[2][1]=0;gy[2][2]=1; int **px; px=new int*[height]; for(i=0;i<height;i++) { px[i]=new int[ww]; } for(int x=0;x<height;x++) { for(int y=0;y<width;y++) { px[x][y]=arr[y][x]; } } for(x=0;x<height;x++)
28

{ for(int y=0;y<ww;y++) { int sumx=0,sumy=0,sum; if((x==0)||(x==(height-1))) sum=0; if((y==0)||(y==(ww-1))) sum=0; else { //g[x-1][y-1]=(arr[x+1][y+1]+2*arr[x+1][y]+arr[x+1][y-1])-(arr[x-1][y-1]+2*arr[x1][y+1]+arr[x+1][y-1]); //gy=(arr[x][y+2]+2*arr[x+1][y+2]+arr[x+2][y+2])(arr[x][y]+2*arr[x+1][y]+arr[x+2][y]); //} //} for(i=-1;i<2;i++) { for(j=-1;j<2;j++) { sumx=sumx+gx[j+1][i+1]*arr[x+j][y+i]; } } for(i=-1;i<2;i++) { for(j=-1;j<2;j++) { sumy=sumy+gy[j+1][i+1]*arr[x+j][y+i]; } } sum=sqrt(pow(sumx,2)+pow(sumy,2));} //} if(sum>255) sum=255; if(sum<0) sum=0; px[y][x]=sum; // //else //arr[x+1][y+1]=1;

29

//arr[x][y]=arr[x+1][y]=arr[x+2][y]=arr[x+1][y]=arr[x+1][y+2]=arr[x+2][y]=arr[x+2] [y+1]=arr[x+2][y+2]=1;

} } for(i=0;i<height;i++) { for(j=0;j<ww;j++) { arr[i][j]=px[j][i]; } } fseek(ptr,1078,SEEK_SET); for(i=0;i<height;i++) { for(j=0;j<ww;j++) { // ch=fgetc(ptr); ch=arr[i][j]; //each character read is 2 pixels - yes 4 bits per pixel - so 16 colors ch1=ch;//ch2=ch; //find those colors using bitwise ops ch1=ch1&(0xf0);ch1=ch1>>4; // ~~ // ch2=ch2&(0x0f); // ~~ //if(j*2<width) //ok so put the first pixel read on screen putpixel(j,(height-i),getcol(ch1)); //if(j*2+1<width) //put the second pixel read on screen //putpixel((j)*2+1,(height-1-i),getcol(ch2)); }} delete arr; fclose(ptr); }*/

6. MERITS/DEMERITS 6.1 Advantages of C++ Platform


C++ (Object-Oriented Programming) has the following advantages over conventional approaches:

30

C++ provides a clear modular structure for programs which makes it good for defining abstract datatypes where implementation details are hidden and the unit has a clearly defined interface. C++ makes it easy to maintain and modify existing code as new objects can be created with small differences to existing ones. C++ provides a good framework for code libraries where supplied software components can be easily adapted and modified by the programmer. This is particularly useful for developing graphical user interfaces.

Advantages of C++:

Objects Classes Data Abstraction and Encapsulation Inheritance Polymorphism

Objects Objects are the basic run-time entities in an object-oriented system. Programming problem is analyzed in terms of objects and nature of communication between them. When a program is executed, objects interact with each other by sending messages. Different objects can also interact with each other without knowing the details of their data or code. Classes A class is a collection of objects of similar type. Once a class is defined, any number of objects can be created which belong to that class. Data Abstraction and Encapsulation Abstraction refers to the act of representing essential features without including the background details or explanations. Classes use the concept of abstraction and are defined as a list of abstract attributes. Storing data and functions in a single unit (class) is encapsulation. Data cannot be accessible to the outside world and only those functions which are stored in the class can access it. Inheritance Inheritance is the process by which objects can acquire the properties of objects of other class. In OOP, inheritance provides reusability, like, adding additional features to an existing class without modifying it. This is achieved by deriving a new class from the existing one. The new class will have combined features of both the classes. Polymorphism Polymorphism means the ability to take more than one form. An operation may exhibit different behaviors in different instances. The behavior depends on the data types used in the operation. Polymorphism is extensively used in implementing Inheritance. It is a highly efficient process. Efficiency (efficiency here is defined as that part of the biomass energy that is available in the producer gas generated from the biomass) is in the gasification range of 70% to 85% depending on the mode in which the gas is being used. Gasification can be applied over a range of output ratings (few kWs to hundreds of kWs). It can be used for thermal applications & electricity generation. The syngas produced can be used for any application that a fossil fuel (coal, natural Gas etc.) is currently used for. There is low initial investment and cost of power production. As the fuel is biomass, the cost of fuel is also much reduced (as compared to fossil fuels). Thus the unit cost of energy generation becomes very low. It is a source of clean energy removing its prospect of pollution due to its cleaner combustion technique. 31

6.2 Disadvantages of C++ Platform

It's not pure object oriented programming language because C++ doesn't support for garbage
collection which is overcome by java. It does not provide very strong type-checking. C++ code is easily prone to errors related to data types, their conversions, for example, while passing arguments to functions. No built in support for threads. Gets complex when you want to develop a graphics rich application in c++ Portability of code on various platforms, etc

7. Application of C++ Platform C++ provides a collection of predefined classes, along with the capability of user-defined classes. The classes of C++ are data types,which can be instantiated any number of times. Class definitions specify data objects (called data members) and functions (called member function). Classes can name one or more parent classes, providing inheritance and multiple inheritance, respectively. Classes inherit the data members and member functions of the parent class that are specified to be inheritable. Therefore it is mainly used for:

Software Engineering Graphics

9. Conclusion
In developing the codes for a few of the image processing Matlab toolbox functions I have learnt about image processing. In doing same I have learnt a lot about C++ graphics which of course needs to be incorporated in reading or displaying an image file. It shows thee differences lying between the two platforms for image processing works. The above code uses a lot of C++ graphics library functions to make the output menu driven and look graphically smart along with the functions that has to be used to accomplish the code.

10. Bibliography
Image Processing Using Matlab-Woods and Gonzalez Object Oriented Programming with C++-Balaguruswamy www.softwaresandfinance.com

32

Vous aimerez peut-être aussi