parameters: (self, bg_arr, text_arr, hs, place_order=None, pad=20)
return_statement: return bg_arr
docstring: Return colorized text image.
  
          text_arr : list of (n x m) numpy text alpha mask (unit8).
          hs : list of minimum heights (scalar) of characters in each text-array. 
          text_loc : [row,column] : location of text in the canvas.
          canvas_sz : size of canvas image.
          
          return : nxmx3 rgb colorized text-image.
docstring_summary: Return colorized text image.
docstring_tokens: Return colorized text image .
function: def color(self, bg_arr, text_arr, hs, place_order=None, pad=20):
          """
          Return colorized text image.
  
          text_arr : list of (n x m) numpy text alpha mask (unit8).
          hs : list of minimum heights (scalar) of characters in each text-array. 
          text_loc : [row,column] : location of text in the canvas.
          canvas_sz : size of canvas image.
          
          return : nxmx3 rgb colorized text-image.
          """
          bg_arr = bg_arr.copy()
          if bg_arr.ndim == 2 or bg_arr.shape[2]==1: # grayscale image:
              bg_arr = np.repeat(bg_arr[:,:,None], 3, 2)
  
          # get the canvas size:
          canvas_sz = np.array(bg_arr.shape[:2])
  
          # initialize the placement order:
          if place_order is None:
              place_order = np.array(xrange(len(text_arr)))
  
          rendered = []
          for i in place_order[::-1]:
              # get the "location" of the text in the image:
              ## this is the minimum x and y coordinates of text:
              loc = np.where(text_arr[i])
              lx, ly = np.min(loc[0]), np.min(loc[1])
              mx, my = np.max(loc[0]), np.max(loc[1])
              l = np.array([lx,ly])
              m = np.array([mx,my])-l+1
              text_patch = text_arr[i][l[0]:l[0]+m[0],l[1]:l[1]+m[1]]
  
              # figure out padding:
              ext = canvas_sz - (l+m)
              num_pad = pad*np.ones(4,dtype='int32')
              num_pad[:2] = np.minimum(num_pad[:2], l)
              num_pad[2:] = np.minimum(num_pad[2:], ext)
              text_patch = np.pad(text_patch, pad_width=((num_pad[0],num_pad[2]), (num_pad[1],num_pad[3])), mode='constant')
              l -= num_pad[:2]
  
              w,h = text_patch.shape
              bg = bg_arr[l[0]:l[0]+w,l[1]:l[1]+h,:]
  
              rdr0 = self.process(text_patch, bg, hs[i])
              rendered.append(rdr0)
  
              bg_arr[l[0]:l[0]+w,l[1]:l[1]+h,:] = rdr0#rendered[-1]
  
  
              return bg_arr
  
          return bg_arr
function_tokens: def color ( self , bg_arr , text_arr , hs , place_order = None , pad = 20 ) : bg_arr = bg_arr . copy ( ) if bg_arr . ndim == 2 or bg_arr . shape [ 2 ] == 1 : # grayscale image: bg_arr = np . repeat ( bg_arr [ : , : , None ] , 3 , 2 ) # get the canvas size: canvas_sz = np . array ( bg_arr . shape [ : 2 ] ) # initialize the placement order: if place_order is None : place_order = np . array ( xrange ( len ( text_arr ) ) ) rendered = [ ] for i in place_order [ : : - 1 ] : # get the "location" of the text in the image: ## this is the minimum x and y coordinates of text: loc = np . where ( text_arr [ i ] ) lx , ly = np . min ( loc [ 0 ] ) , np . min ( loc [ 1 ] ) mx , my = np . max ( loc [ 0 ] ) , np . max ( loc [ 1 ] ) l = np . array ( [ lx , ly ] ) m = np . array ( [ mx , my ] ) - l + 1 text_patch = text_arr [ i ] [ l [ 0 ] : l [ 0 ] + m [ 0 ] , l [ 1 ] : l [ 1 ] + m [ 1 ] ] # figure out padding: ext = canvas_sz - ( l + m ) num_pad = pad * np . ones ( 4 , dtype = 'int32' ) num_pad [ : 2 ] = np . minimum ( num_pad [ : 2 ] , l ) num_pad [ 2 : ] = np . minimum ( num_pad [ 2 : ] , ext ) text_patch = np . pad ( text_patch , pad_width = ( ( num_pad [ 0 ] , num_pad [ 2 ] ) , ( num_pad [ 1 ] , num_pad [ 3 ] ) ) , mode = 'constant' ) l -= num_pad [ : 2 ] w , h = text_patch . shape bg = bg_arr [ l [ 0 ] : l [ 0 ] + w , l [ 1 ] : l [ 1 ] + h , : ] rdr0 = self . process ( text_patch , bg , hs [ i ] ) rendered . append ( rdr0 ) bg_arr [ l [ 0 ] : l [ 0 ] + w , l [ 1 ] : l [ 1 ] + h , : ] = rdr0 #rendered[-1] return bg_arr return bg_arr