-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexp_transform.py
More file actions
28 lines (25 loc) · 849 Bytes
/
exp_transform.py
File metadata and controls
28 lines (25 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""
Applies exponential transformation on an image. Takes image, levels and c as parameters.
Returns the new image
"""
import numpy as np
import imutil
def exp_transform(im, levels, c, a):
#create output image
im_out = np.zeros((im.shape[0],im.shape[1],3), dtype=np.uint8)
#if image is gray
if imutil.is_gray(im):
im_out = np.zeros((im.shape[0],im.shape[1]), dtype=np.uint8)
im = imutil.correct_gray(im)
im_out = im/(levels-1)
im_out = c*((1 + a)**im_out - 1)
im_out = (im_out / im_out.max()) * (levels-1)
#if image is color
else:
im_out = imutil.rgb2ycbcr(im)
dMat = im_out[:, :, 0]
dMat = dMat/(levels-1)
dMat = c*((1 + a)**dMat - 1)
im_out[:, :, 0] = dMat / dMat.max() * (levels-1)
im_out = imutil.ycbcr2rgb(im_out)
return np.uint8(im_out)