Git Product home page Git Product logo

ytzimagecomparison's Introduction

YTZImageComparison

License MIT  CocoaPods  CocoaPods  Support 

##总述

YTZImageComparison是一个使用Objective-C编写,基于对图片颜色分析的一款取色,图片对比的开源库。实现了对图片优势色(主色)的提取,取出图片对应点颜色、对图片进行简单的相同/相似比较。其中取主色的算法借鉴了GitHub上的开源项目ColorCube

##算法简介

1. 提取图片主色的算法实现

  • 将传入的图片重绘为小尺寸的图片,避免遍历所有像素点所带来的性能问题;
  • 先得到重绘后图片的ARGB分量值;
  • 将RGB这三个分量对应到以R,G,B作为空间直角坐标轴的分量(即得到颜色空间);
  • 搜寻每个RGB对应点相邻方向的26个点(空间模型类似于三阶魔方)的RGB值,该点是否比旁边的点更加的"鲜艳";
  • 如果是,则将他加入鲜艳色数组;
  • 计算鲜艳色出现的频率,按照频率高低加入到返回值数组。
  • 其中可根据多个枚举值来定制"鲜艳"的标准,也可以设置忽略一个RGB色彩空间的颜色,避免一些颜色的干扰。

2. 提取图片对应点(像素)颜色的算法实现

  • 将传入的图片重绘为小尺寸的图片;
  • 先得到重绘后图片的ARGB分量值;
  • 由参数Rect算出该像素ARGB信息在字符数组中的位置;
  • 返回一个该ARGB分量组合成的UIColor。

3. 图片相同的算法实现

  • 将传入两张的图片重绘为相同的小尺寸的图片;
  • 先得到重绘后图片的ARGB分量值;
  • 计算对应像素在颜色空间上的距离,小于相等色差阀值则匹配度加一;
  • 匹配度高于最低相等阀值则视为图片相同。
  • 对于相同图片的算法主要是基于对像素的色差对比,这样的对比的结果是稳定的。

##效果图

1. 提取图片主色

YTZImageComparison

YTZImageComparison

YTZImageComparison

YTZImageComparison

2. 提取图片对应点(像素)颜色

YTZImageComparison

YTZImageComparison

YTZImageComparison

YTZImageComparison

3. 图片相同

YTZImageComparison

YTZImageComparison

YTZImageComparison

YTZImageComparison

##安装

CocoaPods

  1. 将 cocoapods 更新至最新版本.
  2. 在 Podfile 中添加 pod 'YTZImageComparison'
  3. 执行 pod installpod update
  4. 导入 "YTZImageComparison.h"

手动安装

  1. 下载 YTZImageComparison 文件夹内的所有内容。
  2. 将 YTZImageComparison 内的源文件添加(拖放)到你的工程。
  3. 导入 YTZImageComparison.h.

##许可证 YTZImageComparison 使用 MIT 许可证,详情见 LICENSE 文件。

ytzimagecomparison's People

Contributors

job-yang avatar

Watchers

James Cloos avatar Zike Xiong avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.