Class: Gauguin::Painting
- Inherits:
-
Object
- Object
- Gauguin::Painting
- Defined in:
- lib/gauguin/painting.rb
Instance Method Summary collapse
-
#initialize(path, image_repository = nil, colors_retriever = nil, colors_limiter = nil, noise_reducer = nil, colors_clusterer = nil, image_recolorer = nil) ⇒ Painting
constructor
A new instance of Painting.
- #palette ⇒ Object
- #recolor(palette, path) ⇒ Object
Constructor Details
#initialize(path, image_repository = nil, colors_retriever = nil, colors_limiter = nil, noise_reducer = nil, colors_clusterer = nil, image_recolorer = nil) ⇒ Painting
Returns a new instance of Painting.
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/gauguin/painting.rb', line 3 def initialize(path, image_repository = nil, colors_retriever = nil, colors_limiter = nil, noise_reducer = nil, colors_clusterer = nil, image_recolorer = nil) @image_repository = image_repository || Gauguin::ImageRepository.new @image = @image_repository.get(path) @colors_retriever = colors_retriever || Gauguin::ColorsRetriever.new(@image) @colors_limiter = colors_limiter || Gauguin::ColorsLimiter.new @noise_reducer = noise_reducer || Gauguin::NoiseReducer.new @colors_clusterer = colors_clusterer || Gauguin::ColorsClusterer.new @image_recolorer = image_recolorer || Gauguin::ImageRecolorer.new(@image) end |
Instance Method Details
#palette ⇒ Object
15 16 17 18 19 20 |
# File 'lib/gauguin/painting.rb', line 15 def palette colors = @colors_retriever.colors colors = @colors_limiter.call(colors) colors_clusters = @colors_clusterer.clusters(colors) @noise_reducer.call(colors_clusters) end |
#recolor(palette, path) ⇒ Object
22 23 24 25 26 |
# File 'lib/gauguin/painting.rb', line 22 def recolor(palette, path) new_colors = @colors_clusterer.reversed_clusters(palette) recolored_image = @image_recolorer.recolor(new_colors) recolored_image.write(path) end |