a. Obtain Negative image Program:
import cv2
img = cv2.imread("C:/Users/welcome/Desktop/sem6/DIP/Nature.png")
cv2.imshow("Original_image", img)
img1=255-img
cv2.imshow("Negative_image", img1)
cv2.waitKey(0)
cv2.destroyAllWindows()
b.Obtain Flip image
Program:
import cv2
img = cv2.imread("C:/Users/welcome/Desktop/sem6/DIP/Nature.png")
horizontal_flip = cv2.flip(img, 1)
vertical_flip = cv2.flip(img, 0)
both_flip = cv2.flip(img, -1)
cv2.imshow("Original_image", img)
cv2.imshow("horizontal_flip_image", horizontal_flip)
cv2.imshow("vertical_flip_image", vertical_flip)
cv2.imshow("both_flip_image", both_flip)
cv2.waitKey(0)
cv2.destroyAllWindows()
c. Thresholding
Program:
import cv2
img = cv2.imread("C:/Users/welcome/Desktop/sem6/DIP/Nature.png",
cv2.IMREAD_GRAYSCALE)
adaptive_thresh = cv2.adaptiveThreshold(
img, 255,
cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
cv2.THRESH_BINARY,
11, 2
)
cv2.imshow("Original_image", img)
cv2.imshow("Adaptive Thresholding", adaptive_thresh)
cv2.waitKey(0)
cv2.destroyAllWindows()
d.Contrast stretching
Program:
import numpy as np
import cv2
img = cv2.imread("C:/Users/welcome/Desktop/sem6/DIP/Nature.png")
min_val = np.min(img)
max_val = np.max(img)
stretched = ((img - min_val) * (255.0 / (max_val -
min_val))).astype(np.uint8)
cv2.imshow("Original_image", img)
cv2.imshow("contrast_stretched", stretched)
cv2.waitKey(0)
cv2.destroyAllWindows()
No comments:
Post a Comment