How to do it...

  1. Create a new Python file and import the following packages:
# 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 
  1. Read the image using the built-in imread function:
image = cv2.imread('image_3.jpg') 
  1. Display the original image using the built-in imshow function:
cv2.imshow("Original", image) 
  1. Wait until any key is pressed:
cv2.waitKey() 
  1. Adjust the image size based on the operator's command:
# cv2.resize(image, output image size, x scale, y scale, interpolation) 
  1. Adjust the image size using cubic interpolation:
# Scaling using cubic interpolation 
scaling_cubic = cv2.resize(image, None, fx=.75, fy=.75, interpolation = cv2.INTER_CUBIC) 
  1. Show the output image:
# Display cubic interpolated image 
cv2.imshow('Cubic Interpolated', scaling_cubic) 
  1. Wait until any key is pressed:
cv2.waitKey()
  1. Adjust the image size using area interpolation:
# Scaling using area interpolation 
scaling_skewed = cv2.resize(image, (600, 300), interpolation = cv2.INTER_AREA) 
  1. Show the output image:
# Display area interpolated image 
cv2.imshow('Area Interpolated', scaling_skewed)  
  1. Wait for the instruction from the operator:
# Wait until any key is pressed 
cv2.waitKey() 
  1. Adjust the image size using linear interpolation:
# Scaling using linear interpolation 
scaling_linear  = cv2.resize(image, None, fx=0.5, fy=0.5, interpolation = cv2.INTER_LINEAR) 
  1. Show the output image:
# Display linear interpolated image 
cv2.imshow('Linear Interpolated', scaling_linear)  
  1. Wait until any key is pressed:
cv2.waitKey() 
  1. After completing the image scaling task, terminate the program execution:
# Close all windows 
cv2.destroyAllWindows() 
  1. The command used to execute the Scaling.py Python program is shown here:
  1. The original image used for scaling is shown here:
  1. Linear interpolated output obtained after executing the Scaling.py file is shown here:
  1. The area-interpolated output obtained after executing the Scaling.py file is shown here:
  1. The cubic-interpolated output obtained after executing the Scaling.py file is shown here:
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.103.202