original_docstring: Convert bgr image to hsv image
      
docstring: Convert bgr image to hsv image
docstring_tokens: Convert bgr image to hsv image
code: def bgr2hsv(img_in):
      """Convert bgr image to hsv image
      """
      if not isinstance(img_in, np.float32):
          img_in = img_in.astype(np.float32)
      
      rgb = img_in.copy() / 255.
      
      hsv = np.zeros_like(rgb, dtype=np.float32)
      
      # get max et min value
      max_vals = np.max(rgb, axis=2).copy()
      min_vals = np.min(rgb, axis=2).copy()
      min_args = np.argmin(rgb, axis=2)
      
      # h
      hsv[:, :, 0][np.where(max_vals == min_vals)] = 0
      
      ## if min_vals = B
      indices = np.where(min_args == 0)
      hsv[:, :, 0][indices] = 60 * (rgb[:, :, 1][indices] - rgb[:, :, 2][indices]) / (max_vals[indices] - min_vals[indices]) + 60
  
      ## if min = G
      indices = np.where(min_args == 1)
      hsv[:, :, 0][indices] = 300 * (rgb[:, :, 2][indices] - rgb[:, :, 0][indices]) / (max_vals[indices] - min_vals[indices]) + 300
      
      ## if min = R
      indices = np.where(min_args == 2)
      hsv[:, :, 0][indices] = 180 * (rgb[:, :, 0][indices] - rgb[:, :, 1][indices]) / (max_vals[indices] - min_vals[indices]) + 180
      
      # S
      hsv[:, :, 1] = max_vals.copy() - min_vals.copy()
      
      # V
      hsv[:, :, 2] = max_vals.copy()
      
      return hsv
code_tokens: def bgr2hsv ( img_in ) : if not isinstance ( img_in , np . float32 ) : img_in = img_in . astype ( np . float32 ) rgb = img_in . copy ( ) / 255. hsv = np . zeros_like ( rgb , dtype = np . float32 ) max_vals = np . max ( rgb , axis = 2 ) . copy ( ) min_vals = np . min ( rgb , axis = 2 ) . copy ( ) min_args = np . argmin ( rgb , axis = 2 ) hsv [ : , : , 0 ] [ np . where ( max_vals == min_vals ) ] = 0 indices = np . where ( min_args == 0 ) hsv [ : , : , 0 ] [ indices ] = 60 * ( rgb [ : , : , 1 ] [ indices ] - rgb [ : , : , 2 ] [ indices ] ) / ( max_vals [ indices ] - min_vals [ indices ] ) + 60 indices = np . where ( min_args == 1 ) hsv [ : , : , 0 ] [ indices ] = 300 * ( rgb [ : , : , 2 ] [ indices ] - rgb [ : , : , 0 ] [ indices ] ) / ( max_vals [ indices ] - min_vals [ indices ] ) + 300 indices = np . where ( min_args == 2 ) hsv [ : , : , 0 ] [ indices ] = 180 * ( rgb [ : , : , 0 ] [ indices ] - rgb [ : , : , 1 ] [ indices ] ) / ( max_vals [ indices ] - min_vals [ indices ] ) + 180 hsv [ : , : , 1 ] = max_vals . copy ( ) - min_vals . copy ( ) hsv [ : , : , 2 ] = max_vals . copy ( ) return hsv
short_docstring: Convert bgr image to hsv image
short_docstring_tokens: Convert bgr image to hsv image
comment: """Convert bgr image to hsv image
      """$SEP$# get max et min value$SEP$# h$SEP$## if min_vals = B$SEP$## if min = G$SEP$## if min = R$SEP$# S$SEP$# V