code: def _find_region(remaining_pixels, segmented_pixels):
      """
      Finds a region and returns a set of pixel coordinates for it.
      :param remaining_pixels: A numpy bool array, with True meaning the pixels are remaining to segment
      :param segmented_pixels: A set of pixel coordinates which have already been assigned to segment. This will be
      updated with the new pixels added to the returned segment.
      """
      in_region = set()
      not_in_region = set()
      # Find the first pixel in remaining_pixels with a value of True
      available_pixels = numpy.transpose(
          numpy.nonzero(remaining_pixels)
      )
      start = tuple(available_pixels[0])
      in_region.add(start)
      new_pixels = in_region.copy()
      while True:
          try_next = set()
          # Find surrounding pixels
          for pixel in new_pixels:
              x, y = pixel
              neighbours = [
                  (x - 1, y),
                  (x + 1, y),
                  (x, y - 1),
                  (x, y + 1),
              ]
              try_next.update(neighbours)
          # Remove pixels we have already seen
          try_next.difference_update(segmented_pixels, not_in_region)
          # If there's no more pixels to try, the region is complete
          if not try_next:
              break
          # Empty new pixels set, so we know whose neighbour's to check next time
          new_pixels = set()
          # Check new pixels
          for pixel in try_next:
              if remaining_pixels[pixel]:
                  in_region.add(pixel)
                  new_pixels.add(pixel)
                  segmented_pixels.add(pixel)
              else:
                  not_in_region.add(pixel)
      return in_region
  
imports: from __future__ import absolute_import, division, print_function
  import sys
  import numpy
  from PIL import Image, ImageFilter
label_desc: Use image node_id 13 for calling a global function with example usage: _find_region(remaining_pixels, segmented_pixels) and returns: in_region