Thursday, 7 July 2022

GIMP Image Editor

GIMP Image Editor:     How to edit images into PGM ?

  • GIMP: GNU Image Manipulation Program.
  • GIMP Image Editor is a Free and Open Source Image Editor. click here to download and install.
  • It is used for converting images into a PGM Extension.
        Different Type of Image Extension:  

             JPEG ->  Joint Photographic Experts Group
             PNG ->   Portable Network Graphics
            XCF ->   eXperimental Computing Facility
             PGM ->  Portable Gray Map

PGM: Portable Gray Map:   

-> In image processing technique, we have to take input as an image. So, the most efficient extension for input image is the ".PGM" extension image.  

-> The ".pgm" extensible Images are editable in a text editor. 

-> The ".xcf, .png, .jpeg" extensible images are not editable in a text editor.

-> ASCII: American Standard Code for Information Interchange.  

 
Process of Converting Images into a PGM Image:


->  Download the GIMP File -> Install.

-> Download image  ->  Save Download Image  ->  "Right Click" on saving image  ->  go to "Open with" and  ->  click on "GIMP Image Editor"  ->  Go to the "file" in open image ->  Click on "save as..."  ->  Go to top and Change the Name: of the file extension into "pgm"  ->  Go to right bottom corner, click "Save"  ->  Click "Take me to the Export dialog"  ->  Go to Right bottom corner and click "Export"  ->  Choose "ASCII"  ->  Export.

Tuesday, 5 July 2022

Image Processing using C-Programming

Image

  • An image is a two-dimensional (2-D) array of pixels.
  • There are mainly two types of Image.
  1. R-G-B Channel Image: The R-G-B Images are formed by three primary channel called a color image. Red, Green and Blue are three channels in a color image.
  2. Single Channel Image: Monochrome Image that has pixel's intensity ranging from 0 to 255 is called Single Channel Image. 

Example:


Monochrome Image
Figure 1. A Monochrome Image












Image Contrast Stretching using C-Programming.


Contrast Stretching in Image Processing:

  • It is an image processing technique for low-contrast images.
  • The low-contrast images can result from poor illumination and wrong setting of a lens aperture during image acquisition.
  • Contrast stretching is a process that expands the range of intensity levels in an image.





#include<stdio.h>
#include<stdlib.h>
#include<math.h>
void main()
{
int i,j,row,col,max,pix,v=0,max1=0,min=1000;
char c[10],a[100];
FILE *p,*q;
p=fopen("cot.pgm","r");
fscanf(p,"%s\n", c);
fscanf(p,"%[^\n]\n", a);
fscanf(p,"%d %d\n", &col ,&row);
fscanf(p,"%d\n",&max);
int m[row][col],m1[row][col],m2[256];
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
fscanf(p,"%d\n",&pix);
m[i][j]=pix;
if(max1<pix)
max1=pix;
if(min>pix)
min=pix;


}
}printf("%d %d\n", max1,min);

for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
m[i][j]=((255*(m[i][j]-min)/(max1-min)));
}
}

q=fopen("d31.pgm","w");
fprintf(q,"%s\n",c);
fprintf(q,"%s\n",a);
fprintf(q,"%d %d\n", col, row);
fprintf(q,"%d\n",max);
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
pix=m[i][j];
fprintf(q,"%d\n",pix);
}
}

fclose(p);
fclose(q);



Monday, 4 July 2022

Generic Pointer in C

Void Pointer or Generic Pointer (void *) in C


Pointers: 


-> A pointer is a derived data type in C-Programming.
-> It builds from one of the fundamental data types (int, float, char, and double).
-> The declaration of a pointer variable is as follows: data_type *pointer_name

Example 1:      int *P;
                         float *x;

-> Ampersand Symbol ( & ) in C-Programming represents the "address of" operator.    

Example 2:      int quantity;
                        int *P; 
                        P = &quantity;     

-> In this syntax, integer, pointer variable 'P' store the address of an integer variable quantity

Example 3:        float rate;
                           int *P;
                           P = &rate

-> The syntax given in Example 3 is wrong. Since, Compatibility and Casting problems.
-> Therefore, we cannot assign the address of floating variable rate into the integer pointer variable P.
-> The problem of Compatibility and Casting, can be solved by using Generic Pointer.

The Generic Pointer:

-> The void pointer is a generic pointer that can represent any pointer type.
-> All pointer types can be assigned to a void pointer and a void pointer can be assigned to any pointer without casting. 

Example 4:            void *vp;    (generic pointer)
                               float rate;
                               vp = &rate;

-> A pointer variable 'vp' with type void is called generic pointer.
-> The syntax in Example 4, resolve the problem of Compatibility and Casting and void pointer vp store the address of floating point variable rate.


Q.1. Why we use a generic pointer in C-Programming ?

Friday, 1 July 2022

Complexity of Infinite Loop

Infinite Loop in C                           

"Infinite Loop in C-code means the loop does not terminate."


Example 1.

C-programing in Linux platform:

1. Open a text-editor -> Write C-code -> Press (ctrl+shift+s) -> type filename.c -> Click on save .
2. Open command prompt (a) For compilation: Type gcc filename.c (b) For execution: Type ./a.out

There are mainly four types of infinite loop in C-programming.

(i) By calling the main function into the main().
(ii) By using for-loop.
(iii) By using while-loop.
(iv) By using do-while-loop.   

# include<stdio.h>
void main ()
{
printf ("hello");
main();
}

The output of this C-programming: hellohellohello--------------till interrupt (ctrl+z). 

#include<stdio.h>
int main()
{
for(;;)
{
printf("hello \n");
}
return(0);
}


#include<stdio.h>
int main()
{
while(1)
{
printf("hello\n");
}
return(0);
}

#include<stdio.h>
int main()
{
do
{
printf("hello\n");
}
while(1);
return(0);
}

If the return type of main() function is an integer then we must include a return(0) function in our code.  

On Windows Platforms (Turbo C++):

Example 2.

#include<stdio.h>
#include<conio.h>
void main ()
{
for (;;)
{
printf ("hello");
}
clrscr ();
getch ();
}

In "Turbo c++" compiler, we must include getch() and clrscr() function for displaying the output on clear screen.
 

PRINCIPAL COMPONENT ANALYSIS (PCA)

(PCA) : - Dimension reduction analysis -> It is a technique for feature extraction from a given data set. -> There are N -number...