-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_cut.py
More file actions
31 lines (23 loc) · 910 Bytes
/
image_cut.py
File metadata and controls
31 lines (23 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import cv2
def crop_image(input_file, output_file):
try:
# Read the image
img = cv2.imread(input_file)
# Check if image is loaded properly
if img is None:
print("Error in loading the image. Please ensure the file exists and is a valid image.")
return
# Crop the image
# Note: OpenCV handles images in [y:y+h, x:x+w] format
cropped_img = img[90:220, 500:600]
# cropped_img = img[90:1000, 380:700]
# Save the cropped image
cv2.imwrite(output_file, cropped_img)
print(f"Cropped image saved as {output_file}")
except Exception as e:
print(f"An error occurred: {e}")
# Replace 'input.png' with your input file name
input_file = r'mesh_psnr\basketball\downsample_100x_with_light.png'
# Specify the name for the cropped output file
output_file = r'mesh_psnr\basketball\downsample_100x_with_light_cut.png'
crop_image(input_file, output_file)