6.2   Remove Background of Arbitrary Shape

In some cases, the background may contain more than just a plane. If it remains steady for all scenes, you can acquire a reference scene (without the wanted objects in it) in order to subtract it from your actual scenes. Follow these steps to remove a background of arbitrary shape:
  1. Get the Z-image of the reference scene and your actual scene and subtract them.
     
    * Offline step, performed once:
    object_model_3d_to_xyz (XRef, YRef, ZRef, ReferenceScene, 'from_xyz_map', [], [])
    * Online steps, performed for every scene:
    object_model_3d_to_xyz (X, Y, Z, Scene, 'from_xyz_map', [], [])
    sub_image (ZRef, Z, ImageSub, 1, 0)
        
  2. Apply a threshold and reduce noise in order to receive a region of interest. Make sure your threshold is lower than the height of the wanted objects.
     
    threshold (ImageSub, Region, 0.5, 1e+10)
    connection (Region, ConnectedRegions)
    * Remove noise based on shape features, e.g. area:
    select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 2000, 1e+10)
    union1 (SelectedRegions, RegionUnion)
        
  3. Reduce your scene by view, using your region of interest.
     
    reduce_object_model_3d_by_view (RegionUnion, Scene, [], [], SceneReduced)