Fix failing tests

This commit is contained in:
blink1073
2014-07-16 19:58:13 -05:00
parent 9576df45f8
commit 1a01f1a83b
4 changed files with 27 additions and 23 deletions
+12 -10
View File
@@ -46,7 +46,7 @@ class LineProfile(PlotPlugin):
if self._limit_type == 'image':
self.limits = (np.min(image), np.max(image))
elif self._limit_type == 'dtype':
self._limit_type = dtype_range[image.dtype.type]
self.limits = dtype_range[image.dtype.type]
elif self._limit_type is None or len(self._limit_type) == 2:
self.limits = self._limit_type
else:
@@ -91,6 +91,7 @@ class LineProfile(PlotPlugin):
profile: list of 1d arrays
Profile of intensity values. Length 1 (grayscale) or 3 (rgb).
"""
self._update_data()
profiles = [data.get_ydata() for data in self.profile]
return self.line_tool.end_points, profiles
@@ -103,8 +104,15 @@ class LineProfile(PlotPlugin):
def line_changed(self, end_points):
x, y = np.transpose(end_points)
self.line_tool.end_points = end_points
scan = measure.profile_line(self.image_viewer.original_image,
*end_points[:, ::-1],
self._update_data()
self.ax.relim()
self._autoscale_view()
self.redraw()
def _update_data(self):
scan = measure.profile_line(self.image_viewer.image,
*self.line_tool.end_points[:, ::-1],
linewidth=self.line_tool.linewidth)
self.scan_data = scan
if scan.ndim == 1:
@@ -117,11 +125,6 @@ class LineProfile(PlotPlugin):
self.profile[i].set_xdata(np.arange(scan.shape[0]))
self.profile[i].set_ydata(scan[:, i])
self.ax.relim()
self._autoscale_view()
self.redraw()
def reset_axes(self, scan_data):
# Clear lines out
for line in self.ax.lines:
@@ -147,7 +150,7 @@ class LineProfile(PlotPlugin):
The line scan values across the image.
"""
end_points = self.line_tool.end_points
line_image = np.zeros(self.image_viewer.original_image.shape[:2],
line_image = np.zeros(self.image_viewer.image.shape[:2],
np.uint8)
width = self.line_tool.linewidth
if width > 1:
@@ -162,4 +165,3 @@ class LineProfile(PlotPlugin):
rr, cc = draw.line(y1, x1, y2, x2)
line_image[rr, cc] = 255
return line_image, self.scan_data
+10 -9
View File
@@ -17,7 +17,7 @@ from skimage.viewer.widgets import Slider
def setup_line_profile(image, limits='image'):
viewer = ImageViewer(skimage.img_as_float(image))
plugin = LineProfile(limits)
plugin = LineProfile(limits=limits)
viewer += plugin
return plugin
@@ -63,16 +63,17 @@ def test_line_profile_dynamic():
line = lp.get_profiles()[-1][0]
assert line.size == 129
assert_almost_equal(np.std(image), 46.478, 3)
assert_almost_equal(np.std(viewer.image), 0.208, 3)
assert_almost_equal(np.std(line), 0.226, 3)
assert_almost_equal(np.max(line) - np.min(line), 0.725, 1)
viewer.image = median(image)
viewer.image = skimage.img_as_float(median(image,
selem=disk(radius=3)))
line = lp.get_profiles()[-1][0]
assert_almost_equal(np.std(image), 51.364, 3)
assert_almost_equal(np.std(line), 56.3555, 3)
assert_almost_equal(np.max(line) - np.min(line), 172.0, 1)
assert_almost_equal(np.std(viewer.image), 0.198, 3)
assert_almost_equal(np.std(line), 0.220, 3)
assert_almost_equal(np.max(line) - np.min(line), 0.639, 1)
@skipif(qt_api is None)
@@ -110,10 +111,10 @@ def test_label_painter():
assert_equal(lp.radius, 5)
lp.label = 1
assert_equal(lp.label, '1')
assert_equal(str(lp.label), '1')
lp.label = 2
assert_equal(lp.label, '2')
assert_equal(lp.paint_tool.radius, 2)
assert_equal(str(lp.paint_tool.label), '2')
assert_equal(lp.paint_tool.radius, 5)
lp._on_new_image(moon)
assert_equal(lp.paint_tool.shape, moon.shape)
+4 -3
View File
@@ -4,6 +4,7 @@ from skimage import data, img_as_float, io
from skimage.viewer import ImageViewer
from skimage.viewer.widgets import (
Slider, OKCancelButtons, SaveButtons, ComboBox, Text)
from skimage.viewer.utils import init_qtapp
from skimage.viewer.plugins.base import Plugin
from skimage.viewer.qt import qt_api, QtGui, QtCore
@@ -24,10 +25,10 @@ def test_combo_box():
cb = ComboBox('hello', ('a', 'b', 'c'))
viewer.plugins[0] += cb
assert_equal(cb.val, 'a')
assert_equal(str(cb.val), 'a')
assert_equal(cb.index, 0)
cb.index = 2
assert_equal(cb.val, 'c'),
assert_equal(str(cb.val), 'c'),
assert_equal(cb.index, 2)
@@ -102,4 +103,4 @@ def test_ok_buttons():
ok.update_original_image(),
ok.close_plugin()
+1 -1
View File
@@ -244,7 +244,7 @@ class ComboBox(BaseWidget):
@property
def val(self):
return self._combo_box.value()
return self._combo_box.currentText()
@property
def index(self):