Skip to content
Snippets Groups Projects
Commit 1a0c8b6c authored by Sander Mathijs van Veen's avatar Sander Mathijs van Veen
Browse files

improc ass2 code cleanup.

parent 799b1ac6
No related branches found
No related tags found
No related merge requests found
...@@ -6,33 +6,32 @@ def inImage(image, x, y): ...@@ -6,33 +6,32 @@ def inImage(image, x, y):
return x >= 0 and y >= 0 and x < image.shape[0] and y < image.shape[1] return x >= 0 and y >= 0 and x < image.shape[0] and y < image.shape[1]
def pV(image, x, y, method): def pV(image, x, y, method):
global bgcolor if not inImage(image, x, y):
if inImage(image, x, y):
if method == 'nearest':
return image[round(x)][round(y)]
elif method == 'linear':
x1 = floor(x)
x2 = ceil(x)
y1 = floor(y)
y2 = ceil(y)
return image[x1][y1] * (x2 - x) * (y2 - y) \
+ image[x2][y1] * (x - x1) * (y2 - y) \
+ image[x1][y2] * (x2 - x) * (y - y1) \
+ image[x2][y2] * (x - x1) * (y - y1)
else:
print 'Interpolation method "%s" is not supported' % method
else:
return bgcolor return bgcolor
if method == 'nearest':
return image[round(x)][round(y)]
if method == 'linear':
x1 = floor(x)
x2 = ceil(x)
y1 = floor(y)
y2 = ceil(y)
return image[x1][y1] * (x2 - x) * (y2 - y) \
+ image[x2][y1] * (x - x1) * (y2 - y) \
+ image[x1][y2] * (x2 - x) * (y - y1) \
+ image[x2][y2] * (x - x1) * (y - y1)
raise ValueError, 'Interpolation method "%s" is not supported' % method
if __name__ == '__main__': if __name__ == '__main__':
from pylab import linspace, show, imread, plot, array from pylab import linspace, show, imread, plot, array
"""Profile of an image along line in n points.""" """Profile of an image along line in n points."""
def profile(image, x0, y0, x1, y1, n, method): def profile(image, x0, y0, x1, y1, n, method):
return array([pV(image, x, y, method) for x, y in zip(linspace(x0, \ dataset = zip(linspace(x0, x1, n), linspace(y0, y1, n))
x1, n), linspace(y0, y1, n))]) return array([pV(image, x, y, method) for x, y in dataset])
a = imread('cameraman.png') a = imread('cameraman.png')
for method in ['nearest', 'linear']: for method in ['nearest', 'linear']:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment