# crop part of image from image, change it and put it same place in original image

I have image (think of image of small plant) with bounding box. For data augmentation I want to rotate (45 degrees) the image (plant) in bounding box, and place it at same place in original image. so that I don't have to annotate again in image. Only difference is that image(plant) in box is rotated by 45 degrees. I am using cv2 and pil. I have below code writtend and got help up after that. Looking for inputs. Thanks for your time.

demo_test_img = 'repa_trn_23_4598958_2920949_png.rf.996ba731acd8b0d4b75c57acf85cc91b.jpg'
demo_test_img_path = os.path.join(f'{DIR_TRAIN}',demo_test_img)

# colors for boxes.
colour_dict = {1:(220, 0, 0), 2:(0, 0, 220)}

# get number of boxes present in image.
demo_img_boxes_info = train_df[train_df["image_id"] == demo_test_img]
print('Number of boxes for demo image ', len(demo_img_boxes_info))

for index, row in demo_img_boxes_info.iterrows():
if (row['class'] == 1 or row['class'] == 2):

H = int(row['h'])
W = int(row['w'])
X = int(row['x'])
Y = int(row['y'])
print('Box for  idx is ', index, 'is ',[X,Y,W,H])

**# TODO: rotate cropped image and place it at same location of original demo test image.**

fig, ax = plt.subplots(1, 1, figsize=(16, 8))

• I believe you are solving the incorrect task. The question should be - Find the bounding rectangle coordinate after rotation. Check Here May 16, 2021 at 15:54
• @10xAI I want to rotate only images present in bounding boxes. Thanks May 17, 2021 at 4:16
• @10xAI I want to rotate only images present in bounding boxes and place it on original image with out change in bounding box. after giving a taught i think if we rotate the image in box the bounding box is going to change. As you mentioned the task i am trying to achieve is not correct. Is my understanding correct. Thanks May 17, 2021 at 4:41