Upload
karthikarajaratna
View
218
Download
0
Embed Size (px)
Citation preview
8/10/2019 Digital Image Processing C Basics
1/7
1 JPS [email protected]
DIGITAL IMAGE PROCESSINGUSING C
INTRODUCTION
If you are already an expert programmer of C and you are merely
looking for some ideas or codes on how to process images then this is
the right tutorial for you. If you are a beginner in C programming then
you are recommended to more detailed tutorials or books. Nevertheless,
we begin with some of the basics of C in this chapter.
In the entire tutorial including all chapters we will be using Microsoft
Visual Studio 2010. Interestingly, C coding in MS Visual Studio is not sostraight forward as the way it used to be in MS Visual Studio 2006.
Therefore our first task would be to familiarize oneself with Microsoft
Visual Studio 2010 and to learn the way to code, debug, compile and
execute C programs.
CODING IN MICROSOFT VISUAL STUDIO 2010
Follow the steps below:
1. Install and open Microsoft Visual Studio 2010
2. Create a new project by clicking File > New > Project
3. Select languageVisual C++
4. Within Visual C++ select tabWin32
5. Select project typeWin32 Console Application
6. EnterProject Name
7. SelectNext from dialog box
8. Select Console applicationon applications settings window
9. Uncheck Precompiled headeron applications settings window
10.Your C project is ready for coding
11. To start coding right click on the Source Files and add a new
item
12. SelectC++ file to add, enter name of program withextension.C13. Open your program and start coding
14. To compile and execute press F5
For illustration of steps see figures below.
CONTENTS
C-coding in MS VisualStudio 2010
Calculate the area oftriangle
Solve the quadraticequation
Calculate factorial of anumber
Accept characters andterminate program
Output arrays and pointervalues
Input values from externaltext file
Dynamic memoryallocation for calculations
CHAPTER -1: BASICS OF C-LANGUAGE
8/10/2019 Digital Image Processing C Basics
2/7
8/10/2019 Digital Image Processing C Basics
3/7
8/10/2019 Digital Image Processing C Basics
4/7
8/10/2019 Digital Image Processing C Basics
5/7
5 JPS [email protected]
EXAMPLE PROGRAMS
Following are some of the examples of C programs for practice. Only the source code is provided for each of the
problems. For detailed discussion or analysis contact [email protected].
Program to calculate factorial
#includeint factor(int n);
main()
{while(1)
{int n,factorial;printf("please enter the value for calculating factorial\n");scanf("%d",&n);factorial=factor(n);printf("factorial of %d = %d\n",n,factorial);}
}
int factor(int n){
int i,factor=1;for(i=1;i
8/10/2019 Digital Image Processing C Basics
6/7
8/10/2019 Digital Image Processing C Basics
7/7
7 JPS [email protected]
printf("%d\t%d\t%d\t%d\t%d\t%d\n",arr[i],p1[i],*(p1+i),*p2,p2);p2++;
}}
Program to accept data from text file and to allocate and use dynamic memory
#include#include
#include
double input(double *data, int n);double std_dev(double *data, int n);
main(){
int n;double stand_dev;double *prt;printf("enter no of elements\n");scanf("%d",&n);prt=malloc(sizeof(double)*n);
if(prt==NULL)
printf("not enough memory\n");
input(prt,n);stand_dev=std_dev(prt,n);printf("standard deviation=%lf\n\n",stand_dev);
free(prt);}
double input(double *data, int n){
int i;printf("enter the values\n");for(i=0;i