Skip to content

Commit 160627f

Browse files
author
Cejo Konuparamban Lonappan
committed
Color channels upscaled by bicubic interpolation
For color images, we previously applied our RAISR algorithm only to the luminance channel, whereas in the Google's RAISR implementation and by others, the color channels are upsampled by bicubic interpolation. We can also use bicubic interpolation, but this will not affect our reported PSNR results as it is dependent on luminance only. Based on comments in issue 1, in this commit, we are switching to applying bicubic interpolation on the chromatic channels.
1 parent 9ab0549 commit 160627f

13 files changed

+9
-24
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Byte-compiled / optimized / DLL files
22
__pycache__/
3+
.idea/
34
*.py[cod]
45
*$py.class
56

Filter/Qfactor_coh2

-171 Bytes
Binary file not shown.

Filter/Qfactor_coh3

-171 Bytes
Binary file not shown.

Filter/Qfactor_coh4

-171 Bytes
Binary file not shown.

Filter/Qfactor_str2

-171 Bytes
Binary file not shown.

Filter/Qfactor_str3

-171 Bytes
Binary file not shown.

Filter/Qfactor_str4

-171 Bytes
Binary file not shown.

Filter/filter2

-817 KB
Binary file not shown.

Filter/filter3

-1.79 MB
Binary file not shown.

Filter/filter4

-3.19 MB
Binary file not shown.

Functions.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ def BGR2YCbCr(im):
2828
mat = np.array([[24.966, 128.553, 65.481],[112, -74.203, -37.797], [-18.214, -93.786, 112]])
2929
mat = mat.T
3030
offset = np.array([[[16, 128, 128]]])
31-
3231
if im.dtype == 'uint8':
3332
mat = mat/255
3433
out = np.dot(im,mat) + offset
@@ -48,7 +47,6 @@ def YCbCr2BGR(im):
4847
mat = mat.T
4948
mat = np.linalg.inv(mat)
5049
offset = np.array([[[16, 128, 128]]])
51-
5250
if im.dtype == 'uint8':
5351
mat = mat * 255
5452
out = np.dot((im - offset),mat)
@@ -64,12 +62,12 @@ def YCbCr2BGR(im):
6462
return out
6563

6664
def im2double(im):
67-
min_val = np.min(im.ravel())
68-
max_val = np.max(im.ravel())
6965
if im.dtype == 'uint8':
7066
out = im.astype('float') / 255
7167
elif im.dtype == 'uint16':
7268
out = im.astype('float') / 65535
69+
elif im.dtype == 'float':
70+
out = im
7371
else:
7472
assert False
7573
out = np.clip(out, 0, 1)
@@ -123,7 +121,6 @@ def is_greyimage(im):
123121

124122
@nb.jit(nopython=True, parallel=True)
125123
def Grad(patchX,patchY,weight):
126-
127124
gx = patchX.ravel()
128125
gy = patchY.ravel()
129126
G = np.vstack((gx,gy)).T
@@ -133,17 +130,13 @@ def Grad(patchX,patchY,weight):
133130
index= w.argsort()[::-1]
134131
w = w[index]
135132
v = v[:,index]
136-
137133
lamda = w[0]
138-
139134
u = (np.sqrt(w[0]) - np.sqrt(w[1]))/(np.sqrt(w[0]) + np.sqrt(w[1]) + 0.00000000000000001)
140-
141135
return lamda,u
142136

143137
@nb.jit(nopython=True, parallel=True)
144138
def HashTable(patchX,patchY,weight, Qangle,Qstrength,Qcoherence,stre,cohe):
145139
assert (len(stre)== Qstrength-1) and (len(cohe)==Qcoherence-1),"Quantization number should be equal"
146-
147140
gx = patchX.ravel()
148141
gy = patchY.ravel()
149142
G = np.vstack((gx,gy)).T
@@ -153,28 +146,20 @@ def HashTable(patchX,patchY,weight, Qangle,Qstrength,Qcoherence,stre,cohe):
153146
index= w.argsort()[::-1]
154147
w = w[index]
155148
v = v[:,index]
156-
157149
theta = atan2(v[1,0], v[0,0])
158150
if theta<0:
159151
theta = theta+pi
160152
theta = floor(theta/(pi/Qangle))
161-
162153
lamda = w[0]
163-
164154
u = (np.sqrt(w[0]) - np.sqrt(w[1]))/(np.sqrt(w[0]) + np.sqrt(w[1]) + 0.00000000000000001)
165-
166155
if isnan(u):
167156
u=1
168-
169157
if theta>Qangle-1:
170158
theta = Qangle-1
171159
if theta<0:
172160
theta = 0
173-
174161
lamda = np.searchsorted(stre,lamda)
175-
176162
u = np.searchsorted(cohe,u)
177-
178163
return theta,lamda,u
179164

180165
@nb.jit(nopython=True, parallel=True)
@@ -233,7 +218,6 @@ def Blending2(LR, HR):
233218
def Backprojection(LR, HR, maxIter):
234219
H, W = LR.shape
235220
H1, W1 = HR.shape
236-
237221
w = Gaussian2d((5,5), 10)
238222
w = w**2
239223
w = w/sum(np.ravel(w))
@@ -242,7 +226,6 @@ def Backprojection(LR, HR, maxIter):
242226
imd = LR - im_L
243227
im_d = imresize(imd, (H1, W1), interp='bicubic', mode='F')
244228
HR = HR + convolve2d(im_d, w, 'same')
245-
246229
return HR
247230

248231
def createFolder(directory):

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Google's RAISR implementation was trained on 10000 advertising banner images. Ou
6363
<p align="center">
6464
<img src="Comparison_result.png">
6565
</p>
66-
A high resolution image after downscaling it by 3 was used as the input low resolution image to both bicubic interpolation and our implementation of RAISR algorithm. A comparison of the resulted output image for this testcase with bicubic interpolation and our implementation of RAISR is shown in the figure above.
66+
A high resolution image after downscaling it by 2 was used as the input low resolution image to both bicubic interpolation and our implementation of RAISR algorithm. A comparison of the resulted output image for this testcase with bicubic interpolation and our implementation of RAISR is shown in the figure above.
6767

6868
## Citations
6969
Please cite the following publications if you plan to use the code or the results for your research:

Test.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@
5151
Qstrength = 3 # Quantization factor of strength =3
5252
Qcoherence = 3 # Quantization factor of coherence =3
5353

54-
with open("Filter/filter"+str(R), "rb") as fp:
54+
with open("Filters/filter"+str(R), "rb") as fp:
5555
h = pickle.load(fp)
5656

57-
with open("Filter/Qfactor_str"+str(R), "rb") as sp:
57+
with open("Filters/Qfactor_str"+str(R), "rb") as sp:
5858
stre = pickle.load(sp)
5959

60-
with open("Filter/Qfactor_coh"+str(R), "rb") as cp:
60+
with open("Filters/Qfactor_coh"+str(R), "rb") as cp:
6161
cohe = pickle.load(cp)
6262

6363
filelist = make_dataset(testPath)
@@ -168,8 +168,9 @@ def TestProcess(i):
168168

169169
if len(im_uint8.shape) > 2:
170170
result_ycbcr = np.zeros((H, W, 3))
171-
result_ycbcr[:, :, 1:3] = im_ycbcr[:, :, 1:3]
172171
result_ycbcr[:, :, 0] = im_blending * 255
172+
result_ycbcr[:, :, 1] = Prepare(im_ycbcr[:, :, 1], patchSize, R) * 255
173+
result_ycbcr[:, :, 2] = Prepare(im_ycbcr[:, :, 2], patchSize, R) * 255
173174
result_ycbcr = result_ycbcr[region].astype('uint8')
174175
result_RAISR = YCbCr2BGR(result_ycbcr)
175176
else:

0 commit comments

Comments
 (0)