def roi_indices(contour)
      raise ArgumentError, "Invalid argument 'contour'. Expected Selection, got #{contour.class}." unless contour.is_a?(Selection)
      ext_value = 3
      int_value = 2
      roi_value = 1
      # Determine external contour:
      ext_contour = external_contour
      row_indices = ext_contour.rows
      # Apply the two contours to an image:
      img = NArray.byte(columns, rows)
      img[ext_contour.indices] = ext_value
      img[contour.indices] = int_value
      # Iterate row by row where the contour is defined:
      (row_indices.min..row_indices.max).each do |row_index|
        img_vector = img[true, row_index]
        row_ext_indices = (img_vector.gt 0).where
        # Iterate the column:
        ext_left = nil
        int_found = nil
        (row_ext_indices.min..row_ext_indices.max).each do |col_index|
          if img_vector[col_index] == ext_value and !int_found
            ext_left = col_index
          elsif img_vector[col_index] == int_value
            int_found = true
          elsif img_vector[col_index] == ext_value and int_found
            # We have identified a span of pixels which belong to the internal contour:
            img[(ext_left+1)..(col_index-1), row_index] = roi_value
            # Reset our indicators:
            ext_left = col_index
            int_found = nil
          end
        end
      end
      # Extract and return our roi indices:
      return Selection.create_from_array((img.eq roi_value).where.to_a, self)
    end
def roi_indices(contour)
      raise ArgumentError, "Invalid argument 'contour'. Expected Selection, got #{contour.class}." unless contour.is_a?(Selection)
      ext_value = 3
      int_value = 2
      roi_value = 1
      # Determine external contour:
      ext_contour = external_contour
      row_indices = ext_contour.rows
      # Apply the two contours to an image:
      img = NArray.byte(columns, rows)
      img[ext_contour.indices] = ext_value
      img[contour.indices] = int_value
      # Iterate row by row where the contour is defined:
      (row_indices.min..row_indices.max).each do |row_index|
        img_vector = img[true, row_index]
        row_ext_indices = (img_vector.gt 0).where
        # Iterate the column:
        ext_left = nil
        int_found = nil
        (row_ext_indices.min..row_ext_indices.max).each do |col_index|
          if img_vector[col_index] == ext_value and !int_found
            ext_left = col_index
          elsif img_vector[col_index] == int_value
            int_found = true
          elsif img_vector[col_index] == ext_value and int_found
            # We have identified a span of pixels which belong to the internal contour:
            img[(ext_left+1)..(col_index-1), row_index] = roi_value
            # Reset our indicators:
            ext_left = col_index
            int_found = nil
          end
        end
      end
      # Extract and return our roi indices:
      return Selection.create_from_array((img.eq roi_value).where.to_a, self)
    end
Determines all pixel indices which belongs to the specified (continuous) contour indices.

 This is achieved by applying an external contour (around the original contour),
 and identifying the indices that are enclosed by this external contour. This identification
 is carried out by scanning line by line, and marking pixels which lies between two external
 contour points.

 * Uses Roman Khudeevs algorithm: A New Flood-Fill Algorithm for Closed Contour
 * https://docs.google.com/viewer?a=v&q=cache:UZ6bo7pXRoIJ:file.lw23.com/file1/01611214.pdf+flood+fill+from+contour+coordinate&hl=no&gl=no&pid=bl&srcid=ADGEEShV4gbKYYq8cDagjT7poT677cIL44K0QW8SR0ODanFy-CD1CHEQi2RvHF8MND7_PXPGYRJMJAcMJO-NEXkM-vU4iA2rNljVetbzuARWuHtKLJKMTNjd3vaDWrIeSU4rKLCVwvff&sig=AHIEtbSAnH6fp584c0_Krv298n-tgpNcJw&pli=1

 @param [Selection] contour a set of pixel indices defining a contour
 @return [Selection] a set of all pixel indices delimited by the given contour