Home > OS >  How can I use thresholding to improve image quality after rotating an image with skimage.transform?
How can I use thresholding to improve image quality after rotating an image with skimage.transform?

Time:12-02

I have the following image:

enter image description here

import cv2
import numpy as np
import skimage.exposure

# load image
img = cv2.imread('122.png')

# convert to gray
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# blur threshold image
blur = cv2.GaussianBlur(gray, (0,0), sigmaX=2, sigmaY=2, borderType = cv2.BORDER_DEFAULT)

# stretch so that 255 -> 255 and 127.5 -> 0
result = skimage.exposure.rescale_intensity(blur, in_range=(127.5,255), out_range=(0,255)).astype(np.uint8)

# save output
cv2.imwrite('122_antialiased.png', result)

# Display various images to see the steps
cv2.imshow('result', result)

cv2.waitKey(0)
cv2.destroyAllWindows()

Result:

enter image description here

  • Related