diff --git a/Python/OpenCV/Flipping.py b/Python/OpenCV/Flipping.py new file mode 100644 index 0000000..320af70 --- /dev/null +++ b/Python/OpenCV/Flipping.py @@ -0,0 +1,45 @@ +# Flipping Images - Horizontally, Vertically, Horizontally & Vertically + +# Import Computer Vision package - cv2 +import cv2 + +# Read the image using imread built in function +image = cv2.imread('image_1.jpg') + +# Display original image using imshow built in function +cv2.imshow("Original-Press any Key to contd", image) + +# Wait until any key is pressed +cv2.waitKey(0) + +# cv2.flip is used to flip images +# Horizontal flipping of images using value '1' +flipping = cv2.flip(image, 1) + +# Display horizontally flipped image +cv2.imshow("Horizontal Flipping", flipping) + +# Wait until any key is pressed +cv2.waitKey(0) + +# Vertical flipping of images using value '0' +flipping = cv2.flip(image, 0) + +# Display vertically flipped image +cv2.imshow("Vertical Flipping", flipping) + +# Wait until any key is pressed +cv2.waitKey(0) + +# Horizontal & Vertical flipping of images using value '-1' +flipping = cv2.flip(image, -1) + +# Display horizontally & vertically flipped image +cv2.imshow("Horizontal & Vertical Flipping", flipping) + +# Wait until any key is pressed +cv2.waitKey(0) + +# Close all windows +cv2.destroyAllWindows() + diff --git a/Python/OpenCV/Scaling.py b/Python/OpenCV/Scaling.py new file mode 100644 index 0000000..53fa0a7 --- /dev/null +++ b/Python/OpenCV/Scaling.py @@ -0,0 +1,49 @@ +# Scaling (Resizing) Images - Cubic, Area, Linear Interpolations +# Interpolation is a method of estimating values between known data points + +# Import Computer Vision package - cv2 +import cv2 + +# Import Numerical Python package - numpy as np +import numpy as np + +# Read the image using imread built-in function +image = cv2.imread('image_2.jpg') + +# Display original image using imshow built-in function +cv2.imshow("Original", image) + +# Wait until any key is pressed +cv2.waitKey() + +# cv2.resize(image, output image size, x scale, y scale, interpolation) + +# Scaling using cubic interpolation +scaling_cubic = cv2.resize(image, None, fx=.75, fy=.75, interpolation = cv2.INTER_CUBIC) + +# Display cubic interpolated image +cv2.imshow('Cubic Interpolated', scaling_cubic) + +# Wait until any key is pressed +cv2.waitKey() + +# Scaling using area interpolation +scaling_skewed = cv2.resize(image, (600, 300), interpolation = cv2.INTER_AREA) + +# Display area interpolated image +cv2.imshow('Area Interpolated', scaling_skewed) + +# Wait until any key is pressed +cv2.waitKey() + +# Scaling using linear interpolation +scaling_linear = cv2.resize(image, None, fx=0.5, fy=0.5, interpolation = cv2.INTER_LINEAR) + +# Display linear interpolated image +cv2.imshow('Linear Interpolated', scaling_linear) + +# Wait until any key is pressed +cv2.waitKey() + +# Close all windows +cv2.destroyAllWindows() diff --git a/Python/OpenCV/Varying_Brightness.py b/Python/OpenCV/Varying_Brightness.py new file mode 100644 index 0000000..5296715 --- /dev/null +++ b/Python/OpenCV/Varying_Brightness.py @@ -0,0 +1,45 @@ +# Varying Brightness of Images using Add and Subtract Operations + +# Import Computer Vision package - cv2 +import cv2 + +# Import Numerical Python package - numpy as np +import numpy as np + +# Read the image using imread built-in function +image = cv2.imread('image_2.jpg') + +# Display original image using imshow built-in function +cv2.imshow("Original", image) + +# Wait until any key is pressed +cv2.waitKey(0) + +# np.ones returns an array of given shape and type, filled with ones +# np.ones(shape, dtype) + +matrix = np.ones(image.shape, dtype = "uint8") * 120 +# image.shape: gives takes the shape of original image +# uint8: unsigned integer (0 to 255) +# matrix: contains ones, having same dimension as original image but mutlipied by 120 + +# Adding matrix to orginal image, increases brightness +add = cv2.add(image, matrix) + +# Display added image +cv2.imshow("Added", add) + +# Wait until any key is pressed +cv2.waitKey(0) + +# Subtracting matrix and original image, decreases brightness +subtract = cv2.subtract(image, matrix) + +# Display subtracted image +cv2.imshow("Subtracted", subtract) + +# Wait untill any key is pressed +cv2.waitKey(0) + +# Close all windows +cv2.destroyAllWindows() diff --git a/Python/OpenCV/image_1.jpg b/Python/OpenCV/image_1.jpg new file mode 100644 index 0000000..6acd617 Binary files /dev/null and b/Python/OpenCV/image_1.jpg differ diff --git a/Python/OpenCV/image_2.jpg b/Python/OpenCV/image_2.jpg new file mode 100644 index 0000000..d018cf4 Binary files /dev/null and b/Python/OpenCV/image_2.jpg differ