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_run_length_encoding_normal_array(self):
     data_in = numpy.array([1, 1, 3, 2, 3, 3, 3, 2, 2, 1, 4, 4])
     data_out = ImagePreprocessor.run_length_encoding(data_in)
     expected = numpy.array([[2, 1], [1, 3], [1, 2], [3, 3], [2, 2], [1, 1],
                             [2, 4]])
     numpy.testing.assert_array_equal(data_out, expected)
 def test_run_length_encoding_empty(self):
     data_in = numpy.array([])
     data_out = ImagePreprocessor.run_length_encoding(data_in)
     expected = numpy.array([])
     numpy.testing.assert_array_equal(data_out, expected)