From e86b0a161c0f204e00a45e046e5dc177ad7a881d Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Tue, 2 Jul 2013 23:22:02 -0500 Subject: [PATCH] Change inflate/inflation to rescale/scale. --- skimage/novice/novice.py | 45 +++++++++-------------------- skimage/novice/tests/test_novice.py | 2 +- 2 files changed, 14 insertions(+), 33 deletions(-) diff --git a/skimage/novice/novice.py b/skimage/novice/novice.py index 067d9379..089d531e 100644 --- a/skimage/novice/novice.py +++ b/skimage/novice/novice.py @@ -327,7 +327,7 @@ class Picture(object): # Common setup. self._modified = False - self._inflation = 1 + self.scale = 1 @staticmethod def from_path(path): @@ -395,7 +395,7 @@ class Picture(object): Path to save the picture (with file extension). """ - io.imsave(path, self._inflate(self._image)) + io.imsave(path, self._rescale(self._image)) self._modified = False self._path = os.path.abspath(path) self._format = imghdr.what(path) @@ -454,33 +454,17 @@ class Picture(object): def height(self, value): self.size = (self.width, value) - @property - def inflation(self): - """The inflation factor.""" - return self._inflation - - @inflation.setter - def inflation(self, value): - try: - value = int(value) - if value < 1: - raise ValueError() - self._inflation = value - except ValueError: - msg = "Expected inflation factor to be an integer greater than one" - raise ValueError(msg) - def _repr_html_(self): - return io.Image(self._inflate(self._image)) + return io.Image(self._rescale(self._image)) def _repr_png_(self): - return io.Image(self._inflate(self._image)) + return io.Image(self._rescale(self._image)) def show(self): """Displays the image in a separate window. """ - io.imshow(self._inflate(self._image)) + io.imshow(self._rescale(self._image)) def _makepixel(self, xy): """ Creates a Pixel object for a given x, y location. @@ -495,22 +479,19 @@ class Picture(object): rgb = self._image[self.height - xy[1] - 1, xy[0]] return Pixel(self, self._image, xy[0], xy[1], rgb) - def _inflate(self, img): - """Inflates image according to inflation factor. + def _rescale(self, image): + """Inflates image according to scale factor. Parameters ---------- - img : array - Raw RGB image data to inflate using nearest neighbor algorithm. + image : array + Raw RGB image data to rescale using nearest neighbor algorithm. """ - if self._inflation == 1: - return img - - # skimage dimensions are flipped: y, x - return img_as_ubyte(resize(img, - (self.height * self._inflation, - self.width * self._inflation), order=0)) + if self.scale == 1: + return image + new_size = (self.height * self.scale, self.width * self.scale) + return img_as_ubyte(resize(image, new_size, order=0)) def __iter__(self): """Iterates over all pixels in the image.""" diff --git a/skimage/novice/tests/test_novice.py b/skimage/novice/tests/test_novice.py index 737554a2..f039d9b2 100644 --- a/skimage/novice/tests/test_novice.py +++ b/skimage/novice/tests/test_novice.py @@ -18,7 +18,7 @@ def test_pic_info(): assert_equal(pic.width, 665) assert_equal(pic.height, 500) assert_equal(pic.modified, False) - assert_equal(pic.inflation, 1) + assert_equal(pic.scale, 1) def test_pixel_iteration():