[![Build Status](https://travis-ci.org/LunarLogic/gauguin.svg?branch=master)](https://travis-ci.org/LunarLogic/gauguin)
[![Code Climate](https://codeclimate.com/github/LunarLogic/gauguin/badges/gpa.svg)](https://codeclimate.com/github/LunarLogic/gauguin)
[![Test Coverage](https://codeclimate.com/github/LunarLogic/gauguin/badges/coverage.svg)](https://codeclimate.com/github/LunarLogic/gauguin)
<img src="http://gauguin.lunarlogic.io/assets/gauguin-b7a7737e8ede819b98df9d05f7df020a.png" alt="Guard Icon" align="left" />
# Gauguin
Retrieves palette of main colors, merging similar colors using [Lab color space](http://en.wikipedia.org/wiki/Lab_color_space).
## Why not just use `RMagick`?
How many colors do you recognize on the image below?
![Black and white image](http://gauguin.lunarlogic.io/assets/gray_and_black-b6871d86ef45c8740bf898233b0a588c.png)
Many people would say `2`, but actually there are `1942`.
It's because of the fact that to make image more smooth, borders of the figure are not pure black but consist of many gray scale colors.
It's common that images includes very similar colors, so when you want to get useful color palette, you would need to process color histogram you get from `RMagick` yourself.
This gem was created to do this for you.
## Sample app
Sample application available here: http://gauguin.lunarlogic.io
## Requirements
Gem depends on `RMagick` which requires `ImageMagick` to be installed.
### Ubuntu
$ sudo apt-get install imagemagick
### OSX
$ brew install imagemagick
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'gauguin'
```
And then execute:
$ bundle
Or install it yourself as:
$ gem install gauguin
## Usage
#### Palette
```ruby
palette = Gauguin::Painting.new("path/to/image.png").palette
```
Result for image above would be:
```ruby
{
rgb(204, 204, 204)[0.5900935269505287] => [
rgb(77, 77, 77)[7.383706620723603e-05],
rgb(85, 85, 85)[0.00012306177701206005],
# ...
rgb(219, 220, 219)[1.2306177701206005e-05],
rgb(220, 220, 220)[7.383706620723603e-05]
],
rgb(0, 0, 0)[0.40990647304947003] => [
rgb(0, 0, 0)[0.40990647304947003],
rgb(1, 1, 1)[0.007912872261875462],
# ...
rgb(64, 64, 64)[6.153088850603002e-05],
rgb(66, 66, 66)[6.153088850603002e-05]
]
}
```
Where keys are instances of `Gauguin::Color` class and values are array of instances of `Gauguin::Color` class.
#### Recolor
There is also recolor feature - you can pass original image and the calculated palette and return new image, colored only with the main colours from the palette.
```ruby
painting.recolor(palette, 'path/where/recolored/file/will/be/placed')
```
## Custom configuration
There are `4` parameters that you can configure:
- `max_colors_count` (default value is `10`) - maximum number of colors that a palette will include
- `colors_limit` (default value is `10000`) - maximum number of colors that will be considered while calculating a palette - if image has too many colors it is not efficient to calculate grouping for all of them, so only `colors_limit` of colors of the largest percentage are used
- `min_percentage_sum` (default value is `0.981`) - parameter used while calculating which colors should be ignored. Colors are sorted by percentage in descending order, then colors which percentages sums to `min_percentage_sum` are taken into consideration
- `color_similarity_threshold` (default value is `25`) - maximum distance in [Lab color space](http://en.wikipedia.org/wiki/Lab_color_space) to consider two colors as the same while grouping
To configure any of above options you can use configuration block.
For example changing `max_colors_count` would look like this:
```ruby
Gauguin.configuration do |config|
config.max_colors_count = 7
end
```
## Contributing
1. Fork it ( https://github.com/LunarLogic/gauguin/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
没有合适的资源?快使用搜索试试~ 我知道了~
从图像中检索主要颜色的工具_Ruby_代码_下载
共59个文件
rb:31个
png:19个
gemspec:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 83 浏览量
2022-06-15
09:55:22
上传
评论
收藏 747KB ZIP 举报
温馨提示
用法 调色板 palette = Gauguin::Painting.new("path/to/image.png").palette 上图的结果是: { rgb(204, 204, 204)[0.5900935269505287] => [ rgb(77, 77, 77)[7.383706620723603e-0 自定义配置 您可以配置以下4参数: max_colors_count(默认值为10) - 调色板将包含的最大颜色数 colors_limit(默认值为10000) - 计算调色板时将考虑的最大颜色数 - 如果图像有太多颜色,则计算所有颜色的分组效率不高,因此只colors_limit使用最大百分比的颜色 min_percentage_sum(默认值为0.981) - 计算应忽略哪些颜色时使用的参数。颜色按百分比降序排序,然后min_percentage_sum考虑百分比总和的颜色 color_similarity_threshold(默认值为)- Lab 颜色空间25中的最大距离,在分组时将两种颜色视为相同 要配置上述任何选项,您可以使用配置块
资源推荐
资源详情
资源评论
收起资源包目录
gauguin-master.zip (59个子文件)
gauguin-master
.gitignore 128B
README.md 4KB
Gemfile 92B
Guardfile 189B
.rspec 32B
spec
integration
painting_spec.rb 2KB
samples_spec.rb 1KB
support
pictures
12_colors.png 3KB
gray_and_black.png 32KB
unique_colors.png 1KB
10_colors.png 3KB
transparent_background.png 92KB
not_unique_colors.png 1KB
gauguin.png 13KB
samples
sample7.png 93KB
sample9.png 60KB
sample4.png 88KB
sample1.png 82KB
sample3.png 32KB
sample5.png 42KB
sample2.png 39KB
sample10.png 32KB
sample8.png 44KB
sample11.png 21KB
sample6.png 47KB
too_many_colors.png 2KB
lib
gauguin
colors_limiter_spec.rb 690B
noise_reducer_spec.rb 1KB
colors_retriever_spec.rb 2KB
color_spec.rb 3KB
painting_spec.rb 2KB
image_recolorer_spec.rb 3KB
image_spec.rb 2KB
palette_serializer_spec.rb 599B
color_space
rgb_vector_spec.rb 296B
xyz_vector_spec.rb 342B
colors_clusterer_spec.rb 4KB
image_repository_spec.rb 307B
spec_helper.rb 1KB
LICENSE.txt 1KB
.travis.yml 202B
lib
gauguin
image_repository.rb 106B
color_space.rb 140B
palette_serializer.rb 439B
colors_retriever.rb 813B
noise_reducer.rb 678B
colors_clusterer.rb 1KB
color.rb 2KB
image_recolorer.rb 639B
colors_limiter.rb 298B
version.rb 39B
image.rb 1KB
color_space
lab_vector.rb 82B
xyz_vector.rb 648B
rgb_vector.rb 815B
painting.rb 1KB
gauguin.rb 1KB
Rakefile 201B
gauguin.gemspec 1KB
共 59 条
- 1
资源评论
快撑死的鱼
- 粉丝: 2w+
- 资源: 9148
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功