Sei sulla pagina 1di 4

Subject: DSIP Class: BE COMPS A.Y.

2019-20

EXPERIMENT 6

Problem Statement: To implement Image negative, contrast stretching and thresholding.

Theory:
POINT OPERATIONS:
Point operations translate gray scale values on a pixel-by-pixel basis from one image to another. The
goal of histogram equalization is to find and apply a point operation such that the histogram of the
modified image approximates a uniform distribution. Histogram is a discrete distribution &
homogeneous point operations can only shift & merge(but never split) histogram entries, we only
obtain approximate solution in general.

Zero memory operations where a given gray


level u ∈ [0, L] is mapped into a gray level v ∈ [0, L] according to
a transformation
v = f(u)
Input and output gray levels are distributed between [0, L].
Typically, L = 255

Image Negative:
The negative of an image with grey levels in the range [0, L-1] is obtained by the negative
transformation shown in figure above, which is given by the expression as s = L – 1 – r. This
expression results in reversing of the gray level intensities of the image thereby producing a negative
like image. In negative transformation, each value of the input image is subtracted from the L-1 and
mapped onto the output image. This is particularly useful for enhancing white or gray details
embedded in dark regions of an image.

Contrast Stretching: Often called as Normalisation is a simple image enhancement technique that
attempts to improve the contrast in an image by `stretching' the range of intensity values it contains
to span a desired range of values, e.g. the the full range of pixel values that the image type concerned
allows

Thresholding:
Thresholding is the special case of clipping where output becomes binary.

Image Procesing (BE COMPS)


Code:

Image Procesing (BE COMPS)


PROGRAM : (CONTRAST STRETCHING)
#include <iostream>
#include <opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
int computeOutput(int , int , int , int ,int);
int main()
{
Mat image = imread("image.jpeg");
Mat new_image = image.clone();
int r1,s1,r2,s2;
cout<<"Enter r1 : "<<endl;cin>>r1;
cout<<"Enter s1 : "<<endl;cin>>s1;
cout<<"Enter r2 : "<<endl;cin>>r2;
cout<<"Enter s2 : "<<endl;cin>>s2;
for(int y=0;y<image.rows;y++)
{
for(int x=0;x<image.cols;x++)
{
for(int c=0;c<3;c++)
{
int output = computeOutput(imageat<Vec3b>(y,x)[c],r1,s1.r2,s2);
new_image.at<Vec3b>(y,c)[c] = saturate_ucast<uchar>(output);
}
}
}
namedWindow("Original Image",1);
imshow("Original Image",image);
namedWindow("Modified Image",1);
imshow("Modified Image",new_image);
waitKey();
return 0;
}
int computeOutput(int x, int r1 , int s1 , int r2 ,int s2){
float result;
if(0<=x&& x<=r1)
{
result = s1/r1*x;
}
elseif(r1<x & x<=r2)
{
result=((s2-s1)/(r2-r1)*(x-r1)+s1;
}
elseif(r2<x && x<=255)
{
result = ((255-s2)/(255-r2))*x-r2+s2;
}
return (int)result;

Image Procesing (BE COMPS)


}
Note: Write your own code Digital Negative and Contrast Stretching

Conclusion: Single-point processing is a simple method of image enhancement. This technique


determines a pixel value in the enhanced image dependent only on the value of the corresponding
pixel in the input image.

Image Procesing (BE COMPS)

Potrebbero piacerti anche