code: 
  
  
  from __future__ import annotations
  def 							_UpperCAmelCase       (UpperCamelCase__  :						List[Any]       ,							UpperCamelCase__  :						Optional[int]		):
         _A   : str       					=				0
         _A   : List[str]       					=				len(UpperCamelCase__		) - 1
         while left <= right:
                _A   : str       					=				(left + right) // 2
                if left == right:
                       if sorted_list[middle] < item:
                              _A   : Dict       					=				middle + 1
                       break
                elif sorted_list[middle] < item:
                       _A   : Optional[Any]       					=				middle + 1
                else:
                       _A   : Any       					=				middle - 1
         sorted_list.insert(UpperCamelCase__       ,							UpperCamelCase__		)
         return sorted_list
  def 							_UpperCAmelCase       (UpperCamelCase__  :						Tuple       ,							UpperCamelCase__  :						List[str]		):
         _A   : int       					=				[]
         while left and right:
                if left[0][0] < right[0][0]:
                       result.append(left.pop(0		)		)
                else:
                       result.append(right.pop(0		)		)
         return result + left + right
  def 							_UpperCAmelCase       (UpperCamelCase__  :						Dict		):
         _A   : Tuple       					=				len(UpperCamelCase__		)
         if length <= 1:
                return list_ad
         _A   : Optional[int]       					=				length // 2
         return merge(sortlist_ad(list_ad[:middle]		)       ,							sortlist_ad(list_ad[middle:]		)		)
  def 							_UpperCAmelCase       (UpperCamelCase__  :						list[int]		):
  
         if len(UpperCamelCase__		) <= 1:
                return collection
         _A   : Optional[int]       					=				[]
         _A   : List[Any]       					=				False
         for i in range(0       ,							len(UpperCamelCase__		)       ,							2		):
                if i == len(UpperCamelCase__		) - 1:
                       _A   : Optional[int]       					=				True
                else:
                       if collection[i] < collection[i + 1]:
                              two_paired_list.append([collection[i], collection[i + 1]]		)
                       else:
                              two_paired_list.append([collection[i + 1], collection[i]]		)
         _A   : Tuple       					=				sortlist_ad(UpperCamelCase__		)
         _A   : Optional[int]       					=				[i[0] for i in sorted_list_ad]
         result.append(sorted_list_ad[-1][1]		)
         if has_last_odd_item:
                _A   : Optional[int]       					=				collection[-1]
                _A   : List[str]       					=				binary_search_insertion(UpperCamelCase__       ,							UpperCamelCase__		)
         _A   : Union[str, Any]       					=				False
         for i in range(len(UpperCamelCase__		) - 1		):
                if result[i] == collection[-1] and has_last_odd_item:
                       _A   : Dict       					=				True
                _A   : int       					=				sorted_list_ad[i][1]
                # If last_odd_item is inserted before the item's index,
                # you should forward index one more.
                if is_last_odd_item_inserted_before_this_index:
                       _A   : Optional[Any]       					=				result[: i + 2] + binary_search_insertion(result[i + 2 :]       ,							UpperCamelCase__		)
                else:
                       _A   : Union[str, Any]       					=				result[: i + 1] + binary_search_insertion(result[i + 1 :]       ,							UpperCamelCase__		)
  
         return result
  
  
  if __name__ == "__main__":
      lowerCAmelCase__   	=				input('Enter numbers separated by a comma:\n').strip()
      lowerCAmelCase__   	=				[int(item) for item in user_input.split(',')]
      print(merge_insertion_sort(unsorted))
  
style_context: 
  
  
  import cva
  import numpy as np
  
  from digital_image_processing.filters.convolve import img_convolve
  from digital_image_processing.filters.sobel_filter import sobel_filter
  
  lowerCAmelCase__   	=				1_80
  def 							_UpperCAmelCase       (UpperCamelCase__  :						Optional[Any]       ,							UpperCamelCase__  :						Optional[Any]		):
         _A   : int       					=				k_size // 2
         _A					,    _A   : Tuple       					=				np.mgrid[0 - center : k_size - center, 0 - center : k_size - center]
         _A   : Union[str, Any]       					=				(
             1
             / (2 * np.pi * sigma)
             * np.exp(-(np.square(UpperCamelCase__		) + np.square(UpperCamelCase__		)) / (2 * np.square(UpperCamelCase__		))		)
         )
         return g
  def 							_UpperCAmelCase       (UpperCamelCase__  :						str       ,							UpperCamelCase__  :						Any       ,							UpperCamelCase__  :						Tuple		):
         _A   : Optional[int]       					=				np.zeros(UpperCamelCase__		)
  
         for row in range(1       ,							image_shape[0] - 1		):
                for col in range(1       ,							image_shape[1] - 1		):
                       _A   : Dict       					=				gradient_direction[row, col]
  
                       if (
                           0 <= direction < PI / 8
                           or 15 * PI / 8 <= direction <= 2 * PI
                           or 7 * PI / 8 <= direction <= 9 * PI / 8
                       ):
                              _A   : Dict       					=				sobel_grad[row, col - 1]
                              _A   : Any       					=				sobel_grad[row, col + 1]
                              if sobel_grad[row, col] >= w and sobel_grad[row, col] >= e:
                                     _A   : List[Any]       					=				sobel_grad[row, col]
  
                       elif (
                           PI / 8 <= direction < 3 * PI / 8
                           or 9 * PI / 8 <= direction < 11 * PI / 8
                       ):
                              _A   : List[str]       					=				sobel_grad[row + 1, col - 1]
                              _A   : str       					=				sobel_grad[row - 1, col + 1]
                              if sobel_grad[row, col] >= sw and sobel_grad[row, col] >= ne:
                                     _A   : List[Any]       					=				sobel_grad[row, col]
  
                       elif (
                           3 * PI / 8 <= direction < 5 * PI / 8
                           or 11 * PI / 8 <= direction < 13 * PI / 8
                       ):
                              _A   : Any       					=				sobel_grad[row - 1, col]
                              _A   : int       					=				sobel_grad[row + 1, col]
                              if sobel_grad[row, col] >= n and sobel_grad[row, col] >= s:
                                     _A   : Any       					=				sobel_grad[row, col]
  
                       elif (
                           5 * PI / 8 <= direction < 7 * PI / 8
                           or 13 * PI / 8 <= direction < 15 * PI / 8
                       ):
                              _A   : List[str]       					=				sobel_grad[row - 1, col - 1]
                              _A   : Optional[Any]       					=				sobel_grad[row + 1, col + 1]
                              if sobel_grad[row, col] >= nw and sobel_grad[row, col] >= se:
                                     _A   : List[Any]       					=				sobel_grad[row, col]
  
         return destination
  def 							_UpperCAmelCase       (UpperCamelCase__  :						Dict       ,							UpperCamelCase__  :						Optional[Any]       ,							UpperCamelCase__  :						str       ,							UpperCamelCase__  :						Dict       ,							UpperCamelCase__  :						Optional[Any]       ,							UpperCamelCase__  :						Any		):
         for row in range(1       ,							image_shape[0] - 1		):
                for col in range(1       ,							image_shape[1] - 1		):
                       if destination[row, col] >= threshold_high:
                              _A   : Optional[int]       					=				strong
                       elif destination[row, col] <= threshold_low:
                              _A   : Optional[int]       					=				0
                       else:
                              _A   : Union[str, Any]       					=				weak
  def 							_UpperCAmelCase       (UpperCamelCase__  :						Optional[Any]       ,							UpperCamelCase__  :						Optional[int]       ,							UpperCamelCase__  :						Any       ,							UpperCamelCase__  :						Any		):
         for row in range(1       ,							image_shape[0]		):
                for col in range(1       ,							image_shape[1]		):
                       if destination[row, col] == weak:
                              if 255 in (
                                  destination[row, col + 1],
                                  destination[row, col - 1],
                                  destination[row - 1, col],
                                  destination[row + 1, col],
                                  destination[row - 1, col - 1],
                                  destination[row + 1, col - 1],
                                  destination[row - 1, col + 1],
                                  destination[row + 1, col + 1],
                              ):
                                     _A   : str       					=				strong
                              else:
                                     _A   : Any       					=				0
  def 							_UpperCAmelCase       (UpperCamelCase__  :						Dict       ,							UpperCamelCase__  :						int=15       ,							UpperCamelCase__  :						Dict=30       ,							UpperCamelCase__  :						int=128       ,							UpperCamelCase__  :						Union[str, Any]=255		):
         # gaussian_filter
         _A   : Union[str, Any]       					=				img_convolve(UpperCamelCase__       ,							gen_gaussian_kernel(9       ,							sigma=1.4		)		)
         # get the gradient and degree by sobel_filter
         _A					,    _A   : Dict       					=				sobel_filter(UpperCamelCase__		)
         _A   : Tuple       					=				PI + np.radadeg(UpperCamelCase__		)
  
         _A   : Optional[int]       					=				suppress_non_maximum(image.shape       ,							UpperCamelCase__       ,							UpperCamelCase__		)
  
         detect_high_low_threshold(
             image.shape       ,							UpperCamelCase__       ,							UpperCamelCase__       ,							UpperCamelCase__       ,							UpperCamelCase__       ,							UpperCamelCase__		)
  
         track_edge(image.shape       ,							UpperCamelCase__       ,							UpperCamelCase__       ,							UpperCamelCase__		)
  
         return destination
  
  
  if __name__ == "__main__":
      # read original image in gray mode
      lowerCAmelCase__   	=				cva.imread(R'../image_data/lena.jpg', 0)
      # canny edge detection
      lowerCAmelCase__   	=				canny(lena)
      cva.imshow('canny', canny_destination)
      cva.waitKey(0)
  