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

Code before:
        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
  int32_t trans_threshold; // noise tolerance
  int32_t dot_count;       // small objects
  int32_t norm_count;      // normal objects
  int32_t dud_words;       // number discarded
  int32_t ok_words;        // number remaining
  int32_t word_index;      // current word
                           // words of row
  WERD_IT word_it = row->word_list();

Review comment (suggestion):
```suggestion
  return super_norm_count < textord_noise_sncount && rejected;
```

Code after:
        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
  int32_t trans_threshold; // noise tolerance
  int32_t dot_count;       // small objects
  int32_t norm_count;      // normal objects
  int32_t dud_words;       // number discarded
  int32_t ok_words;        // number remaining
  int32_t word_index;      // current word
                           // words of row
  WERD_IT word_it = row->word_list();