test_mask.rb
  1| require 'rubygems'
  2| require_gem 'camellia'
  3| include Camellia
  4|     
  5| source=CamImage.new
  6| 
  7| # load picture chess.pgm
  8| source.load_pgm("resources/chess.pgm")
  9| mask=CamImage.new(source.width,source.height)
 10| 
 11| # draw a filled circle in mask
 12| mask.set!(0)
 13| mask.draw_circle(mask.width/2,mask.height/2,50,255)
 14| mask.fill_color(mask.width/2,mask.height/2,255)
 15| 
 16| # encode the mask and associate it to the source image
 17| encoded_mask=mask.encode
 18| source.mask=encoded_mask
 19| encoded_mask.inverse!
 20| dest=CamImage.new
 21| source.copy(dest) # copies only the mask! not like dup or clone!
 22| 
 23| # and then compute a sobel inside
 24| encoded_mask.inverse!
 25| source.sobel_v_abs(dest) # sobel only on the mask 
 26| dest.save_pgm("output/ruby_chess_sobel_mask.pgm")