This is only part of making inverted scan work. There are still issues with background not being considered outside objects.