PyImageSearch / imutils

A series of convenience functions to make basic image processing operations such as translation, rotation, resizing, skeletonization, and displaying Matplotlib images easier with OpenCV and Python.
MIT License
4.54k stars 1.03k forks source link

Background colour on rotate #188

Open pydemo opened 4 years ago

pydemo commented 4 years ago

can you add background colour var to your rotate method?

imutils.rotate(image, M, (w, h), borderValue=(255,255,255))
#//cv2.warpAffine(img, M, (cols, rows), borderValue=(255,255,255))
burhr2 commented 3 years ago

Hi! you can use scipy.ndimage library to get your desired output. Check out the documentation here. Let me show an example

from skimage import io
from scipy import ndimage

image = io.imread('https://www.pyimagesearch.com/wp-content/uploads/2019/12/tensorflow2_install_ubuntu_header.jpg')
io.imshow(image)
plt.show()

image

rotated = ndimage.rotate(image, angle=234, mode='nearest')
rotated = cv2.resize(rotated, (image.shape[:2]))
# rotated = cv2.cvtColor(rotated, cv2.COLOR_BGR2RGB) # if you wish to save it using opencv
io.imshow(rotated)
plt.show()

image

Note: For Scipy you may encounter an error if not properly imported kindly check here