From 8a3479a3c3a485da6ff7986e081ace9b181bb299 Mon Sep 17 00:00:00 2001 From: Julien Lengrand-Lambert Date: Mon, 28 Nov 2011 14:49:33 +0100 Subject: [PATCH] Adds first example to Tippy Examples package added. Tests Region growing function. TODO: Tippy is not reachable from examples folder. This has to be fixed soon. --- tippy/examples/__init__.py | 0 tippy/examples/region_growing.py | 42 ++++++++++++++++++++++++++++++++ tippy/segmentations.py | 4 +-- 3 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 tippy/examples/__init__.py create mode 100644 tippy/examples/region_growing.py diff --git a/tippy/examples/__init__.py b/tippy/examples/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tippy/examples/region_growing.py b/tippy/examples/region_growing.py new file mode 100644 index 0000000..c5dd4d1 --- /dev/null +++ b/tippy/examples/region_growing.py @@ -0,0 +1,42 @@ +''' +Created on Nov 28, 2011 + +@author: Julien Lengrand-Lambert +@email: julien@lengrand.fr +--- +Here is a simple example of (simple) Region Growing algorithm in Python. + +A word about region growing (taken from Wikipedia), and this implementation : +"Region growing is a simple region-based image segmentation method. It is also classified as a pixel-based image segmentation method since it involves the selection of initial seed points. +This approach to segmentation examines neighboring pixels of initial “seed points” and determines whether the pixel neighbors should be added to the region. The process is iterated on, in the same manner as general data clustering algorithms" +Basically, region growing is an iterative method used to extract similar parts of an image. One or several points are chosen as a start. The region then grows until it is finally blocked by the stop criteria. This criteria is generally an inside/outside region comparison (energy, size, . . .). +Region growing is massively used in medical imaging, and object detection. Here is an example of application in automatic Mine Hunting, which I worked with last year at TNO. + +The following method uses one seed point, defined by the user. The region grows by comparing with its neighbourhood. The chosen criteria is in this case a difference between outside pixel's intensity value and the region's mean. +The pixel with minimum intensity in the region neighbouhood is chosen to be included. The growing stops as soon as the difference is larger than a threshold. + +In this implementation, a 4-connectivity has been chosen. The 8-connectivity should be included soon. +Due to the method itself, only grayscale images may be processed for now. So color images should be converted first. + +''' + +import cv +import tippy.segmentations as se +import tippy.basic_operations as bo +import tippy.display_operations as do + + +user_input = 0 + +img_name = "../data/gnu.jpg" +threshold = 20 +img = cv.LoadImage(img_name, cv.CV_LOAD_IMAGE_GRAYSCALE) + +if user_input: + seed = bo.mouse_point(img, mode="S") # waits for user click to get seed +else: + seed = (70, 106) + +out_img = se.simple_region_growing(img, seed, threshold) + +do.display_single_image(out_img, "Region Growing result") diff --git a/tippy/segmentations.py b/tippy/segmentations.py index 15e825a..83e5aca 100644 --- a/tippy/segmentations.py +++ b/tippy/segmentations.py @@ -93,6 +93,4 @@ def simple_region_growing(img, seed, threshold=1): del contour[index] del contour_val[index] - return reg - - ### \ No newline at end of file + return reg \ No newline at end of file