Professional Documents
Culture Documents
Experiment 2
Experiment 2
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:
g(x,y)=T[f(x,y)] s=T(r)
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.
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()