def external_contour
      start_index = (@narray > 0).where[0] - 1
      s_col, s_row = indices_general_to_specific(start_index, columns)
      col, row = s_col, s_row
      row_indices = Array.new(1, row)
      col_indices = Array.new(1, col)
      last_dir = :north # on first step, pretend we came from the south (going north)
      directions = {
        :north => {:dir => [:east, :north, :west, :south], :col => [1, 0, -1, 0], :row => [0, -1, 0, 1]},
        :east => {:dir => [:south, :east, :north, :west], :col => [0, 1, 0, -1], :row => [1, 0, -1, 0]},
        :south => {:dir => [:west, :south, :east, :north], :col => [-1, 0, 1, 0], :row => [0, 1, 0, -1]},
        :west => {:dir => [:north, :west, :south, :east], :col => [0, -1, 0, 1], :row => [-1, 0, 1, 0]},
      }
      loop = true
      while loop do
        # Probe the neighbourhood pixels in a CCW order:
        map = directions[last_dir]
        4.times do |i|
          # Find the first 'free' (zero) pixel, and make that index
          # the next pixel of our external contour:
          if @narray[col + map[:col][i], row + map[:row][i]] == 0
            last_dir = map[:dir][i]
            col = col + map[:col][i]
            row = row + map[:row][i]
            col_indices << col
            row_indices << row
            break
          end
        end
        loop = false if col == s_col and row == s_row
      end
      return Selection.create_from_array(indices_specific_to_general(col_indices, row_indices, columns), self)
    end
def external_contour
      start_index = (@narray > 0).where[0] - 1
      s_col, s_row = indices_general_to_specific(start_index, columns)
      col, row = s_col, s_row
      row_indices = Array.new(1, row)
      col_indices = Array.new(1, col)
      last_dir = :north # on first step, pretend we came from the south (going north)
      directions = {
        :north => {:dir => [:east, :north, :west, :south], :col => [1, 0, -1, 0], :row => [0, -1, 0, 1]},
        :east => {:dir => [:south, :east, :north, :west], :col => [0, 1, 0, -1], :row => [1, 0, -1, 0]},
        :south => {:dir => [:west, :south, :east, :north], :col => [-1, 0, 1, 0], :row => [0, 1, 0, -1]},
        :west => {:dir => [:north, :west, :south, :east], :col => [0, -1, 0, 1], :row => [-1, 0, 1, 0]},
      }
      loop = true
      while loop do
        # Probe the neighbourhood pixels in a CCW order:
        map = directions[last_dir]
        4.times do |i|
          # Find the first 'free' (zero) pixel, and make that index
          # the next pixel of our external contour:
          if @narray[col + map[:col][i], row + map[:row][i]] == 0
            last_dir = map[:dir][i]
            col = col + map[:col][i]
            row = row + map[:row][i]
            col_indices << col
            row_indices << row
            break
          end
        end
        loop = false if col == s_col and row == s_row
      end
      return Selection.create_from_array(indices_specific_to_general(col_indices, row_indices, columns), self)
    end
Determines a set of pixel indices which enclose the structure.

 @see This implementation 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

 @return [Selection] the contour's indices