Skip to content

Commit

Permalink
downsizing of interpolated picture to normal size
Browse files Browse the repository at this point in the history
  • Loading branch information
David Siecinski committed Jun 14, 2016
1 parent 02dde86 commit 4c34d6c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
14 changes: 5 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ def readStandardSequence(filename):
comparations=None
start = time.time()
end = time.time()
useIntrpolation=False
useInterpolation=True


if "full" in feed_in.lower() :
full_ = fullSearch.FullSearch(current_picture=current_picture,referenced_picture=referenced_picture,n=n,p=p,useIntrpolation=useIntrpolation)
full_ = fullSearch.FullSearch(current_picture=current_picture,referenced_picture=referenced_picture,n=n,p=p,useIntrpolation=useInterpolation)
compressedImage = full_.createCompressedImage()
end = time.time()

Expand All @@ -76,7 +76,7 @@ def readStandardSequence(filename):
print ds.motionEstimation()
comparations=ds.numOfcomparedMacroblocks
elif "log" in feed_in.lower() :
log = logsearch.LogSearch(current_picture=current_picture,referenced_picture=referenced_picture,n=n,p=p, useIntrpolation=useIntrpolation)
log = logsearch.LogSearch(current_picture=current_picture,referenced_picture=referenced_picture,n=n,p=p, useIntrpolation=useInterpolation)
compressedImage = log.createCompressedImage()
end = time.time()

Expand All @@ -88,12 +88,8 @@ def readStandardSequence(filename):

running_time=(end - start)
print "it took: ",running_time, "s"," Number of comparitions: ",comparations
if useIntrpolation:
# Only to get intepolated picture
full_ = fullSearch.FullSearch(current_picture=current_picture,referenced_picture=referenced_picture,n=n,p=p,useIntrpolation=useIntrpolation)
print psnr(full_.referenced_picture_interpolated,compressedImage),"[dB] - bigger value is better"
else:
print psnr(referenced_picture,compressedImage),"[dB] - bigger value is better"

print psnr(referenced_picture,compressedImage),"[dB] - bigger value is better"

im = Image.new("L", (len(compressedImage[0]), len(compressedImage)), "white")
img_list=[]
Expand Down
13 changes: 11 additions & 2 deletions search.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
__author__ = 'davidsiecinski'
from abc import ABCMeta, abstractmethod
from scipy import interpolate
from scipy import ndimage
import numpy


class Search:
Expand Down Expand Up @@ -88,6 +90,11 @@ def imageInterpolation(self,image):
interpolated_image=f(xx,yy).tolist()
return interpolated_image

def imageDownScaling(self,interpolated_image):
np_array=numpy.array(interpolated_image)
np_array_small=ndimage.interpolation.zoom(np_array,.5,order=5)
return np_array_small.tolist()


def createCompressedImage(self):
current_picture=None
Expand Down Expand Up @@ -129,5 +136,7 @@ def createCompressedImage(self):
exit()
except TypeError as e:
print e.message

return compressedImage
if self.useIntrpolation:
return self.imageDownScaling(compressedImage)
else:
return compressedImage
8 changes: 7 additions & 1 deletion unittest/fullSearch_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,10 @@ def test_motionEstimation2(self):
def test_image_interpolation(self):
image=[[0,1,0],[0,1,0],[0,1,0]]#[0,1,1,0,0,0],[0,1,1,0,0,0],[0,1,1,0,0,0],[0,1,1,0,0,0],[0,1,1,0,0,0]]
result =[[ 0.,0.5,1.,0.5,0.,0.],[ 0.,0.5,1.,0.5,0.,0.],[ 0.,0.5,1.,0.5,0.,0.],[ 0.,0.5,1.,0.5,0.,0.],[ 0.,0.5,1.,0.5,0.,0.],[ 0.,0.5,1.,0.5,0.,0.]]
self.assertEqual(self.small_fullsearch.imageInterpolation(image),result)
self.assertEqual(self.small_fullsearch.imageInterpolation(image),result)

def test_imageDownScaling(self):
big_image = [[ 0.,0.5,1.,0.5,0.,0.],[ 0.,0.5,1.,0.5,0.,0.],[ 0.,0.5,1.,0.5,0.,0.],[ 0.,0.5,1.,0.5,0.,0.],[ 0.,0.5,1.,0.5,0.,0.],[ 0.,0.5,1.,0.5,0.,0.]]
expected_result = [[0,1,0],[0,1,0],[0,1,0]]
# self.assertEqual(self.small_fullsearch.imageDownScaling(big_image), expected_result)
self.assertAlmostEqual(self.small_fullsearch.imageDownScaling(big_image)[0][1], expected_result[0][1],delta=0.2)

0 comments on commit 4c34d6c

Please sign in to comment.