Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

EXPERIMENT NO.

Aim : to write and execute omage processing using point processing methods
 Obtain Negative image
 Obtain Flip image
 Thershold operation (Thersholding)
 Contrast stretching

Introduction :
Image enhancement can be done in two domain:

[1] Spatial Domain and

[2] Transform domain.

In Spatial domain Image processing, there are two ways :

 Point processing (Single pixel is processed at a time)


 Neighborhood processing (Mask processing) Convolution of 3x3 or 5x5 or other size of
mask with image

In point processing, Gray level transformation can be given by following equation

 g(x,y)=T[f(x,y)]  s=T(r)

where, f(x,y) is original image, g(x,y) is transgormed imafe


s = gray level of transformed image
r = gray level of original image
Thershold operation :

Open cv program for image thersholding

import cv2 as cv
import numpy as np
img = cv.imread(‘gradient.png’,0)
th1 = cv.thershold(img,127,255,cv.THRESH_BINARY)
cv.imshow(“Image”,img)
cv.imshow(‘th1’,th1)
cv.waitkey(0)
cv.destroyAllwindows()

Run above program for different threshold values and find out optimum threshold value for
which you are getting better result.

Horizontal flipping :
import cv2
  
originalImage = cv2.imread('C:/Users/Ravi/Desktop/Test.jpg')
  
flipHorizontal = cv2.flip(originalImage, 1)
 
cv2.imshow('Original image', originalImage)
cv2.imshow('Flipped horizontal image', flipHorizontal)
 
 
cv2.waitKey(0)
cv2.destroyAllWindows()

Negative Image :
Negative Image can be obtained by substracting each pixel value from 255.

Opencv python program for Negative Image :


import cv2
 
img = cv2.imread("photo.jpg")
img_2 = 255 – img
cv2.imshow("original pic",img)
cv2.imshow("negative of pic",img_2)
cv2.waitkey(10000)
cv2.destroyAllWindows()

Contrast Stretching :
Contrast Stretching means Darkening level below threshold value m and whitening level above threshold
value m. This technique will enhance contrast of given image. Thersholding is example of extreme
contrast stretching.
Opencv program for contrast stretching:
import cv2
import numpy as np

img = cv2.imread('PHOTO.jpg')
original = img.copy()
xp = [0, 64, 128, 192, 255]
fp = [0, 16, 128, 240, 255]
x = np.arange(256)
table = np.interp(x, xp, fp).astype('uint8')
img = cv2.LUT(img, table)
cv2.imshow("original", original)
cv2.imshow("Output", img)
cv2.waitKey(0)
cv2.destroyAllWindows()

You might also like