Image:
- An image is a two-dimensional (2-D) array of pixels.
- There are mainly two types of Image.
- 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.
- Single Channel Image: Monochrome Image that has pixel's intensity ranging from 0 to 255 is called Single Channel Image.
Example:
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);
}