python – How to extract the fixed size ROI for multiple images?

python – How to extract the fixed size ROI for multiple images?

Make the following changes where you are calling the crop_brain_contour function:

desired_width, desired_height = (100, 100)
final_img = np.zeros((desired_height, desired_width, 3), dtype=uint8)
img_crop = crop_brain_contour(cv_img)
h,w = img_crop.shape[:2]
#Make sure h < desired_height and w < desired_width
x1 = int(desired_width/2 - w/2)
y1 = int(desired_height/2 - h/2)
x2 = x1 + w
y2 = y1 + h

final_img[y1:y2, x1:x2, :] = img_crop

# Write the final image
cv2.imwrite(./extracted_data_1/image%04i.bmp %i,final_img)

python – How to extract the fixed size ROI for multiple images?

Leave a Reply

Your email address will not be published.