Connected component labeling

Connected component analysis assigns the same label to neighbouring pixel which have the same value

See also

#!/usr/bin/env ruby
require 'hornetseye'
include Hornetseye
raise "Syntax: ./components.rb <input image> <output image>" if ARGV.size != 2
img = MultiArray.load_ubytergb ARGV[0]
components = img.eq( 77 ).components
palette = Sequence.ubytergb components.max + 1
palette.decompose.random! 256
palette[ 0 ] = 0
components.map( palette ).save_ubytergb ARGV[1]
Close