import numpy as np
import boto3
import cv2
s3 = boto3.client("s3")
bucket_name = "bucket_name"
# fetching object from bucket
file_obj = s3.get_object(Bucket=bucket_name, Key='path/to/image' )
# reading the file content in bytes
file_content = file_obj["Body"].read()
# creating 1D array from bytes data range between[0,255]
np_array = np.frombuffer(file_content, np.uint8)
# decoding array
image_np = cv2.imdecode(np_array, cv2.IMREAD_COLOR)
gray = cv2.cvtColor(image_np, cv2.COLOR_BGR2GRAY)
# now you can save the read image from s3 to local machine if you want or you can use the image contents from gray or from image_np
cv2.imwrite(r"path/to/new_image", gray)