From 5b71cd9481fbde576370d6391e5308a8d878a415 Mon Sep 17 00:00:00 2001 From: salvatore Date: Sat, 20 Dec 2014 00:39:33 +0100 Subject: [PATCH 1/8] Added an example of use of CanvasTools.RectTool to allow generation of docs. RectTool is used to write rectangles over an image (lena). This example also can be useful for set_color explanation using both [RGB] and single value color setting --- skimage/viewer/canvastools/recttool.py | 34 +++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/skimage/viewer/canvastools/recttool.py b/skimage/viewer/canvastools/recttool.py index 8932e180..62e7d9b3 100644 --- a/skimage/viewer/canvastools/recttool.py +++ b/skimage/viewer/canvastools/recttool.py @@ -37,8 +37,40 @@ class RectangleTool(CanvasToolBase, RectangleSelector): ---------- extents : tuple Rectangle extents: (xmin, xmax, ymin, ymax). - """ + + Examples + -------- + >>>from skimage import data + >>>import matplotlib.pyplot as plt + >>>from skimage.viewer.canvastools import RectangleTool + >>>import numpy as np + >>>from skimage.draw import line + >>>from skimage.draw import set_color + + >>>im = data.lena() + >>>[f, ax] = plt.subplots() + >>>ax.imshow(im) + + >>>def stampa(extents): + >>>>>>global im,ax + >>>>>>coord = np.int64(extents) + >>>>>>[rr1, cc1] = line(coord[2],coord[0],coord[2],coord[1]) + >>>>>>[rr2, cc2] = line(coord[2],coord[1],coord[3],coord[1]) + >>>>>>[rr3, cc3] = line(coord[3],coord[1],coord[3],coord[0]) + >>>>>>[rr4, cc4] = line(coord[3],coord[0],coord[2],coord[0]) + >>>>>>set_color(im, (rr1, cc1), [255, 255, 0]) + >>>>>>set_color(im, (rr2, cc2), [0, 255, 255]) + >>>>>>set_color(im, (rr3, cc3), [255, 0, 255]) + >>>>>>set_color(im, (rr4, cc4), [0, 0, 0]) + >>>>>>ax.imshow(im) + >>>>>>plt.show() + + >>>rect_tool = RectangleTool(ax, on_enter=stampa) + >>>plt.show() + + """ + def __init__(self, viewer, on_move=None, on_release=None, on_enter=None, maxdist=10, rect_props=None): CanvasToolBase.__init__(self, viewer, on_move=on_move, From a01a5ed0238e334d2d55518455bd420319b62722 Mon Sep 17 00:00:00 2001 From: salvatore Date: Sat, 20 Dec 2014 23:54:06 +0100 Subject: [PATCH 2/8] Added an example of use of CanvasTools.RectTool to allow generation of docs. RectTool is used to write rectangles over an image (lena). This example also can be useful for set_color explanation using both [RGB] and single value color setting from previous commit indented code in examples is formatted properly. --- skimage/viewer/canvastools/recttool.py | 48 +++++++++++++------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/skimage/viewer/canvastools/recttool.py b/skimage/viewer/canvastools/recttool.py index 62e7d9b3..3f8fbd79 100644 --- a/skimage/viewer/canvastools/recttool.py +++ b/skimage/viewer/canvastools/recttool.py @@ -41,33 +41,33 @@ class RectangleTool(CanvasToolBase, RectangleSelector): Examples -------- - >>>from skimage import data - >>>import matplotlib.pyplot as plt - >>>from skimage.viewer.canvastools import RectangleTool - >>>import numpy as np - >>>from skimage.draw import line - >>>from skimage.draw import set_color + >>> from skimage import data + >>> import matplotlib.pyplot as plt + >>> from skimage.viewer.canvastools import RectangleTool + >>> import numpy as np + >>> from skimage.draw import line + >>> from skimage.draw import set_color - >>>im = data.lena() - >>>[f, ax] = plt.subplots() - >>>ax.imshow(im) + >>> im = data.lena() + >>> [f, ax] = plt.subplots() + >>> ax.imshow(im) - >>>def stampa(extents): - >>>>>>global im,ax - >>>>>>coord = np.int64(extents) - >>>>>>[rr1, cc1] = line(coord[2],coord[0],coord[2],coord[1]) - >>>>>>[rr2, cc2] = line(coord[2],coord[1],coord[3],coord[1]) - >>>>>>[rr3, cc3] = line(coord[3],coord[1],coord[3],coord[0]) - >>>>>>[rr4, cc4] = line(coord[3],coord[0],coord[2],coord[0]) - >>>>>>set_color(im, (rr1, cc1), [255, 255, 0]) - >>>>>>set_color(im, (rr2, cc2), [0, 255, 255]) - >>>>>>set_color(im, (rr3, cc3), [255, 0, 255]) - >>>>>>set_color(im, (rr4, cc4), [0, 0, 0]) - >>>>>>ax.imshow(im) - >>>>>>plt.show() + >>> def stampa(extents): + ... global im,ax + ... coord = np.int64(extents) + ... [rr1, cc1] = line(coord[2],coord[0],coord[2],coord[1]) + ... [rr2, cc2] = line(coord[2],coord[1],coord[3],coord[1]) + ... [rr3, cc3] = line(coord[3],coord[1],coord[3],coord[0]) + ... [rr4, cc4] = line(coord[3],coord[0],coord[2],coord[0]) + ... set_color(im, (rr1, cc1), [255, 255, 0]) + ... set_color(im, (rr2, cc2), [0, 255, 255]) + ... set_color(im, (rr3, cc3), [255, 0, 255]) + ... set_color(im, (rr4, cc4), [0, 0, 0]) + ... ax.imshow(im) + ... plt.show() - >>>rect_tool = RectangleTool(ax, on_enter=stampa) - >>>plt.show() + >>> rect_tool = RectangleTool(ax, on_enter=stampa) + >>> plt.show() """ From 37a45a2b60217c56525f998a22d185102a917595 Mon Sep 17 00:00:00 2001 From: salvatore Date: Sun, 21 Dec 2014 00:05:56 +0100 Subject: [PATCH 3/8] Contributor file updated .... very nice to be part of this beatiful scikit! --- CONTRIBUTORS.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 143b2b78..d57b6015 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -200,3 +200,6 @@ - Matěj Týč Extended the image labelling implementation so it also works on 3D images. + +- Salvatore Scaramuzzino + RectTool example \ No newline at end of file From 04b998199aca8e54936d30222398e4459fee3f04 Mon Sep 17 00:00:00 2001 From: salvatore Date: Mon, 22 Dec 2014 11:25:00 +0100 Subject: [PATCH 4/8] try to format properly a function in examples of RectTool --- skimage/viewer/canvastools/recttool.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/skimage/viewer/canvastools/recttool.py b/skimage/viewer/canvastools/recttool.py index 3f8fbd79..595faba6 100644 --- a/skimage/viewer/canvastools/recttool.py +++ b/skimage/viewer/canvastools/recttool.py @@ -48,23 +48,23 @@ class RectangleTool(CanvasToolBase, RectangleSelector): >>> from skimage.draw import line >>> from skimage.draw import set_color - >>> im = data.lena() + >>> im = data.coffee() >>> [f, ax] = plt.subplots() >>> ax.imshow(im) >>> def stampa(extents): - ... global im,ax - ... coord = np.int64(extents) - ... [rr1, cc1] = line(coord[2],coord[0],coord[2],coord[1]) - ... [rr2, cc2] = line(coord[2],coord[1],coord[3],coord[1]) - ... [rr3, cc3] = line(coord[3],coord[1],coord[3],coord[0]) - ... [rr4, cc4] = line(coord[3],coord[0],coord[2],coord[0]) - ... set_color(im, (rr1, cc1), [255, 255, 0]) - ... set_color(im, (rr2, cc2), [0, 255, 255]) - ... set_color(im, (rr3, cc3), [255, 0, 255]) - ... set_color(im, (rr4, cc4), [0, 0, 0]) - ... ax.imshow(im) - ... plt.show() + >>> global im,ax + >>> coord = np.int64(extents) + >>> [rr1, cc1] = line(coord[2],coord[0],coord[2],coord[1]) + >>> [rr2, cc2] = line(coord[2],coord[1],coord[3],coord[1]) + >>> [rr3, cc3] = line(coord[3],coord[1],coord[3],coord[0]) + >>> [rr4, cc4] = line(coord[3],coord[0],coord[2],coord[0]) + >>> set_color(im, (rr1, cc1), [255, 255, 0]) + >>> set_color(im, (rr2, cc2), [0, 255, 255]) + >>> set_color(im, (rr3, cc3), [255, 0, 255]) + >>> set_color(im, (rr4, cc4), [0, 0, 0]) + >>> ax.imshow(im) + >>> plt.show() >>> rect_tool = RectangleTool(ax, on_enter=stampa) >>> plt.show() From 5401d00b627200252127998ea7d7e008de47cdcf Mon Sep 17 00:00:00 2001 From: salvatore Date: Mon, 22 Dec 2014 12:13:10 +0100 Subject: [PATCH 5/8] deleted ">>>" in body of print_the_rect function --- skimage/viewer/canvastools/recttool.py | 30 +++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/skimage/viewer/canvastools/recttool.py b/skimage/viewer/canvastools/recttool.py index 595faba6..93400ceb 100644 --- a/skimage/viewer/canvastools/recttool.py +++ b/skimage/viewer/canvastools/recttool.py @@ -39,7 +39,7 @@ class RectangleTool(CanvasToolBase, RectangleSelector): Rectangle extents: (xmin, xmax, ymin, ymax). - Examples + Examples -------- >>> from skimage import data >>> import matplotlib.pyplot as plt @@ -52,21 +52,21 @@ class RectangleTool(CanvasToolBase, RectangleSelector): >>> [f, ax] = plt.subplots() >>> ax.imshow(im) - >>> def stampa(extents): - >>> global im,ax - >>> coord = np.int64(extents) - >>> [rr1, cc1] = line(coord[2],coord[0],coord[2],coord[1]) - >>> [rr2, cc2] = line(coord[2],coord[1],coord[3],coord[1]) - >>> [rr3, cc3] = line(coord[3],coord[1],coord[3],coord[0]) - >>> [rr4, cc4] = line(coord[3],coord[0],coord[2],coord[0]) - >>> set_color(im, (rr1, cc1), [255, 255, 0]) - >>> set_color(im, (rr2, cc2), [0, 255, 255]) - >>> set_color(im, (rr3, cc3), [255, 0, 255]) - >>> set_color(im, (rr4, cc4), [0, 0, 0]) - >>> ax.imshow(im) - >>> plt.show() + >>> def print_the_rect(extents): + global im,ax + coord = np.int64(extents) + [rr1, cc1] = line(coord[2],coord[0],coord[2],coord[1]) + [rr2, cc2] = line(coord[2],coord[1],coord[3],coord[1]) + [rr3, cc3] = line(coord[3],coord[1],coord[3],coord[0]) + [rr4, cc4] = line(coord[3],coord[0],coord[2],coord[0]) + set_color(im, (rr1, cc1), [255, 255, 0]) + set_color(im, (rr2, cc2), [0, 255, 255]) + set_color(im, (rr3, cc3), [255, 0, 255]) + set_color(im, (rr4, cc4), [0, 0, 0]) + ax.imshow(im) + plt.show() - >>> rect_tool = RectangleTool(ax, on_enter=stampa) + >>> rect_tool = RectangleTool(ax, on_enter=print_the_rect) >>> plt.show() """ From ad96b911abb69965629ab5f4531c5d14278cbd02 Mon Sep 17 00:00:00 2001 From: salvatore Date: Mon, 22 Dec 2014 20:49:44 +0100 Subject: [PATCH 6/8] ... added in indented code --- skimage/viewer/canvastools/recttool.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/skimage/viewer/canvastools/recttool.py b/skimage/viewer/canvastools/recttool.py index 93400ceb..da6accf2 100644 --- a/skimage/viewer/canvastools/recttool.py +++ b/skimage/viewer/canvastools/recttool.py @@ -53,18 +53,18 @@ class RectangleTool(CanvasToolBase, RectangleSelector): >>> ax.imshow(im) >>> def print_the_rect(extents): - global im,ax - coord = np.int64(extents) - [rr1, cc1] = line(coord[2],coord[0],coord[2],coord[1]) - [rr2, cc2] = line(coord[2],coord[1],coord[3],coord[1]) - [rr3, cc3] = line(coord[3],coord[1],coord[3],coord[0]) - [rr4, cc4] = line(coord[3],coord[0],coord[2],coord[0]) - set_color(im, (rr1, cc1), [255, 255, 0]) - set_color(im, (rr2, cc2), [0, 255, 255]) - set_color(im, (rr3, cc3), [255, 0, 255]) - set_color(im, (rr4, cc4), [0, 0, 0]) - ax.imshow(im) - plt.show() + ... global im, ax + ... coord = np.int64(extents) + ... [rr1, cc1] = line(coord[2],coord[0],coord[2],coord[1]) + ... [rr2, cc2] = line(coord[2],coord[1],coord[3],coord[1]) + ... [rr3, cc3] = line(coord[3],coord[1],coord[3],coord[0]) + ... [rr4, cc4] = line(coord[3],coord[0],coord[2],coord[0]) + ... set_color(im, (rr1, cc1), [255, 255, 0]) + ... set_color(im, (rr2, cc2), [0, 255, 255]) + ... set_color(im, (rr3, cc3), [255, 0, 255]) + ... set_color(im, (rr4, cc4), [0, 0, 0]) + ... ax.imshow(im) + ... plt.show() >>> rect_tool = RectangleTool(ax, on_enter=print_the_rect) >>> plt.show() From d28ae513ca8911cc5a8b293647f6b8615a1f35e1 Mon Sep 17 00:00:00 2001 From: salvatore Date: Fri, 26 Dec 2014 10:37:03 +0100 Subject: [PATCH 7/8] Travis auto-build Doctest skipped to avoid window opening --- skimage/viewer/canvastools/recttool.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/skimage/viewer/canvastools/recttool.py b/skimage/viewer/canvastools/recttool.py index da6accf2..b5c2742e 100644 --- a/skimage/viewer/canvastools/recttool.py +++ b/skimage/viewer/canvastools/recttool.py @@ -38,22 +38,20 @@ class RectangleTool(CanvasToolBase, RectangleSelector): extents : tuple Rectangle extents: (xmin, xmax, ymin, ymax). - Examples - -------- + ---------- >>> from skimage import data - >>> import matplotlib.pyplot as plt + >>> from skimage.viewer import ImageViewer >>> from skimage.viewer.canvastools import RectangleTool >>> import numpy as np >>> from skimage.draw import line >>> from skimage.draw import set_color - - >>> im = data.coffee() - >>> [f, ax] = plt.subplots() - >>> ax.imshow(im) + + >>> viewer = ImageViewer(data.coffee()) # doctest: +SKIP >>> def print_the_rect(extents): - ... global im, ax + ... global viewer + ... im = viewer.image ... coord = np.int64(extents) ... [rr1, cc1] = line(coord[2],coord[0],coord[2],coord[1]) ... [rr2, cc2] = line(coord[2],coord[1],coord[3],coord[1]) @@ -63,12 +61,14 @@ class RectangleTool(CanvasToolBase, RectangleSelector): ... set_color(im, (rr2, cc2), [0, 255, 255]) ... set_color(im, (rr3, cc3), [255, 0, 255]) ... set_color(im, (rr4, cc4), [0, 0, 0]) - ... ax.imshow(im) - ... plt.show() + ... viewer.image=im + + >>> rect_tool = RectangleTool(viewer.ax, on_enter=print_the_rect) # doctest: +SKIP + >>> viewer.show() # doctest: +SKIP - >>> rect_tool = RectangleTool(ax, on_enter=print_the_rect) - >>> plt.show() - + + + """ def __init__(self, viewer, on_move=None, on_release=None, on_enter=None, From ac52af7d83bd621ec9fbbe54309b1fd214bd8a7e Mon Sep 17 00:00:00 2001 From: salvatore Date: Fri, 26 Dec 2014 12:12:15 +0100 Subject: [PATCH 8/8] removed numpy import and spaces --- skimage/viewer/canvastools/recttool.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/skimage/viewer/canvastools/recttool.py b/skimage/viewer/canvastools/recttool.py index b5c2742e..44a5cc1d 100644 --- a/skimage/viewer/canvastools/recttool.py +++ b/skimage/viewer/canvastools/recttool.py @@ -43,7 +43,6 @@ class RectangleTool(CanvasToolBase, RectangleSelector): >>> from skimage import data >>> from skimage.viewer import ImageViewer >>> from skimage.viewer.canvastools import RectangleTool - >>> import numpy as np >>> from skimage.draw import line >>> from skimage.draw import set_color @@ -65,10 +64,6 @@ class RectangleTool(CanvasToolBase, RectangleSelector): >>> rect_tool = RectangleTool(viewer.ax, on_enter=print_the_rect) # doctest: +SKIP >>> viewer.show() # doctest: +SKIP - - - - """ def __init__(self, viewer, on_move=None, on_release=None, on_enter=None,