<s> '''<STR_LIT>''' <EOL> import numpy as np <EOL> import cellprofiler . cpimage as cpi <EOL> import cellprofiler . cpmodule as cpm <EOL> import cellprofiler . settings as cps <EOL> from cellprofiler . settings import YES , NO <EOL> CC_GRAYSCALE = "<STR_LIT>" <EOL> CC_COLOR = "<STR_LIT>" <EOL> CC_ALL = [ CC_COLOR , CC_GRAYSCALE ] <EOL> class InvertForPrinting ( cpm . CPModule ) : <EOL> module_name = "<STR_LIT>" <EOL> category = '<STR_LIT>' <EOL> variable_revision_number = <NUM_LIT:1> <EOL> def create_settings ( self ) : <EOL> self . input_color_choice = cps . Choice ( <EOL> "<STR_LIT>" , CC_ALL , doc = """<STR_LIT>""" ) <EOL> self . wants_red_input = cps . Binary ( <EOL> "<STR_LIT>" , True , doc = """<STR_LIT>""" % globals ( ) ) <EOL> self . red_input_image = cps . ImageNameSubscriber ( <EOL> "<STR_LIT>" , cps . NONE ) <EOL> self . wants_green_input = cps . Binary ( <EOL> "<STR_LIT>" , True , doc = """<STR_LIT>""" % globals ( ) ) <EOL> self . green_input_image = cps . ImageNameSubscriber ( <EOL> "<STR_LIT>" , cps . NONE ) <EOL> self . wants_blue_input = cps . Binary ( <EOL> "<STR_LIT>" , True , doc = """<STR_LIT>""" % globals ( ) ) <EOL> self . blue_input_image = cps . ImageNameSubscriber ( <EOL> "<STR_LIT>" , cps . NONE ) <EOL> self . color_input_image = cps . ImageNameSubscriber ( <EOL> "<STR_LIT>" , cps . NONE , doc = '''<STR_LIT>''' ) <EOL> self . output_color_choice = cps . Choice ( <EOL> "<STR_LIT>" , CC_ALL , doc = """<STR_LIT>""" ) <EOL> self . wants_red_output = cps . Binary ( <EOL> "<STR_LIT>" % globals ( ) , True ) <EOL> self . red_output_image = cps . ImageNameProvider ( <EOL> "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . wants_green_output = cps . Binary ( <EOL> "<STR_LIT>" % globals ( ) , True ) <EOL> self . green_output_image = cps . ImageNameProvider ( <EOL> "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . wants_blue_output = cps . Binary ( <EOL> "<STR_LIT>" % globals ( ) , True ) <EOL> self . blue_output_image = cps . ImageNameProvider ( <EOL> "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . color_output_image = cps . ImageNameProvider ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , doc = '''<STR_LIT>''' ) <EOL> def settings ( self ) : <EOL> '''<STR_LIT>''' <EOL> return [ self . input_color_choice , <EOL> self . wants_red_input , self . red_input_image , <EOL> self . wants_green_input , self . green_input_image , <EOL> self . wants_blue_input , self . blue_input_image , <EOL> self . color_input_image , <EOL> self . output_color_choice , <EOL> self . wants_red_output , self . red_output_image , <EOL> self . wants_green_output , self . green_output_image , <EOL> self . wants_blue_output , self . blue_output_image , <EOL> self . color_output_image ] <EOL> def help_settings ( self ) : <EOL> return [ self . input_color_choice , <EOL> self . wants_red_input , self . red_input_image , <EOL> self . wants_green_input , self . green_input_image , <EOL> self . wants_blue_input , self . blue_input_image , <EOL> self . color_input_image , <EOL> self . output_color_choice , <EOL> self . color_output_image , <EOL> self . wants_red_output , self . red_output_image , <EOL> self . wants_green_output , self . green_output_image , <EOL> self . wants_blue_output , self . blue_output_image ] <EOL> def visible_settings ( self ) : <EOL> '''<STR_LIT>''' <EOL> result = [ self . input_color_choice ] <EOL> if self . input_color_choice == CC_GRAYSCALE : <EOL> for wants_input , input_image in ( ( self . wants_red_input , self . red_input_image ) , <EOL> ( self . wants_green_input , self . green_input_image ) , <EOL> ( self . wants_blue_input , self . blue_input_image ) ) : <EOL> result += [ wants_input ] <EOL> if wants_input . value : <EOL> result += [ input_image ] <EOL> else : <EOL> result += [ self . color_input_image ] <EOL> result += [ self . output_color_choice ] <EOL> if self . output_color_choice == CC_GRAYSCALE : <EOL> for wants_output , output_image in ( ( self . wants_red_output , self . red_output_image ) , <EOL> ( self . wants_green_output , self . green_output_image ) , <EOL> ( self . wants_blue_output , self . blue_output_image ) ) : <EOL> result += [ wants_output ] <EOL> if wants_output . value : <EOL> result += [ output_image ] <EOL> else : <EOL> result += [ self . color_output_image ] <EOL> return result <EOL> def validate_module ( self , pipeline ) : <EOL> '''<STR_LIT>''' <EOL> if ( self . input_color_choice == CC_GRAYSCALE and <EOL> ( not self . wants_red_input . value ) and <EOL> ( not self . wants_green_input . value ) and <EOL> ( not self . wants_blue_input . value ) ) : <EOL> raise cps . ValidationError ( "<STR_LIT>" , <EOL> self . wants_red_input ) <EOL> def run ( self , workspace ) : <EOL> image_set = workspace . image_set <EOL> shape = None <EOL> if self . input_color_choice == CC_GRAYSCALE : <EOL> if self . wants_red_input . value : <EOL> red_image = image_set . get_image ( <EOL> self . red_input_image . value , <EOL> must_be_grayscale = True ) . pixel_data <EOL> shape = red_image . shape <EOL> else : <EOL> red_image = <NUM_LIT:0> <EOL> if self . wants_green_input . value : <EOL> green_image = image_set . get_image ( <EOL> self . green_input_image . value , <EOL> must_be_grayscale = True ) . pixel_data <EOL> shape = green_image . shape <EOL> else : <EOL> green_image = <NUM_LIT:0> <EOL> if self . wants_blue_input . value : <EOL> blue_image = image_set . get_image ( <EOL> self . blue_input_image . value , <EOL> must_be_grayscale = True ) . pixel_data <EOL> shape = blue_image . shape <EOL> else : <EOL> blue_image = <NUM_LIT:0> <EOL> color_image = np . zeros ( ( shape [ <NUM_LIT:0> ] , shape [ <NUM_LIT:1> ] , <NUM_LIT:3> ) ) <EOL> color_image [ : , : , <NUM_LIT:0> ] = red_image <EOL> color_image [ : , : , <NUM_LIT:1> ] = green_image <EOL> color_image [ : , : , <NUM_LIT:2> ] = blue_image <EOL> red_image = color_image [ : , : , <NUM_LIT:0> ] <EOL> green_image = color_image [ : , : , <NUM_LIT:1> ] <EOL> blue_image = color_image [ : , : , <NUM_LIT:2> ] <EOL> elif self . input_color_choice == CC_COLOR : <EOL> color_image = image_set . get_image ( <EOL> self . color_input_image . value , <EOL> must_be_color = True ) . pixel_data <EOL> red_image = color_image [ : , : , <NUM_LIT:0> ] <EOL> green_image = color_image [ : , : , <NUM_LIT:1> ] <EOL> blue_image = color_image [ : , : , <NUM_LIT:2> ] <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" % <EOL> self . input_color_choice . value ) <EOL> inverted_red = ( <NUM_LIT:1> - green_image ) * ( <NUM_LIT:1> - blue_image ) <EOL> inverted_green = ( <NUM_LIT:1> - red_image ) * ( <NUM_LIT:1> - blue_image ) <EOL> inverted_blue = ( <NUM_LIT:1> - red_image ) * ( <NUM_LIT:1> - green_image ) <EOL> inverted_color = np . dstack ( ( inverted_red , inverted_green , inverted_blue ) ) <EOL> if self . output_color_choice == CC_GRAYSCALE : <EOL> for wants_output , output_image_name , output_image in ( ( self . wants_red_output , self . red_output_image , inverted_red ) , <EOL> ( self . wants_green_output , self . green_output_image , inverted_green ) , <EOL> ( self . wants_blue_output , self . blue_output_image , inverted_blue ) ) : <EOL> if wants_output . value : <EOL> image = cpi . Image ( output_image ) <EOL> image_set . add ( output_image_name . value , image ) <EOL> elif self . output_color_choice == CC_COLOR : <EOL> image = cpi . Image ( inverted_color ) <EOL> image_set . add ( self . color_output_image . value , image ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" % <EOL> self . output_color_choice . value ) <EOL> if self . show_window : <EOL> workspace . display_data . color_image = color_image <EOL> workspace . display_data . inverted_color = inverted_color <EOL> def display ( self , workspace , figure ) : <EOL> figure . set_subplots ( ( <NUM_LIT:2> , <NUM_LIT:1> ) ) <EOL> color_image = workspace . display_data . color_image <EOL> inverted_color = workspace . display_data . inverted_color <EOL> figure . subplot_imshow ( <NUM_LIT:0> , <NUM_LIT:0> , color_image , "<STR_LIT>" ) <EOL> figure . subplot_imshow ( <NUM_LIT:1> , <NUM_LIT:0> , inverted_color , "<STR_LIT>" , <EOL> sharexy = figure . subplot ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> def upgrade_settings ( self , setting_values , variable_revision_number , <EOL> module_name , from_matlab ) : <EOL> if from_matlab and variable_revision_number == <NUM_LIT:1> : <EOL> setting_values = [ <EOL> CC_GRAYSCALE , <EOL> setting_values [ <NUM_LIT:0> ] != cps . NONE , <EOL> setting_values [ <NUM_LIT:0> ] , <EOL> setting_values [ <NUM_LIT:1> ] != cps . NONE , <EOL> setting_values [ <NUM_LIT:1> ] , <EOL> setting_values [ <NUM_LIT:2> ] != cps . NONE , <EOL> setting_values [ <NUM_LIT:2> ] , <EOL> cps . NONE , <EOL> CC_GRAYSCALE , <EOL> setting_values [ <NUM_LIT:3> ] != cps . NONE , <EOL> setting_values [ <NUM_LIT:3> ] , <EOL> setting_values [ <NUM_LIT:4> ] != cps . NONE , <EOL> setting_values [ <NUM_LIT:4> ] , <EOL> setting_values [ <NUM_LIT:5> ] != cps . NONE , <EOL> setting_values [ <NUM_LIT:5> ] , <EOL> '<STR_LIT>' ] <EOL> from_matlab = False <EOL> variable_revision_number = <NUM_LIT:1> <EOL> return setting_values , variable_revision_number , from_matlab </s>
