jbclass.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*====================================================================*
  2. - Copyright (C) 2001 Leptonica. All rights reserved.
  3. -
  4. - Redistribution and use in source and binary forms, with or without
  5. - modification, are permitted provided that the following conditions
  6. - are met:
  7. - 1. Redistributions of source code must retain the above copyright
  8. - notice, this list of conditions and the following disclaimer.
  9. - 2. Redistributions in binary form must reproduce the above
  10. - copyright notice, this list of conditions and the following
  11. - disclaimer in the documentation and/or other materials
  12. - provided with the distribution.
  13. -
  14. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  15. - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  16. - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  17. - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
  18. - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19. - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20. - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  21. - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  22. - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23. - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. *====================================================================*/
  26. #ifndef LEPTONICA_JBCLASS_H
  27. #define LEPTONICA_JBCLASS_H
  28. /*
  29. * jbclass.h
  30. *
  31. * JbClasser
  32. * JbData
  33. */
  34. /* The JbClasser struct holds all the data accumulated during the
  35. * classification process that can be used for a compressed
  36. * jbig2-type representation of a set of images. This is created
  37. * in an initialization process and added to as the selected components
  38. * on each successive page are analyzed. */
  39. struct JbClasser
  40. {
  41. struct Sarray *safiles; /* input page image file names */
  42. l_int32 method; /* JB_RANKHAUS, JB_CORRELATION */
  43. l_int32 components; /* JB_CONN_COMPS, JB_CHARACTERS or */
  44. /* JB_WORDS */
  45. l_int32 maxwidth; /* max component width allowed */
  46. l_int32 maxheight; /* max component height allowed */
  47. l_int32 npages; /* number of pages already processed */
  48. l_int32 baseindex; /* number of components already processed */
  49. /* on fully processed pages */
  50. struct Numa *nacomps; /* number of components on each page */
  51. l_int32 sizehaus; /* size of square struct element for haus */
  52. l_float32 rankhaus; /* rank val of haus match, each way */
  53. l_float32 thresh; /* thresh value for correlation score */
  54. l_float32 weightfactor; /* corrects thresh value for heaver */
  55. /* components; use 0 for no correction */
  56. struct Numa *naarea; /* w * h of each template, without extra */
  57. /* border pixels */
  58. l_int32 w; /* max width of original src images */
  59. l_int32 h; /* max height of original src images */
  60. l_int32 nclass; /* current number of classes */
  61. l_int32 keep_pixaa; /* If zero, pixaa isn't filled */
  62. struct Pixaa *pixaa; /* instances for each class; unbordered */
  63. struct Pixa *pixat; /* templates for each class; bordered */
  64. /* and not dilated */
  65. struct Pixa *pixatd; /* templates for each class; bordered */
  66. /* and dilated */
  67. struct NumaHash *nahash; /* Hash table to find templates by size */
  68. struct Numa *nafgt; /* fg areas of undilated templates; */
  69. /* only used for rank < 1.0 */
  70. struct Pta *ptac; /* centroids of all bordered cc */
  71. struct Pta *ptact; /* centroids of all bordered template cc */
  72. struct Numa *naclass; /* array of class ids for each component */
  73. struct Numa *napage; /* array of page nums for each component */
  74. struct Pta *ptaul; /* array of UL corners at which the */
  75. /* template is to be placed for each */
  76. /* component */
  77. struct Pta *ptall; /* similar to ptaul, but for LL corners */
  78. };
  79. typedef struct JbClasser JBCLASSER;
  80. /* The JbData struct holds all the data required for
  81. * the compressed jbig-type representation of a set of images.
  82. * The data can be written to file, read back, and used
  83. * to regenerate an approximate version of the original,
  84. * which differs in two ways from the original:
  85. * (1) It uses a template image for each c.c. instead of the
  86. * original instance, for each occurrence on each page.
  87. * (2) It discards components with either a height or width larger
  88. * than the maximuma, given here by the lattice dimensions
  89. * used for storing the templates. */
  90. struct JbData
  91. {
  92. struct Pix *pix; /* template composite for all classes */
  93. l_int32 npages; /* number of pages */
  94. l_int32 w; /* max width of original page images */
  95. l_int32 h; /* max height of original page images */
  96. l_int32 nclass; /* number of classes */
  97. l_int32 latticew; /* lattice width for template composite */
  98. l_int32 latticeh; /* lattice height for template composite */
  99. struct Numa *naclass; /* array of class ids for each component */
  100. struct Numa *napage; /* array of page nums for each component */
  101. struct Pta *ptaul; /* array of UL corners at which the */
  102. /* template is to be placed for each */
  103. /* component */
  104. };
  105. typedef struct JbData JBDATA;
  106. /* Classifier methods */
  107. enum {
  108. JB_RANKHAUS = 0,
  109. JB_CORRELATION = 1
  110. };
  111. /* For jbGetComponents(): type of component to extract from images */
  112. enum {
  113. JB_CONN_COMPS = 0,
  114. JB_CHARACTERS = 1,
  115. JB_WORDS = 2
  116. };
  117. /* These parameters are used for naming the two files
  118. * in which the jbig2-like compressed data is stored. */
  119. #define JB_TEMPLATE_EXT ".templates.png"
  120. #define JB_DATA_EXT ".data"
  121. #endif /* LEPTONICA_JBCLASS_H */