Fahad Khan
Fahad Khan

Reputation: 21

image Log transformation in python open cv

I am learning image processing and I've come across image log processing. I have googled about it, watched youtube videos but I am unable to correctly code it.

I am using following code:

img = cv2.imread('spectrum.jpg')
img00=np.uint8(np.log1p(img))

_, img3 = cv2.threshold(img00, 55, 255, cv2.THRESH_BINARY)
cv2.imshow('log',img3)
cv2.waitKey(0)
cv2.destroyAllWindows()

Upvotes: 1

Views: 5777

Answers (1)

Jeru Luke
Jeru Luke

Reputation: 21203

You are on the right track. After obtaining the log transform of the image, you are supposed to normalize the pixels values.

The pixel values on a log transformed image do not range between 0 - 255 (as one expects). In order to apply a threshold, the image needs to be normalized which can be done as follows:

normalized_image = cv2.normalize(img00, None, 0, 255, cv2.NORM_MINMAX, dtype = cv2.CV_8U)

Now apply the threshold on the normalized_image.

Upvotes: 1

Related Questions