text: #!/usr/bin/env python
  
  # Import modules
  import pcl
  
  from pcl_helper import *
  
  
  def statistical_outlier(cloud):
      stat_filter = cloud.make_statistical_outlier_filter()
      stat_filter.set_mean_k(20)
      stat_filter.set_std_dev_mul_thresh(0.3)
      filtered_cloud = stat_filter.filter()
  
      return filtered_cloud
  
  # Returns Downsampled version of a point cloud
  # The bigger the leaf size the less information retained
  def do_voxel_grid_filter(point_cloud, LEAF_SIZE = 0.01):
    voxel_filter = point_cloud.make_voxel_grid_filter()
    voxel_filter.set_leaf_size(LEAF_SIZE, LEAF_SIZE, LEAF_SIZE) 
    return voxel_filter.filter()
  
  # Returns only the point cloud information at a specific range of a specific axis
  def do_passthrough_filter(point_cloud, name_axis = 'z', min_axis = 0.6, max_axis = 1.1):
    pass_filter = point_cloud.make_passthrough_filter()
    pass_filter.set_filter_field_name(name_axis);
    pass_filter.set_filter_limits(min_axis, max_axis)
    return pass_filter.filter()
  
  # Use RANSAC planse segmentation to separate plane and not plane points
  # Returns inliers (plane) and outliers (not plane)
  def do_ransac_plane_segmentation(point_cloud, max_distance = 0.01):
  
    segmenter = point_cloud.make_segmenter()
  
    segmenter.set_model_type(pcl.SACMODEL_PLANE)
    segmenter.set_method_type(pcl.SAC_RANSAC)
    segmenter.set_distance_threshold(max_distance)
  
    #obtain inlier indices and model coefficients
    inlier_indices, coefficients = segmenter.segment()
  
    inliers = point_cloud.extract(inlier_indices, negative = False)
    outliers = point_cloud.extract(inlier_indices, negative = True)
  
    return inliers, outliers
  
  # Euclidean Clustering
  def euclid_cluster(cloud):
      white_cloud = XYZRGB_to_XYZ(cloud) # Apply function to convert XYZRGB to XYZ
      tree = white_cloud.make_kdtree()
      ec = white_cloud.make_EuclideanClusterExtraction()
      ec.set_ClusterTolerance(0.015)
      ec.set_MinClusterSize(20)
      ec.set_MaxClusterSize(3000)
      ec.set_SearchMethod(tree)
      cluster_indices = ec.Extract()
  
      return cluster_indices, white_cloud
  
  
  def cluster_mask(cluster_indices, white_cloud):
      # Create Cluster-Mask Point Cloud to visualize each cluster separately
      #Assign a color corresponding to each segmented object in scene
      cluster_color = get_color_list(len(cluster_indices))
  
      color_cluster_point_list = []
  
      for j, indices in enumerate(cluster_indices):
          for i, indice in enumerate(indices):
              color_cluster_point_list.append([
                                              white_cloud[indice][0],
                                              white_cloud[indice][1],
                                              white_cloud[indice][2],
                                              rgb_to_float( cluster_color[j] )
                                             ])
  
      #Create new cloud containing all clusters, each with unique color
      cluster_cloud = pcl.PointCloud_PointXYZRGB()
      cluster_cloud.from_list(color_cluster_point_list)
  
      return cluster_cloud