TestPreprocessor package

Submodules

TestPreprocessor.test_Preprocessor module

This module is responsible for testing the PreprocessImages.py module.

There are two different types of tests: firstly, whether the PreprocessImages module (defined as Pp in this test) returns an image that has the same dimensions (i.e. shape), and type (i.e. numpy.ndarray) as the input image (i.e. expected image). The expected image and it’s attributes are defined below.

Secondly, it is tested whether error messages are returned if the input image is in color, while gray scale images are required by that preprocessor (i.e. binary threshold and normalization).

The actual content of the output image has to be checked manually. Alternatively the EvaluateReadDisplay.py module can be run to check whether the ReadDisplay module achieves a higher accuracy as a result of the new preprocessing output of Pp. The reason why the image content (i.e. pixels) of the Pp output are not checked (i.e. pixels_of_expected_image == pixels_of_output_image) is because even the slightest change in parameters in Pp can change the pixels of an image drastically, and it does not necessarily mean that the module does not work anymore. Additionally, a slight change in pixels can have a big impact on the accuracy of ReadDisplay. Therefore, it’s best to check the quality of the Pp output images by eye as well as through EvaluateReadDisplay.

TestPreprocessor.test_Preprocessor.assert_img_attributes(output_img)

This method asserts whether the image attributes of the output image of Pp match those of the expected image.

The two image attributes that are checked are (1) the image type, and (2) the image shape.

Parameters:output_img – The output image returned by Pp.
TestPreprocessor.test_Preprocessor.assert_img_attributes_white_boarder(output_img)

This method asserts whether the image attributes of the output image of Pp match those of the expected image. Here the expected image is larger that the original image.

The two image attributes that are checked are (1) the image type, and (2) the image shape.

Parameters:output_img – The output image returned by Pp.
TestPreprocessor.test_Preprocessor.assert_binary_thresh_error(direct_method_call, **kwargs)

This method asserts whether the Pp module returns the correct warning message when triggered.

The warning message is printed to stdout when an image is passed to the binary_threshold() function in Pp that is not gray scale. The method can be called directly (via ‘binary_threshold(img)’ or indirectly (via ‘preprocess_image(list, img)’).

If the binary threshold method is called indirectly, an extra input parameter is required which is handled by **kwargs in this function.

Parameters:
  • direct_method_call – True if binary threshold method is called directly,
  • if called indirectly. (false) –
  • kwargs – A list (‘pp_list’) containing a selection and sequence of
  • preprocessors.
TestPreprocessor.test_Preprocessor.assert_binary_adap_thresh_error(direct_method_call, **kwargs)

This method asserts whether the Pp module returns the correct warning message when triggered.

The warning message is printed to stdout when an image is passed to the binary_threshold() function in Pp that is not gray scale. The method can be called directly (via ‘binary_threshold(img)’ or indirectly (via ‘preprocess_image(list, img)’).

If the binary threshold method is called indirectly, an extra input parameter is required which is handled by **kwargs in this function.

Parameters:
  • direct_method_call – True if binary threshold method is called directly,
  • if called indirectly. (false) –
  • kwargs – A list (‘pp_list’) containing a selection and sequence of
  • preprocessors.
TestPreprocessor.test_Preprocessor.assert_normalisation_error(direct_method_call, **kwargs)

This method asserts whether the Pp module returns the correct warning message when triggered.

The warning message is printed to stdout when an image is passed to the binary_threshold() function in Pp that is not gray scale. The method can be called directly (via ‘binary_threshold(img)’ or indirectly (via ‘preprocess_image(list, img)’).

If the binary threshold method is called indirectly, an extra input parameter is required which is handled by **kwargs in this function.

Parameters:
  • direct_method_call – True if binary threshold method is called directly,
  • if called indirectly. (false) –
  • kwargs – A list (‘pp_list’) containing a selection and sequence of
  • preprocessors.
TestPreprocessor.test_Preprocessor.assert_binary_thresh_and_normalisation_error(direct_method_call, **kwargs)

This method asserts whether the Pp module returns the correct warning message when triggered.

The warning message is printed to stdout when an image is passed to the binary_threshold() function in Pp that is not gray scale. The method can be called directly (via ‘binary_threshold(img)’ or indirectly (via ‘preprocess_image(list, img)’).

If the binary threshold method is called indirectly, an extra input parameter is required which is handled by **kwargs in this function.

Parameters:
  • direct_method_call – True if binary threshold method is called directly,
  • if called indirectly. (false) –
  • kwargs – A list (‘pp_list’) containing a selection and sequence of
  • preprocessors.
TestPreprocessor.test_Preprocessor.test_individual_pp()

This test checks if each individual preprocessor method (direct call) returns the correct output.

The getattr() function is used to call a function based on a String value. For example, the string ‘erosion’ can be used to call the method erosion() in the Pp module.

The test asserts whether the output image is valid for each of the individual preprocessor methods. The binary_threshold and normalisation methods are checked with a gray scale image, the perspective_transform for both color and grey scale image, and the white_border method is checked individually as the output of this function is expected to have a larger size than the input.

TestPreprocessor.test_Preprocessor.test_default_pp()

This test checks whether the Pp module returns the correct output given the default list of preprocessors.

The list containing the default selection and sequence of preprocessors, default_pp, is passed to the Pp module. The difference between this test and test_individual_pp() is that the preprocessor methods are not called directly, but via preprocess_image() instead, which requires a list of preprocessors and image as input.

TestPreprocessor.test_Preprocessor.test_default_pp_reverse_order()

Tests whether the Pp module returns the correct output given the reversed list of default preprocessors.

The list containing the default selection and sequence of preprocessors is reversed. Therefore, three assertions are required. The first assertion checks whether the output image is correct. The second assertion checks whether the warning message is printed to stdout since ‘4’is called before ‘1’ (i.e. binary threshold before gray scale). The thirt check whether the warning message is printed to stdout since ‘8’ is called before ‘1’ (i.e. normalisation before gray scale).

TestPreprocessor.test_Preprocessor.test_pp_binary_thresh()

Tests whether the binary threshold method returns the correct warning message.

The binary threshold method is called (indirectly) without the gray scale method being called.

TestPreprocessor.test_Preprocessor.test_pp_binary_adap_thresh()

Tests whether the binary threshold method returns the correct warning message.

The binary threshold method is called (indirectly) without the gray scale method being called.

TestPreprocessor.test_Preprocessor.test_pp_normalisation()

Tests whether the normalisation method returns the correct warning message.

The normalisation method is called (indirectly) without the gray scale method being called.

TestPreprocessor.test_Preprocessor.test_pp_4_before_1()

Tests whether the binary threshold method returns the correct warning message.

The binary threshold method is called (indirectly) before the gray scale method is called.

TestPreprocessor.test_Preprocessor.test_pp_8_before_1()

Tests whether the normalisation method returns the correct warning message.

The normalisation method is called (indirectly) before the gray scale method is called.

Module contents