Skip to content

Commit

Permalink
pep8
Browse files Browse the repository at this point in the history
  • Loading branch information
gitmirgut committed Apr 10, 2017
1 parent 3da9fa9 commit 660db34
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
25 changes: 21 additions & 4 deletions bb_stitcher/measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,40 @@
import bb_stitcher.picking.picker as picker


def calc_ratio(image):
def get_ratio(image):
"""Determine the ratio to convert from pixel to mm.
The user must select two points on the image. The selected points, will be used to determine the
ratio between px and mm.
Args:
image (ndarray): Reference image.
Returns:
flaot: Ratio to convert pixel to mm.
float: Ratio to convert pixel to mm.
"""
pt_picker = picker.PointPicker()
points = pt_picker.pick([image], False)
assert len(points[0]) == 2
start_point, end_point = points[0]
print(start_point)
print(end_point)
distance_mm = float(input('Distance in mm of the two selected points: '))
ratio = helpers.get_ratio_px_to_mm(start_point, end_point, distance_mm)

return ratio


def get_origin(image):
"""Determine origin of the image.
The user must select one point on the image.
The selected point will be used to define the origin of the image, this will assure that mapped
coordinates will always be in relation to the origin and not to the image.
Args:
image (ndarray): Reference image.
Returns:
ndarray: origin (2,)
"""
pt_picker = picker.PointPicker()
points = pt_picker.pick([image], False)
assert len(points[0]) == 1
return points[0][0]
15 changes: 13 additions & 2 deletions tests/test_measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import bb_stitcher.measure as measure


def test_calc_ratio(panorma, monkeypatch):
def test_get_ratio(panorma, monkeypatch):
def mockreturn(myself, image_list, all):
points = [np.array([
[94.43029022, 471.89901733],
Expand All @@ -14,6 +14,17 @@ def mockreturn(myself, image_list, all):
return points
monkeypatch.setattr(bb_stitcher.picking.picker.PointPicker, 'pick', mockreturn)
monkeypatch.setitem(__builtins__, 'input', lambda x: "348")
ratio = measure.calc_ratio(panorma)
ratio = measure.get_ratio(panorma)
target = 348 / 5400
npt.assert_almost_equal(ratio, target, decimal=4)


def test_get_origin(panorma, monkeypatch):
def mockreturn(myself, image_list, all):
points = [np.array([
[94.43029022, 471.89901733]
], dtype=np.float32)]
return points
monkeypatch.setattr(bb_stitcher.picking.picker.PointPicker, 'pick', mockreturn)
point = measure.get_origin(panorma)
assert point is not None

0 comments on commit 660db34

Please sign in to comment.