extinction_values

Autor: alexgs
Data: 19/06/2009

C++ Extinction Values Library

A gray-level image can be interpreted as a topographical surface, and represented by a component tree, based on the inclusion relation of connected components obtained by threshold decomposition. Relations between plateaus, valleys or mountains of this relief are useful in computer vision systems. An important definition to characterize the topographical surface is the dynamics, introduced by Grimaud (1992), associated to each regional minimum. This concept has been extended, by Vachier and Meyer (1995), by the definition of extinction values associated to each extremum of the image. This paper proposes four new extinction values -- two based on the topology of the component tree: (i) number of descendants and (ii) sub-tree height; and two geometric: (iii) level component bounding box (subdivided into extinctions of height, width or diagonal). This work describes an efficient computation of these extinction values based on the incremental determination of attributes from the component tree construction in quasi-linear time, compares the computation time of the method and illustrates the usefulness of these new extinction values from real examples.

  • Developer: Alexandre Gonçalves Silva - DCC/CCT/UDESC
  • Advisor: Roberto de Alencar Lotufo - DCA/FEEC/UNICAMP

Source code

Main function (morph image interface)

 1 #include "morph4python.h"
 2 
 3 Image *extinction_cpp(Image *image, char *option, int threshold) {
 4     #define OPTIONS 8
 5     int i, j, ext;
 6     char op[OPTIONS][10] = {"height","area","volume","desc","htop","hbbox","wbbox","dbbox"};
 7     Imagem f = imZeros(image->height(), image->width(), 1);
 8 
 9     for (i=0; i < OPTIONS; i++)
10         if (strcmp(option,op[i])==0) break;
11     ext = i;
12     if (ext == OPTIONS) {
13         printf("Invalid option.\n");
14         return NULL;
15     }
16 
17     for (i=0; i < image->height(); i++)
18         for (j=0; j < image->width(); j++)
19             f.matriz[i][j] = image->getpixel(j,i,0);
20 
21     HashMaxTree *mt = img2tree(f);
22 
23     switch (ext) {
24         case 0:
25             extinction_height(mt);
26             break;
27         case 1:
28             extinction_area(mt);
29             break;
30         case 2:
31             extinction_volume(mt);
32             break;
33         case 3:
34             extinction_desc(mt);
35             break;
36         case 4:
37             extinction_htop(mt);
38             break;
39         case 5:
40             extinction_hbbox(mt);
41             break;
42         case 6:
43             extinction_wbbox(mt);
44             break;
45         case 7:
46             extinction_dbbox(mt);
47             break;
48     }
49     Imagem out = mt->ext2img();
50 
51     out = imThreshold(out, threshold);
52     out.asgray(); out = imNormalize(out);
53 
54     Image *output = new Image(image->width(), image->height(), image->depth(), "uint8");
55     for (i=0; i < image->height(); i++)
56         for (j=0; j < image->width(); j++)
57             output->putpixel(j, i, 0, out.matriz[i][j]);
58 
59     return output;
60 }

Library interface

1 Image *extinction_cpp(Image *image, char *option, int threshold);
OK

--------------------------------------------------------------------------------
    Thu Dec 12 15:01:11 2013
--------------------------------------------------------------------------------
-- Configuring done
-- Generating done
-- Build files have been written to: <pkg_dir>/_build/_extinction_values
[ 25%] Swig source
Scanning dependencies of target __extinction_values
[ 50%] Building CXX object CMakeFiles/__extinction_values.dir/_extinction_valuesPYTHON_wrap.o
[ 75%] Building CXX object CMakeFiles/__extinction_values.dir/_extinction_values.o
In file included from /usr/include/python2.7/Python.h:8:0,
                 from /home/adessowiki/morph4python16/morph4python.h:63,
                 from <pkg_dir>/_build/_extinction_values/_extinction_values.cpp:2659:
/usr/include/python2.7/pyconfig.h:1161:0: warning: "_POSIX_C_SOURCE" redefined [enabled by default]
/usr/include/features.h:164:0: note: this is the location of the previous definition
/usr/include/python2.7/pyconfig.h:1183:0: warning: "_XOPEN_SOURCE" redefined [enabled by default]
/usr/include/features.h:166:0: note: this is the location of the previous definition
<pkg_dir>/_build/_extinction_values/_extinction_values.cpp: In constructor 'Imagem::Imagem(char*)':
<pkg_dir>/_build/_extinction_values/_extinction_values.cpp:1548:26: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
<pkg_dir>/_build/_extinction_values/_extinction_values.cpp:1557:42: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
<pkg_dir>/_build/_extinction_values/_extinction_values.cpp:1561:52: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
<pkg_dir>/_build/_extinction_values/_extinction_values.cpp:1577:23: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
<pkg_dir>/_build/_extinction_values/_extinction_values.cpp:1580:23: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
[100%] Building CXX object CMakeFiles/__extinction_values.dir<pkg_dir>/_build/simple_arrays.o
Linking CXX shared module __extinction_values.so
[100%] Built target __extinction_values

Python binding

1 def extinction(image, option, threshold = 1):
2     from numpy import uint8
3     return extinction_cpp(image.astype(uint8), option, threshold)

Examples

1 from code.extinction_values import extinction
2 from ia636 import ianormalize
3 
4 f = mmreadgray('brigadeiros.pgm')
5 
6 Edesc = extinction(f, 'desc',  500)
7 
8 adshow(mmneg(f), title='f')
9 adshow(ianormalize(mmdil(uint8(Edesc) ,mmsedisk()), (0,255)), title='Edesc(f) >= 500')

f

Edesc(f) >= 500