Repository: tesseract-ocr/tesseract
File: src/textord/tordmain.cpp (C++)

Code before:
      } else {
        super_norm_count++;
      }
      blob_box = blob->bounding_box();
      blob_size = blob_box.width() > blob_box.height() ? blob_box.width() : blob_box.height();
      if (blob_size >= textord_noise_sizelimit * row->x_height() &&
          blob_size < row->x_height() * 2) {
        trans_threshold = blob_size / textord_noise_sizefraction;
        trans_count = blob->count_transitions(trans_threshold);
        if (trans_count < textord_noise_translimit) {
          norm_count++;
        }
      } else if (blob_box.height() > row->x_height() * 2 &&
                 (!word_it.at_first() || !blob_it.at_first())) {
        dot_count += 2;
      }
      if (testing_on) {
        tprintf("Blob at (%d,%d) -> (%d,%d), ols=%d, tc=%d, bldiff=%g\n", blob_box.left(),
                blob_box.bottom(), blob_box.right(), blob_box.top(), blob->out_list()->length(),
                trans_count, blob_box.bottom() - row->base_line(blob_box.left()));
      }
    }
  }
  bool rejected = dot_count > norm_count * textord_noise_normratio && \
                  dot_count > 2 && \
                  super_norm_count < textord_noise_sncount;
  if (textord_noise_debug) {
    tprintf("Row ending at (%d,%g):", blob_box.right(), row->base_line(blob_box.right()));
    tprintf(" R=%g, dc=%d, nc=%d, %s\n",
            norm_count > 0 ? static_cast<float>(dot_count) / norm_count : 9999, dot_count,
            norm_count,
            rejected? "REJECTED": "ACCEPTED");
  }
  return rejected;
}

/**********************************************************************
 * clean_noise_from_words
 *
 * Move blobs of words from rows of garbage into the reject blobs list.
 **********************************************************************/

void Textord::clean_noise_from_words( // remove empties
    ROW *row                          // row to clean
) {
  TBOX blob_box;           // bounding box
  C_BLOB *blob;            // current blob
  C_OUTLINE *outline;      // current outline
  WERD *word;              // current word
  int32_t blob_size;       // biggest size
  int32_t trans_count;     // no of transitions

Review comment (suggestion):
```suggestion
  bool rejected = dot_count > norm_count * textord_noise_normratio &&
                  dot_count > 2 &&
                  super_norm_count < textord_noise_sncount;
```

Code after:
      } else {
        super_norm_count++;
      }
      blob_box = blob->bounding_box();
      blob_size = blob_box.width() > blob_box.height() ? blob_box.width() : blob_box.height();
      if (blob_size >= textord_noise_sizelimit * row->x_height() &&
          blob_size < row->x_height() * 2) {
        trans_threshold = blob_size / textord_noise_sizefraction;
        trans_count = blob->count_transitions(trans_threshold);
        if (trans_count < textord_noise_translimit) {
          norm_count++;
        }
      } else if (blob_box.height() > row->x_height() * 2 &&
                 (!word_it.at_first() || !blob_it.at_first())) {
        dot_count += 2;
      }
      if (testing_on) {
        tprintf("Blob at (%d,%d) -> (%d,%d), ols=%d, tc=%d, bldiff=%g\n", blob_box.left(),
                blob_box.bottom(), blob_box.right(), blob_box.top(), blob->out_list()->length(),
                trans_count, blob_box.bottom() - row->base_line(blob_box.left()));
      }
    }
  }
  // TODO: check whether `&& super_norm_count < textord_noise_sncount`should always be added here.
  bool rejected = dot_count > norm_count * textord_noise_normratio &&
                  dot_count > 2;
  if (textord_noise_debug) {
    tprintf("Row ending at (%d,%g):", blob_box.right(), row->base_line(blob_box.right()));
    tprintf(" R=%g, dc=%d, nc=%d, %s\n",
            norm_count > 0 ? static_cast<float>(dot_count) / norm_count : 9999, dot_count,
            norm_count,
            rejected? "REJECTED": "ACCEPTED");
  }
  return super_norm_count < textord_noise_sncount && rejected;
}

/**********************************************************************
 * clean_noise_from_words
 *
 * Move blobs of words from rows of garbage into the reject blobs list.
 **********************************************************************/

void Textord::clean_noise_from_words( // remove empties
    ROW *row                          // row to clean
) {
  TBOX blob_box;           // bounding box
  C_BLOB *blob;            // current blob
  C_OUTLINE *outline;      // current outline
  WERD *word;              // current word
  int32_t blob_size;       // biggest size
  int32_t trans_count;     // no of transitions