Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix logging info and offset error. #3

Merged
merged 2 commits into from
Feb 3, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions SRRestorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def upsample(arr, n):
return arr.reshape((1,-1))[0]


def SRRestore(camera, high_res, images, upscale, iter):
def SRRestore(camera, high_res, images, upscale, iter):
error = 0
captured_images = images

Expand All @@ -40,12 +40,12 @@ def SRRestore(camera, high_res, images, upscale, iter):

# for every LR with known pixel-offset
for (offset, captured) in captured_images:

(dx,dy) = offset

# make LR of HR given current pixel-offset
simulated = camera.take_a_photo(high_res, offset, 1.0/upscale)

# convert captured and simulated to numpy arrays (mind the data type!)
cap_arr = numpy.asarray(captured).astype(numpy.float32)
sim_arr = numpy.asarray(simulated).astype(numpy.float32)
Expand All @@ -72,7 +72,7 @@ def SRRestore(camera, high_res, images, upscale, iter):
delta_hr_R = camera.doOffset(delta_hr_R, (-dx,-dy))
delta_hr_G = camera.doOffset(delta_hr_G, (-dx,-dy))
delta_hr_B = camera.doOffset(delta_hr_B, (-dx,-dy))

# Blur the (upsampled) delta with PSF
delta_hr_R = camera.Convolve(delta_hr_R)
delta_hr_G = camera.Convolve(delta_hr_G)
Expand Down Expand Up @@ -101,19 +101,20 @@ def stub():
scale = config['scale']

input_images = []

camera = Camera.Camera(config['psf'])

for (dx, dy) in config['offsets_of_captured_imgs']:
fname = ('%s/S_%d_%d.tif' % (config['samples_folder'], dx, dy))
print "opening %s..." % fname
image = Image.open(fname)
input_images.append(((dx, dy), image))

# start value = sum(upsampled + shifted LR)
high_res_size = [int(input_images[0][1].size[1] * scale), int(input_images[0][1].size[0] * scale), 3]
high_res_image = numpy.zeros(high_res_size).astype(numpy.float32)
for (offset, LR_img) in input_images:
dx, dy = offset
HR_arr = numpy.asarray(LR_img.resize((high_res_size[1],high_res_size[0]), Image.ANTIALIAS))
high_res_image += numpy.dstack((camera.doOffset(HR_arr[:,:,0],(-dx,-dy)),
camera.doOffset(HR_arr[:,:,1],(-dx,-dy)),
Expand All @@ -131,5 +132,5 @@ def stub():
high_res_image.save('%s/Reconstructed.png' % (config['output_folder']))


if __name__=="__main__":
if __name__=="__main__":
stub()
8 changes: 4 additions & 4 deletions myconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
'psf1': [0.5, 1.0, 0.5,
1.0, 3.0, 1.0,
0.5, 1.0, 0.5],

# this PSF is a 5x5 Gaussian
'psf': [ 2.66971863e-03, 5.36227322e-02, 1.45761699e-01, 5.36227322e-02, 2.66971863e-03,
5.36227322e-02, 1.07704137e+00, 2.92770198e+00, 1.07704137e+00, 5.36227322e-02,
1.45761699e-01, 2.92770198e+00, 7.95831909e+00, 2.92770198e+00, 1.45761699e-01,
5.36227322e-02, 1.07704137e+00, 2.92770198e+00, 1.07704137e+00, 5.36227322e-02,
2.66971863e-03, 5.36227322e-02, 1.45761699e-01, 5.36227322e-02, 2.66971863e-03 ],


'offsets_of_captured_imgs' : [[0,0], [1,0], [2,0],
[0,1], [1,1], [2,1],
[0,2], [1,2], [2,2]],

'scale' : 2,
'iterations' : 10,
'samples_folder' : './inputs/',
'output_folder' : './output/'
'samples_folder' : './inputs',
'output_folder' : './output'
}