Code
opencv
import cv2
img = cv2.imread("input.jpg")
h, w = img.shape[:2]
# Resize to fixed size
fixed = cv2.resize(img, (300, 200))
# Resize by scale factor, preserving aspect
scaled = cv2.resize(img, None, fx=0.5, fy=0.5,
interpolation=cv2.INTER_AREA)
# Crop a region of interest (y, x ordering)
roi = img[100:400, 200:600]
# Resize to a target width keeping aspect ratio
target_w = 400
ratio = target_w / w
new_size = (target_w, int(h * ratio))
resized = cv2.resize(img, new_size, interpolation=cv2.INTER_LINEAR)
cv2.imwrite("roi.jpg", roi)