<s> """<STR_LIT>""" <EOL> import StringIO <EOL> import base64 <EOL> import unittest <EOL> import zlib <EOL> import numpy as np <EOL> from cellprofiler . preferences import set_headless <EOL> set_headless ( ) <EOL> import cellprofiler . workspace as cpw <EOL> import cellprofiler . pipeline as cpp <EOL> import cellprofiler . cpimage as cpi <EOL> import cellprofiler . modules . crop as cpmc <EOL> import cellprofiler . measurements as cpm <EOL> import cellprofiler . objects as cpo <EOL> import cellprofiler . preferences as cpprefs <EOL> INPUT_IMAGE = "<STR_LIT>" <EOL> CROP_IMAGE = "<STR_LIT>" <EOL> CROP_OBJECTS = "<STR_LIT>" <EOL> CROPPING = "<STR_LIT>" <EOL> OUTPUT_IMAGE = "<STR_LIT>" <EOL> class TestCrop ( unittest . TestCase ) : <EOL> def make_workspace ( self , <EOL> input_pixels , <EOL> crop_image = None , <EOL> cropping = None , <EOL> crop_objects = None ) : <EOL> """<STR_LIT>""" <EOL> image_set_list = cpi . ImageSetList ( ) <EOL> image_set = image_set_list . get_image_set ( <NUM_LIT:0> ) <EOL> module = cpmc . Crop ( ) <EOL> module . module_num = <NUM_LIT:1> <EOL> image_set . add ( INPUT_IMAGE , cpi . Image ( input_pixels ) ) <EOL> module . image_name . value = INPUT_IMAGE <EOL> module . cropped_image_name . value = OUTPUT_IMAGE <EOL> if crop_image is not None : <EOL> image_set . add ( CROP_IMAGE , cpi . Image ( crop_image ) ) <EOL> module . image_mask_source . value = CROP_IMAGE <EOL> if cropping is not None : <EOL> image_set . add ( CROPPING , cpi . Image ( np . zeros ( cropping . shape ) , <EOL> crop_mask = cropping ) ) <EOL> module . cropping_mask_source . value = CROPPING <EOL> object_set = cpo . ObjectSet ( ) <EOL> if crop_objects is not None : <EOL> objects = cpo . Objects ( ) <EOL> objects . segmented = crop_objects <EOL> object_set . add_objects ( objects , CROP_OBJECTS ) <EOL> pipeline = cpp . Pipeline ( ) <EOL> def callback ( caller , event ) : <EOL> self . assertFalse ( isinstance ( event , cpp . RunExceptionEvent ) ) <EOL> pipeline . add_listener ( callback ) <EOL> pipeline . add_module ( module ) <EOL> m = cpm . Measurements ( ) <EOL> workspace = cpw . Workspace ( pipeline , <EOL> module , <EOL> image_set , <EOL> object_set , <EOL> m , <EOL> image_set_list ) <EOL> m . add_measurement ( cpm . IMAGE , cpm . GROUP_INDEX , <NUM_LIT:0> , image_set_number = <NUM_LIT:1> ) <EOL> m . add_measurement ( cpm . IMAGE , cpm . GROUP_NUMBER , <NUM_LIT:1> , image_set_number = <NUM_LIT:1> ) <EOL> return workspace , module <EOL> def test_00_00_zeros ( self ) : <EOL> """<STR_LIT>""" <EOL> workspace , module = self . make_workspace ( np . zeros ( ( <NUM_LIT:10> , <NUM_LIT:10> ) ) , <EOL> crop_image = np . zeros ( ( <NUM_LIT:10> , <NUM_LIT:10> ) , bool ) ) <EOL> module . shape . value = cpmc . SH_IMAGE <EOL> module . remove_rows_and_columns . value = cpmc . RM_NO <EOL> module . run ( workspace ) <EOL> output_image = workspace . image_set . get_image ( OUTPUT_IMAGE ) <EOL> self . assertTrue ( np . all ( output_image . pixel_data == <NUM_LIT:0> ) ) <EOL> self . assertTrue ( np . all ( output_image . mask == output_image . pixel_data ) ) <EOL> self . assertTrue ( np . all ( output_image . crop_mask == output_image . pixel_data ) ) <EOL> m = workspace . measurements <EOL> self . assertTrue ( '<STR_LIT>' in m . get_object_names ( ) ) <EOL> columns = module . get_measurement_columns ( workspace . pipeline ) <EOL> self . assertEqual ( len ( columns ) , <NUM_LIT:2> ) <EOL> self . assertTrue ( all ( [ x [ <NUM_LIT:0> ] == cpm . IMAGE for x in columns ] ) ) <EOL> self . assertTrue ( all ( [ x [ <NUM_LIT:2> ] == cpm . COLTYPE_INTEGER for x in columns ] ) ) <EOL> feature = '<STR_LIT>' % OUTPUT_IMAGE <EOL> self . assertTrue ( feature in [ x [ <NUM_LIT:1> ] for x in columns ] ) <EOL> self . assertTrue ( feature in m . get_feature_names ( '<STR_LIT>' ) ) <EOL> values = m . get_current_measurement ( '<STR_LIT>' , feature ) <EOL> self . assertAlmostEqual ( values , <NUM_LIT:10> * <NUM_LIT:10> ) <EOL> feature = '<STR_LIT>' % OUTPUT_IMAGE <EOL> self . assertTrue ( feature in [ x [ <NUM_LIT:1> ] for x in columns ] ) <EOL> self . assertTrue ( feature in m . get_feature_names ( '<STR_LIT>' ) ) <EOL> values = m . get_current_measurement ( '<STR_LIT>' , feature ) <EOL> self . assertEqual ( values , <NUM_LIT:0> ) <EOL> def test_00_01_zeros_and_remove_all ( self ) : <EOL> """<STR_LIT>""" <EOL> workspace , module = self . make_workspace ( np . zeros ( ( <NUM_LIT:10> , <NUM_LIT:10> ) ) , <EOL> crop_image = np . zeros ( ( <NUM_LIT:10> , <NUM_LIT:10> ) , bool ) ) <EOL> module . shape . value = cpmc . SH_IMAGE <EOL> module . remove_rows_and_columns . value = cpmc . RM_ALL <EOL> module . run ( workspace ) <EOL> output_image = workspace . image_set . get_image ( OUTPUT_IMAGE ) <EOL> self . assertEqual ( np . product ( output_image . pixel_data . shape ) , <NUM_LIT:0> ) <EOL> def test_01_01_crop_edges_with_image ( self ) : <EOL> """<STR_LIT>""" <EOL> x , y = np . mgrid [ <NUM_LIT:0> : <NUM_LIT:10> , <NUM_LIT:0> : <NUM_LIT:10> ] <EOL> input_image = x / <NUM_LIT> + y / <NUM_LIT> <EOL> crop_image = np . zeros ( ( <NUM_LIT:10> , <NUM_LIT:10> ) , bool ) <EOL> crop_image [ <NUM_LIT:2> , <NUM_LIT:3> ] = True <EOL> crop_image [ <NUM_LIT:7> , <NUM_LIT:5> ] = True <EOL> expected_image = np . zeros ( ( <NUM_LIT:6> , <NUM_LIT:3> ) , np . float32 ) <EOL> expected_image [ <NUM_LIT:0> , <NUM_LIT:0> ] = input_image [ <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> expected_image [ <NUM_LIT:5> , <NUM_LIT:2> ] = input_image [ <NUM_LIT:7> , <NUM_LIT:5> ] <EOL> workspace , module = self . make_workspace ( input_image , <EOL> crop_image = crop_image ) <EOL> module . shape . value = cpmc . SH_IMAGE <EOL> module . remove_rows_and_columns . value = cpmc . RM_EDGES <EOL> module . run ( workspace ) <EOL> output_image = workspace . image_set . get_image ( OUTPUT_IMAGE ) <EOL> self . assertTrue ( np . all ( output_image . pixel_data == expected_image ) ) <EOL> def test_01_02_crop_all_with_image ( self ) : <EOL> """<STR_LIT>""" <EOL> x , y = np . mgrid [ <NUM_LIT:0> : <NUM_LIT:10> , <NUM_LIT:0> : <NUM_LIT:10> ] <EOL> input_image = ( x / <NUM_LIT> + y / <NUM_LIT> ) . astype ( np . float32 ) <EOL> crop_image = np . zeros ( ( <NUM_LIT:10> , <NUM_LIT:10> ) , bool ) <EOL> crop_image [ <NUM_LIT:2> , <NUM_LIT:3> ] = True <EOL> crop_image [ <NUM_LIT:7> , <NUM_LIT:5> ] = True <EOL> expected_image = input_image [ ( <NUM_LIT:2> , <NUM_LIT:7> ) , : ] [ : , ( <NUM_LIT:3> , <NUM_LIT:5> ) ] <EOL> expected_image [ <NUM_LIT:1> , <NUM_LIT:0> ] = <NUM_LIT:0> <EOL> expected_image [ <NUM_LIT:0> , <NUM_LIT:1> ] = <NUM_LIT:0> <EOL> workspace , module = self . make_workspace ( input_image , <EOL> crop_image = crop_image ) <EOL> module . shape . value = cpmc . SH_IMAGE <EOL> module . remove_rows_and_columns . value = cpmc . RM_ALL <EOL> module . run ( workspace ) <EOL> output_image = workspace . image_set . get_image ( OUTPUT_IMAGE ) <EOL> self . assertTrue ( np . all ( output_image . pixel_data == expected_image ) ) <EOL> def test_02_01_crop_edges_with_cropping ( self ) : <EOL> """<STR_LIT>""" <EOL> x , y = np . mgrid [ <NUM_LIT:0> : <NUM_LIT:10> , <NUM_LIT:0> : <NUM_LIT:10> ] <EOL> input_image = ( x / <NUM_LIT> + y / <NUM_LIT> ) . astype ( np . float32 ) <EOL> crop_image = np . zeros ( ( <NUM_LIT:10> , <NUM_LIT:10> ) , bool ) <EOL> crop_image [ <NUM_LIT:2> , <NUM_LIT:3> ] = True <EOL> crop_image [ <NUM_LIT:7> , <NUM_LIT:5> ] = True <EOL> expected_image = np . zeros ( ( <NUM_LIT:6> , <NUM_LIT:3> ) ) <EOL> expected_image [ <NUM_LIT:0> , <NUM_LIT:0> ] = input_image [ <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> expected_image [ <NUM_LIT:5> , <NUM_LIT:2> ] = input_image [ <NUM_LIT:7> , <NUM_LIT:5> ] <EOL> workspace , module = self . make_workspace ( input_image , <EOL> cropping = crop_image ) <EOL> module . shape . value = cpmc . SH_CROPPING <EOL> module . remove_rows_and_columns . value = cpmc . RM_EDGES <EOL> module . run ( workspace ) <EOL> output_image = workspace . image_set . get_image ( OUTPUT_IMAGE ) <EOL> self . assertTrue ( np . all ( output_image . pixel_data == expected_image ) ) <EOL> def test_03_01_crop_with_ellipse_x_major ( self ) : <EOL> """<STR_LIT>""" <EOL> x , y = np . mgrid [ <NUM_LIT:0> : <NUM_LIT:10> , <NUM_LIT:0> : <NUM_LIT:10> ] <EOL> input_image = ( x / <NUM_LIT> + y / <NUM_LIT> ) . astype ( np . float32 ) <EOL> workspace , module = self . make_workspace ( input_image ) <EOL> module . shape . value = cpmc . SH_ELLIPSE <EOL> module . remove_rows_and_columns . value = cpmc . RM_EDGES <EOL> module . ellipse_center . set_value ( ( <NUM_LIT:4> , <NUM_LIT:5> ) ) <EOL> module . ellipse_x_radius . value = <NUM_LIT:3> <EOL> module . ellipse_y_radius . value = <NUM_LIT:2> <EOL> expected_image = input_image [ <NUM_LIT:3> : <NUM_LIT:8> , <NUM_LIT:1> : <NUM_LIT:8> ] <EOL> for i , j in ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:0> , <NUM_LIT:2> ) ) : <EOL> expected_image [ i , j ] = <NUM_LIT:0> <EOL> expected_image [ - i - <NUM_LIT:1> , j ] = <NUM_LIT:0> <EOL> expected_image [ i , - j - <NUM_LIT:1> ] = <NUM_LIT:0> <EOL> expected_image [ - i - <NUM_LIT:1> , - j - <NUM_LIT:1> ] = <NUM_LIT:0> <EOL> module . run ( workspace ) <EOL> output_image = workspace . image_set . get_image ( OUTPUT_IMAGE ) <EOL> self . assertTrue ( np . all ( output_image . pixel_data == expected_image ) ) <EOL> def test_03_02_crop_with_ellipse_y_major ( self ) : <EOL> x , y = np . mgrid [ <NUM_LIT:0> : <NUM_LIT:10> , <NUM_LIT:0> : <NUM_LIT:10> ] <EOL> input_image = ( x / <NUM_LIT> + y / <NUM_LIT> ) . astype ( np . float32 ) <EOL> workspace , module = self . make_workspace ( input_image ) <EOL> module . shape . value = cpmc . SH_ELLIPSE <EOL> module . remove_rows_and_columns . value = cpmc . RM_EDGES <EOL> module . ellipse_center . set_value ( ( <NUM_LIT:5> , <NUM_LIT:4> ) ) <EOL> module . ellipse_x_radius . value = <NUM_LIT:2> <EOL> module . ellipse_y_radius . value = <NUM_LIT:3> <EOL> expected_image = input_image [ <NUM_LIT:1> : <NUM_LIT:8> , <NUM_LIT:3> : <NUM_LIT:8> ] <EOL> for i , j in ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:2> , <NUM_LIT:0> ) ) : <EOL> expected_image [ i , j ] = <NUM_LIT:0> <EOL> expected_image [ - i - <NUM_LIT:1> , j ] = <NUM_LIT:0> <EOL> expected_image [ i , - j - <NUM_LIT:1> ] = <NUM_LIT:0> <EOL> expected_image [ - i - <NUM_LIT:1> , - j - <NUM_LIT:1> ] = <NUM_LIT:0> <EOL> module . run ( workspace ) <EOL> output_image = workspace . image_set . get_image ( OUTPUT_IMAGE ) <EOL> self . assertTrue ( np . all ( output_image . pixel_data == expected_image ) ) <EOL> def test_04_01_crop_with_rectangle ( self ) : <EOL> x , y = np . mgrid [ <NUM_LIT:0> : <NUM_LIT:10> , <NUM_LIT:0> : <NUM_LIT:10> ] <EOL> input_image = ( x / <NUM_LIT> + y / <NUM_LIT> ) . astype ( np . float32 ) <EOL> expected_image = input_image [ <NUM_LIT:2> : <NUM_LIT:8> , <NUM_LIT:1> : <NUM_LIT:9> ] <EOL> workspace , module = self . make_workspace ( input_image ) <EOL> module . shape . value = cpmc . SH_RECTANGLE <EOL> module . horizontal_limits . set_value ( ( <NUM_LIT:1> , <NUM_LIT:9> ) ) <EOL> module . vertical_limits . set_value ( ( <NUM_LIT:2> , <NUM_LIT:8> ) ) <EOL> module . remove_rows_and_columns . value = cpmc . RM_EDGES <EOL> module . run ( workspace ) <EOL> output_image = workspace . image_set . get_image ( OUTPUT_IMAGE ) <EOL> self . assertTrue ( np . all ( output_image . pixel_data == expected_image ) ) <EOL> def test_04_02_crop_with_rectangle_unbounded_xmin ( self ) : <EOL> x , y = np . mgrid [ <NUM_LIT:0> : <NUM_LIT:10> , <NUM_LIT:0> : <NUM_LIT:10> ] <EOL> input_image = ( x / <NUM_LIT> + y / <NUM_LIT> ) . astype ( np . float32 ) <EOL> expected_image = input_image [ <NUM_LIT:2> : <NUM_LIT:8> , : <NUM_LIT:9> ] <EOL> workspace , module = self . make_workspace ( input_image ) <EOL> module . shape . value = cpmc . SH_RECTANGLE <EOL> module . horizontal_limits . set_value ( ( <NUM_LIT:0> , <NUM_LIT:9> ) ) <EOL> module . vertical_limits . set_value ( ( <NUM_LIT:2> , <NUM_LIT:8> ) ) <EOL> module . remove_rows_and_columns . value = cpmc . RM_EDGES <EOL> module . run ( workspace ) <EOL> output_image = workspace . image_set . get_image ( OUTPUT_IMAGE ) <EOL> self . assertTrue ( np . all ( output_image . pixel_data == expected_image ) ) <EOL> def test_04_03_crop_with_rectangle_unbounded_xmax ( self ) : <EOL> x , y = np . mgrid [ <NUM_LIT:0> : <NUM_LIT:10> , <NUM_LIT:0> : <NUM_LIT:10> ] <EOL> input_image = ( x / <NUM_LIT> + y / <NUM_LIT> ) . astype ( np . float32 ) <EOL> expected_image = input_image [ <NUM_LIT:2> : <NUM_LIT:8> , <NUM_LIT:1> : ] <EOL> workspace , module = self . make_workspace ( input_image ) <EOL> module . shape . value = cpmc . SH_RECTANGLE <EOL> module . horizontal_limits . set_value ( ( <NUM_LIT:1> , "<STR_LIT:end>" ) ) <EOL> module . vertical_limits . set_value ( ( <NUM_LIT:2> , <NUM_LIT:8> ) ) <EOL> module . remove_rows_and_columns . value = cpmc . RM_EDGES <EOL> module . run ( workspace ) <EOL> output_image = workspace . image_set . get_image ( OUTPUT_IMAGE ) <EOL> self . assertTrue ( np . all ( output_image . pixel_data == expected_image ) ) <EOL> def test_04_04_crop_with_rectangle_unbounded_ymin ( self ) : <EOL> x , y = np . mgrid [ <NUM_LIT:0> : <NUM_LIT:10> , <NUM_LIT:0> : <NUM_LIT:10> ] <EOL> input_image = ( x / <NUM_LIT> + y / <NUM_LIT> ) . astype ( np . float32 ) <EOL> expected_image = input_image [ : <NUM_LIT:8> , <NUM_LIT:1> : <NUM_LIT:9> ] <EOL> workspace , module = self . make_workspace ( input_image ) <EOL> module . shape . value = cpmc . SH_RECTANGLE <EOL> module . horizontal_limits . set_value ( ( <NUM_LIT:1> , <NUM_LIT:9> ) ) <EOL> module . vertical_limits . set_value ( ( <NUM_LIT:0> , <NUM_LIT:8> ) ) <EOL> module . remove_rows_and_columns . value = cpmc . RM_EDGES <EOL> module . run ( workspace ) <EOL> output_image = workspace . image_set . get_image ( OUTPUT_IMAGE ) <EOL> self . assertTrue ( np . all ( output_image . pixel_data == expected_image ) ) <EOL> def test_04_05_crop_with_rectangle_unbounded_ymax ( self ) : <EOL> x , y = np . mgrid [ <NUM_LIT:0> : <NUM_LIT:10> , <NUM_LIT:0> : <NUM_LIT:10> ] <EOL> input_image = ( x / <NUM_LIT> + y / <NUM_LIT> ) . astype ( np . float32 ) <EOL> expected_image = input_image [ <NUM_LIT:2> : , <NUM_LIT:1> : <NUM_LIT:9> ] <EOL> workspace , module = self . make_workspace ( input_image ) <EOL> module . shape . value = cpmc . SH_RECTANGLE <EOL> module . horizontal_limits . set_value ( ( <NUM_LIT:1> , <NUM_LIT:9> ) ) <EOL> module . vertical_limits . set_value ( ( <NUM_LIT:2> , "<STR_LIT:end>" ) ) <EOL> module . remove_rows_and_columns . value = cpmc . RM_EDGES <EOL> module . run ( workspace ) <EOL> output_image = workspace . image_set . get_image ( OUTPUT_IMAGE ) <EOL> self . assertTrue ( np . all ( output_image . pixel_data == expected_image ) ) <EOL> def test_04_06_crop_color_with_rectangle ( self ) : <EOL> '''<STR_LIT>''' <EOL> i , j , k = np . mgrid [ <NUM_LIT:0> : <NUM_LIT:10> , <NUM_LIT:0> : <NUM_LIT:10> , <NUM_LIT:0> : <NUM_LIT:3> ] <EOL> input_image = ( i / <NUM_LIT> + j / <NUM_LIT> + k ) . astype ( np . float32 ) <EOL> expected_image = input_image [ <NUM_LIT:2> : <NUM_LIT:8> , <NUM_LIT:1> : <NUM_LIT:9> , : ] <EOL> workspace , module = self . make_workspace ( input_image ) <EOL> module . shape . value = cpmc . SH_RECTANGLE <EOL> module . horizontal_limits . set_value ( ( <NUM_LIT:1> , <NUM_LIT:9> ) ) <EOL> module . vertical_limits . set_value ( ( <NUM_LIT:2> , <NUM_LIT:8> ) ) <EOL> module . remove_rows_and_columns . value = cpmc . RM_EDGES <EOL> module . run ( workspace ) <EOL> output_image = workspace . image_set . get_image ( OUTPUT_IMAGE ) <EOL> self . assertTrue ( np . all ( output_image . pixel_data == expected_image ) ) <EOL> def test_05_01_crop_image_plate_fixup ( self ) : <EOL> x , y = np . mgrid [ <NUM_LIT:0> : <NUM_LIT:10> , <NUM_LIT:0> : <NUM_LIT:10> ] <EOL> input_image = ( x / <NUM_LIT> + y / <NUM_LIT> ) . astype ( np . float32 ) <EOL> crop_image = np . zeros ( ( <NUM_LIT:10> , <NUM_LIT:10> ) , bool ) <EOL> crop_image [ <NUM_LIT:2> : , <NUM_LIT:1> : <NUM_LIT:9> ] = True <EOL> crop_image [ <NUM_LIT:1> , ( <NUM_LIT:1> , <NUM_LIT:4> ) ] = True <EOL> expected_image = input_image [ <NUM_LIT:2> : , <NUM_LIT:1> : <NUM_LIT:9> ] <EOL> workspace , module = self . make_workspace ( input_image , <EOL> crop_image = crop_image ) <EOL> module . shape . value = cpmc . SH_IMAGE <EOL> module . horizontal_limits . set_value ( ( <NUM_LIT:0> , "<STR_LIT:end>" ) ) <EOL> module . vertical_limits . set_value ( ( <NUM_LIT:0> , "<STR_LIT:end>" ) ) <EOL> module . remove_rows_and_columns . value = cpmc . RM_EDGES <EOL> module . use_plate_fix . value = True <EOL> module . run ( workspace ) <EOL> output_image = workspace . image_set . get_image ( OUTPUT_IMAGE ) <EOL> self . assertTrue ( np . all ( output_image . pixel_data == expected_image ) ) <EOL> def test_05_02_crop_image_plate_fixup_with_rectangle ( self ) : <EOL> x , y = np . mgrid [ <NUM_LIT:0> : <NUM_LIT:10> , <NUM_LIT:0> : <NUM_LIT:10> ] <EOL> input_image = ( x / <NUM_LIT> + y / <NUM_LIT> ) . astype ( np . float32 ) <EOL> crop_image = np . zeros ( ( <NUM_LIT:10> , <NUM_LIT:10> ) , bool ) <EOL> crop_image [ <NUM_LIT:1> : , <NUM_LIT:1> : <NUM_LIT:9> ] = True <EOL> expected_image = input_image [ <NUM_LIT:2> : , <NUM_LIT:1> : <NUM_LIT:9> ] <EOL> workspace , module = self . make_workspace ( input_image , <EOL> crop_image = crop_image ) <EOL> module . shape . value = cpmc . SH_IMAGE <EOL> module . horizontal_limits . set_value ( ( <NUM_LIT:0> , "<STR_LIT:end>" ) ) <EOL> module . vertical_limits . set_value ( ( <NUM_LIT:2> , "<STR_LIT:end>" ) ) <EOL> module . remove_rows_and_columns . value = cpmc . RM_EDGES <EOL> module . use_plate_fix . value = True <EOL> module . run ( workspace ) <EOL> output_image = workspace . image_set . get_image ( OUTPUT_IMAGE ) <EOL> self . assertTrue ( np . all ( output_image . pixel_data == expected_image ) ) <EOL> def test_05_03_crop_color_image_plate_fixup ( self ) : <EOL> x , y , z = np . mgrid [ <NUM_LIT:0> : <NUM_LIT:10> , <NUM_LIT:0> : <NUM_LIT:10> , <NUM_LIT:0> : <NUM_LIT:3> ] <EOL> input_image = ( x / <NUM_LIT> + y / <NUM_LIT> + z / <NUM_LIT> ) . astype ( np . float32 ) <EOL> crop_image = np . zeros ( ( <NUM_LIT:10> , <NUM_LIT:10> ) , bool ) <EOL> crop_image [ <NUM_LIT:2> : , <NUM_LIT:1> : <NUM_LIT:9> ] = True <EOL> crop_image [ <NUM_LIT:1> , ( <NUM_LIT:1> , <NUM_LIT:4> ) ] = True <EOL> expected_image = input_image [ <NUM_LIT:2> : , <NUM_LIT:1> : <NUM_LIT> : ] <EOL> workspace , module = self . make_workspace ( input_image , <EOL> crop_image = crop_image ) <EOL> module . shape . value = cpmc . SH_IMAGE <EOL> module . horizontal_limits . set_value ( ( <NUM_LIT:0> , "<STR_LIT:end>" ) ) <EOL> module . vertical_limits . set_value ( ( <NUM_LIT:0> , "<STR_LIT:end>" ) ) <EOL> module . remove_rows_and_columns . value = cpmc . RM_EDGES <EOL> module . use_plate_fix . value = True <EOL> module . run ( workspace ) <EOL> output_image = workspace . image_set . get_image ( OUTPUT_IMAGE ) <EOL> self . assertTrue ( np . all ( output_image . pixel_data == expected_image ) ) <EOL> def test_06_01_mask_with_objects ( self ) : <EOL> np . random . seed ( ) <EOL> input_image = np . random . uniform ( size = ( <NUM_LIT:20> , <NUM_LIT:10> ) ) <EOL> input_objects = np . zeros ( ( <NUM_LIT:20> , <NUM_LIT:10> ) , dtype = int ) <EOL> input_objects [ <NUM_LIT:2> : <NUM_LIT:7> , <NUM_LIT:3> : <NUM_LIT:8> ] = <NUM_LIT:1> <EOL> input_objects [ <NUM_LIT:12> : <NUM_LIT> , <NUM_LIT:3> : <NUM_LIT:8> ] = <NUM_LIT:2> <EOL> workspace , module = self . make_workspace ( input_image , <EOL> crop_objects = input_objects ) <EOL> module . shape . value = cpmc . SH_OBJECTS <EOL> module . objects_source . value = CROP_OBJECTS <EOL> module . use_plate_fix . value = False <EOL> module . remove_rows_and_columns . value = cpmc . RM_NO <EOL> module . run ( workspace ) <EOL> output_image = workspace . image_set . get_image ( OUTPUT_IMAGE ) <EOL> self . assertTrue ( output_image . has_masking_objects ) <EOL> self . assertTrue ( np . all ( input_objects == output_image . labels ) ) <EOL> self . assertTrue ( np . all ( output_image . mask == ( input_objects > <NUM_LIT:0> ) ) ) <EOL> def test_06_02_crop_with_objects ( self ) : <EOL> np . random . seed ( ) <EOL> input_image = np . random . uniform ( size = ( <NUM_LIT:20> , <NUM_LIT:10> ) ) <EOL> input_objects = np . zeros ( ( <NUM_LIT:20> , <NUM_LIT:10> ) , dtype = int ) <EOL> input_objects [ <NUM_LIT:2> : <NUM_LIT:7> , <NUM_LIT:3> : <NUM_LIT:8> ] = <NUM_LIT:1> <EOL> input_objects [ <NUM_LIT:12> : <NUM_LIT> , <NUM_LIT:3> : <NUM_LIT:8> ] = <NUM_LIT:2> <EOL> workspace , module = self . make_workspace ( input_image , <EOL> crop_objects = input_objects ) <EOL> module . shape . value = cpmc . SH_OBJECTS <EOL> module . objects_source . value = CROP_OBJECTS <EOL> module . remove_rows_and_columns . value = cpmc . RM_EDGES <EOL> module . use_plate_fix . value = False <EOL> module . run ( workspace ) <EOL> output_image = workspace . image_set . get_image ( OUTPUT_IMAGE ) <EOL> self . assertTrue ( output_image . has_masking_objects ) <EOL> self . assertTrue ( np . all ( input_objects [ <NUM_LIT:2> : <NUM_LIT> , <NUM_LIT:3> : <NUM_LIT:8> ] == output_image . labels ) ) <EOL> self . assertTrue ( np . all ( output_image . mask == ( input_objects [ <NUM_LIT:2> : <NUM_LIT> , <NUM_LIT:3> : <NUM_LIT:8> ] > <NUM_LIT:0> ) ) ) <EOL> self . assertTrue ( np . all ( output_image . crop_mask == ( input_objects > <NUM_LIT:0> ) ) ) <EOL> def test_07_01_load_matlab_pipeline ( self ) : <EOL> u64data = '<STR_LIT>' <EOL> data = base64 . b64decode ( u64data ) <EOL> pipeline = cpp . Pipeline ( ) <EOL> pipeline . load ( StringIO . StringIO ( data ) ) <EOL> self . assertEqual ( len ( pipeline . modules ( ) ) , <NUM_LIT:4> ) <EOL> self . assertTrue ( all ( [ isinstance ( module , cpmc . Crop ) <EOL> for module in pipeline . modules ( ) [ <NUM_LIT:1> : ] ] ) ) <EOL> module = pipeline . modules ( ) [ <NUM_LIT:1> ] <EOL> self . assertEqual ( module . image_name . value , "<STR_LIT>" ) <EOL> self . assertEqual ( module . cropped_image_name . value , "<STR_LIT>" ) <EOL> self . assertEqual ( module . shape . value , cpmc . SH_ELLIPSE ) <EOL> self . assertEqual ( module . individual_or_once , cpmc . IO_FIRST ) <EOL> self . assertEqual ( module . ellipse_center . x , <NUM_LIT:200> ) <EOL> self . assertEqual ( module . ellipse_center . y , <NUM_LIT> ) <EOL> self . assertEqual ( module . ellipse_x_radius . value , <NUM_LIT> ) <EOL> self . assertEqual ( module . ellipse_y_radius . value , <NUM_LIT:200> ) <EOL> self . assertTrue ( module . remove_rows_and_columns ) <EOL> module = pipeline . modules ( ) [ <NUM_LIT:2> ] <EOL> self . assertEqual ( module . image_name . value , "<STR_LIT>" ) <EOL> self . assertEqual ( module . cropped_image_name . value , "<STR_LIT>" ) <EOL> self . assertEqual ( module . cropping_mask_source . value , "<STR_LIT>" ) <EOL> self . assertEqual ( module . shape . value , cpmc . SH_CROPPING ) <EOL> self . assertFalse ( module . use_plate_fix . value ) <EOL> self . assertTrue ( module . remove_rows_and_columns . value ) <EOL> module = pipeline . modules ( ) [ <NUM_LIT:3> ] <EOL> self . assertEqual ( module . image_name . value , "<STR_LIT>" ) <EOL> self . assertEqual ( module . cropped_image_name . value , "<STR_LIT>" ) <EOL> self . assertEqual ( module . shape . value , cpmc . SH_CROPPING ) <EOL> self . assertEqual ( module . cropping_mask_source . value , "<STR_LIT>" ) <EOL> self . assertFalse ( module . use_plate_fix . value ) <EOL> self . assertTrue ( module . remove_rows_and_columns . value ) <EOL> def test_07_02_load_v2 ( self ) : <EOL> data = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> pipeline = cpp . Pipeline ( ) <EOL> def callback ( caller , event ) : <EOL> self . assertFalse ( isinstance ( event , cpp . LoadExceptionEvent ) ) <EOL> pipeline . add_listener ( callback ) <EOL> pipeline . load ( StringIO . StringIO ( zlib . decompress ( base64 . b64decode ( data ) ) ) ) <EOL> self . assertEqual ( len ( pipeline . modules ( ) ) , <NUM_LIT:4> ) <EOL> self . assertTrue ( all ( [ isinstance ( module , cpmc . Crop ) <EOL> for module in pipeline . modules ( ) [ <NUM_LIT:1> : ] ] ) ) <EOL> module = pipeline . modules ( ) [ <NUM_LIT:1> ] <EOL> self . assertEqual ( module . image_name . value , "<STR_LIT>" ) <EOL> self . assertEqual ( module . cropped_image_name . value , "<STR_LIT>" ) <EOL> self . assertEqual ( module . shape . value , cpmc . SH_ELLIPSE ) <EOL> self . assertEqual ( module . individual_or_once , cpmc . IO_FIRST ) <EOL> self . assertEqual ( module . ellipse_center . x , <NUM_LIT:200> ) <EOL> self . assertEqual ( module . ellipse_center . y , <NUM_LIT> ) <EOL> self . assertEqual ( module . ellipse_x_radius . value , <NUM_LIT> ) <EOL> self . assertEqual ( module . ellipse_y_radius . value , <NUM_LIT:200> ) <EOL> self . assertTrue ( module . remove_rows_and_columns ) <EOL> module = pipeline . modules ( ) [ <NUM_LIT:2> ] <EOL> self . assertEqual ( module . image_name . value , "<STR_LIT>" ) <EOL> self . assertEqual ( module . cropped_image_name . value , "<STR_LIT>" ) <EOL> self . assertEqual ( module . cropping_mask_source . value , "<STR_LIT>" ) <EOL> self . assertEqual ( module . shape . value , cpmc . SH_CROPPING ) <EOL> self . assertFalse ( module . use_plate_fix . value ) <EOL> self . assertTrue ( module . remove_rows_and_columns . value ) <EOL> module = pipeline . modules ( ) [ <NUM_LIT:3> ] <EOL> self . assertEqual ( module . image_name . value , "<STR_LIT>" ) <EOL> self . assertEqual ( module . cropped_image_name . value , "<STR_LIT>" ) <EOL> self . assertEqual ( module . shape . value , cpmc . SH_CROPPING ) <EOL> self . assertEqual ( module . cropping_mask_source . value , "<STR_LIT>" ) <EOL> self . assertFalse ( module . use_plate_fix . value ) <EOL> self . assertTrue ( module . remove_rows_and_columns . value ) </s>
