0

I am writing a code to rotate all the images in a dataset and saving the rotated images in the same folder of the dataset. But after saving most of the saved images are black. Why this problem is occurring and how to fix it? Here is the code I wrote.

path = r'Enhanced/train/NORMAL'
import os
import cv2 as cv
from skimage import transform

for dirName, subdirList, fileList, in os.walk(path):
   for file in fileList:
       full_file_path = os.path.join(dirName, file)

       if file.endswith(".png"):
            image = cv.imread(full_file_path, cv.IMREAD_GRAYSCALE)

            # image rotation
            transformed_image = transform.rotate(image, angle=45)

       new_filename = file.split('.jpg')[0] +'rotation45.png'
       path2 = r"Enhanced/train/NORMAL"

       cv.imshow(new_filename, transformed_image)
       cv.waitKey(1)
       cv.imwrite(os.path.join(path2, new_filename), transformed_image)
       cv.destroyAllWindows()
  • See this https://stackoverflow.com/a/51389714/18667225 and that https://stackoverflow.com/a/18683594/18667225 ! Also please be aware that in your code above the `transformed_image` is only set in the if-block while it is used outside. – Markus Jun 01 '22 at 16:53
  • Can you share an image where it fails? – Jeru Luke Jun 10 '22 at 20:17

0 Answers0