jbclass.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. * \file jbclass.h
  30. *
  31. * JbClasser
  32. * JbData
  33. */
  34. /*!
  35. * <pre>
  36. * The JbClasser struct holds all the data accumulated during the
  37. * classification process that can be used for a compressed
  38. * jbig2-type representation of a set of images. This is created
  39. * in an initialization process and added to as the selected components
  40. * on each successive page are analyzed.
  41. * </pre>
  42. */
  43. struct JbClasser
  44. {
  45. struct Sarray *safiles; /*!< input page image file names */
  46. l_int32 method; /*!< JB_RANKHAUS, JB_CORRELATION */
  47. l_int32 components; /*!< JB_CONN_COMPS, JB_CHARACTERS or */
  48. /*!< JB_WORDS */
  49. l_int32 maxwidth; /*!< max component width allowed */
  50. l_int32 maxheight; /*!< max component height allowed */
  51. l_int32 npages; /*!< number of pages already processed */
  52. l_int32 baseindex; /*!< number components already processed */
  53. /*!< on fully processed pages */
  54. struct Numa *nacomps; /*!< number of components on each page */
  55. l_int32 sizehaus; /*!< size of square struct elem for haus */
  56. l_float32 rankhaus; /*!< rank val of haus match, each way */
  57. l_float32 thresh; /*!< thresh value for correlation score */
  58. l_float32 weightfactor; /*!< corrects thresh value for heaver */
  59. /*!< components; use 0 for no correction */
  60. struct Numa *naarea; /*!< w * h of each template, without */
  61. /*!< extra border pixels */
  62. l_int32 w; /*!< max width of original src images */
  63. l_int32 h; /*!< max height of original src images */
  64. l_int32 nclass; /*!< current number of classes */
  65. l_int32 keep_pixaa; /*!< If zero, pixaa isn't filled */
  66. struct Pixaa *pixaa; /*!< instances for each class; unbordered */
  67. struct Pixa *pixat; /*!< templates for each class; bordered */
  68. /*!< and not dilated */
  69. struct Pixa *pixatd; /*!< templates for each class; bordered */
  70. /*!< and dilated */
  71. struct L_DnaHash *dahash; /*!< Hash table to find templates by size */
  72. struct Numa *nafgt; /*!< fg areas of undilated templates; */
  73. /*!< only used for rank < 1.0 */
  74. struct Pta *ptac; /*!< centroids of all bordered cc */
  75. struct Pta *ptact; /*!< centroids of all bordered template cc */
  76. struct Numa *naclass; /*!< array of class ids for each component */
  77. struct Numa *napage; /*!< array of page nums for each component */
  78. struct Pta *ptaul; /*!< array of UL corners at which the */
  79. /*!< template is to be placed for each */
  80. /*!< component */
  81. struct Pta *ptall; /*!< similar to ptaul, but for LL corners */
  82. };
  83. typedef struct JbClasser JBCLASSER;
  84. /*!
  85. * <pre>
  86. * The JbData struct holds all the data required for
  87. * the compressed jbig-type representation of a set of images.
  88. * The data can be written to file, read back, and used
  89. * to regenerate an approximate version of the original,
  90. * which differs in two ways from the original:
  91. * (1) It uses a template image for each c.c. instead of the
  92. * original instance, for each occurrence on each page.
  93. * (2) It discards components with either a height or width larger
  94. * than the maximuma, given here by the lattice dimensions
  95. * used for storing the templates.
  96. * </pre>
  97. */
  98. struct JbData
  99. {
  100. struct Pix *pix; /*!< template composite for all classes */
  101. l_int32 npages; /*!< number of pages */
  102. l_int32 w; /*!< max width of original page images */
  103. l_int32 h; /*!< max height of original page images */
  104. l_int32 nclass; /*!< number of classes */
  105. l_int32 latticew; /*!< lattice width for template composite */
  106. l_int32 latticeh; /*!< lattice height for template composite */
  107. struct Numa *naclass; /*!< array of class ids for each component */
  108. struct Numa *napage; /*!< array of page nums for each component */
  109. struct Pta *ptaul; /*!< array of UL corners at which the */
  110. /*!< template is to be placed for each */
  111. /*!< component */
  112. };
  113. typedef struct JbData JBDATA;
  114. /*! Classifier methods */
  115. enum {
  116. JB_RANKHAUS = 0,
  117. JB_CORRELATION = 1
  118. };
  119. /*! For jbGetComponents(): type of component to extract from images */
  120. enum {
  121. JB_CONN_COMPS = 0,
  122. JB_CHARACTERS = 1,
  123. JB_WORDS = 2
  124. };
  125. /*! These parameters are used for naming the two files
  126. * in which the jbig2-like compressed data is stored. */
  127. #define JB_TEMPLATE_EXT ".templates.png"
  128. #define JB_DATA_EXT ".data"
  129. #endif /* LEPTONICA_JBCLASS_H */