0

I have the task of generating data for deep learning. I take seed images, rotate them and plot them randomly on a background. The issue is the rotation results in a broken line boundary around the image and I can't figure out why it appears or how to get rid of it.

def rotateSeed(img):
rotated = imutils.rotate_bound(img, randint(0,360))
for row in range(rotated.shape[0]):
    for col in range(rotated.shape[1]):
        if (rotated[row,col,0] == 0) and (rotated[row,col,1] == 0) and (rotated[row,col,2] == 0):
            rotated[row,col] = default[0,0]
return rotated

Code explanation: default is the background color in the seed image. Rotation produces a black region I cover with the default.

Only one other person has had this problem and the solution does not explain much. It did not even rotate: OpenCV

Original seed image Rotated seed image

1 Answers1

0

You can use this code for rotation:

import cv2
import numpy as np

img = cv2.imread('C:\\Code\\1.jpeg')
num_rows, num_cols = img.shape[:2]

rotation_matrix = cv2.getRotationMatrix2D((num_cols/2, num_rows/2), 30, 1)
img_rotation = cv2.warpAffine(img, rotation_matrix, (num_cols, num_rows))
cv2.imshow('Rotation', img_rotation)
cv2.waitKey()
Andy_101
  • 1,246
  • 10
  • 20
  • Dear Andy_101, under the hood imutils uses these functions and the link you shared is precisely the one I followed because this approach directly cuts the seed in some rotations. It also did not solve the border issue as it is still there. :( – Muhammad Mubashirullah Durrani Oct 22 '19 at 09:19