def create_row_patterns(img, step=10): """ Extracts pixel rows from the image :param img: Source images :type img: Binary numpy array :param step: Pixel distance between each row :return: An array of row patterns from top to bottom """ h, w = img.shape row_patterns = [] for i in range(0, h, step): rle_data = ImagePreprocessor.run_length_encoding(img[i]) detailed_pattern = ImagePreprocessor.cleanup_row_noise(rle_data) row_patterns.append(detailed_pattern[:, 1]) return row_patterns
def test_cleanup_row_noise_invalid_suffix(self): data_in = numpy.array([[7, 1], [8, 0], [12, 1], [9, 0], [4, 1]]) data_out = ImagePreprocessor.cleanup_row_noise(data_in, 6) expected = numpy.array([[7, 1], [8, 0], [12, 1], [13, 0]]) numpy.testing.assert_array_equal(data_out, expected)
def test_cleanup_row_noise_double_invalid_middle(self): data_in = numpy.array([[7, 1], [2, 0], [3, 1], [9, 0], [12, 1]]) data_out = ImagePreprocessor.cleanup_row_noise(data_in, 6) expected = numpy.array([[12, 1], [9, 0], [12, 1]]) numpy.testing.assert_array_equal(data_out, expected)