원시데이터 수집 시스템
선정목록으로

Automatic 1D Histogram Segmentation and Application to the Computation of Color Palettes

관련 필름·전자재료 · (16) CPI(투명 폴리이미드)

기본 정보

저자
  1. José-Luis Lisani — Universitat Illes Balears, IAC3-IEEC (Spain)
  2. Ana Belén Petro — Universitat Illes Balears, IAC3-IEEC (Spain)
DOI
10.5201/ipol.2021.344
저널
Image Processing On Line
발행년도
2021
발행기관
Image Processing On Line
피인용수
4
라이선스
cc-by-nc-sa
논문 유형
–
언어
–
원문 페이지
https://doi.org/10.5201/ipol.2021.344
토픽
Color Science and Applications
OpenAlex ID
W3162523624

평가 내용

관련도
관련
사업분야
필름·전자재료 · (16) CPI(투명 폴리이미드)
부 분야
–
R&D 측면
–
확신도
–
근거 용어
–
판단 근거
임베딩 유사도 기반 평가로 '필름·전자재료 > CPI(투명 폴리이미드)' 분야에 선정된 논문입니다.
R&D 활용 포인트
–
평가 입력
–

초록

This article presents an implementation of the FTC (Fine-to-Coarse) algorithm for histogram segmentation, presented by Delon et al. in 2007. This algorithm uses a non-parametric a contrario approach to segment a 1D histogram into its meaningful modes. We describe also how the method may be applied to the hue, saturation and intensity histograms of color images in order to automatically extract their more representative colors, the so-called color palette. The algorithm for color palette extraction described in this paper is based on the one first published in 2007 by Delon et al., with an improvement that affects low-saturated colors. Several results illustrate the effectiveness of the algorithm.

본문 54,771자

본문 펼치기
Published in Image [Processing](https://doi.org/10.5201/ipol) On Line on 2021–04–23. Submitted on 2021–04–06, accepted on 2021–04–20. ISSN 2105–1232 _⃝_ c 2021 IPOL & the authors [CC–BY–NC–SA](http://creativecommons.org/licenses/by-nc-sa/3.0/) This article is available online with supplementary materials, software, datasets and online demo at ``` https://doi.org/10.5201/ipol.2021.344 # Automatic 1D Histogram Segmentation and Application to the Computation of Color Palettes ## Jose-Luis Lisani, Ana Bel´en Petro ``` Universitat Illes Balears, IAC3-IEEC (Spain) ``` joseluis.lisani, anabelen.petro@uib.es ``` _Communicated_ _by_ Luis Alvarez <sup>´</sup> _Demo_ _edited_ _by_ Jose-Luis Lisani Abstract This article presents an implementation of the FTC (Fine-to-Coarse) algorithm for histogram segmentation, presented by Delon et al. in 2007. This algorithm uses a non-parametric a contrario approach to segment a 1D histogram into its meaningful modes. We describe also how the method may be applied to the hue, saturation and intensity histograms of color images in order to automatically extract their more representative colors, the so-called color palette. The algorithm for color palette extraction described in this paper is based on the one first published in 2007 by Delon et al., with an improvement that affects low-saturated colors. Several results illustrate the effectiveness of the algorithm. Source Code The C source codes implementing the algorithms described in the paper, and the online demo, are accessible at the [associated](https://doi.org/10.5201/ipol.2021.344) web page <sup>1</sup> . Keywords: 1D histogram segmentation; a contrario method; color palette # 1 Introduction Histograms are extensively used in data analysis because they provide a compact representation of large amounts of data. Moreover, it is often possible to infer global properties of the data from the behavior of their histogram. Histograms can be described by the list of their modes, i.e., the ranges of values around which the data are concentrated. In 2007 Delon et al. [8] proposed a non-parametric algorithm (the _FTC_ _algorithm_ ) for the segmentation of a 1D histogram into its meaningful modes. The _meaningfulness_ of each node was determined using the a contrario approach, following previous works of the same authors [9, 10, 11]. The algorithm was later refined in [3]. 1 `[https://doi.org/10.5201/ipol.2021.344](https://doi.org/10.5201/ipol.2021.344)` Jose-Luis Lisani, Ana Bel´en Petro, _Automatic_ _1D_ _Histogram_ _Segmentation_ _and_ _Application_ _to_ _the_ _Computation_ _of_ _Color_ _Palettes_, Image The FTC algorithm has found applications in diverse problems, such as camera stabilization [6], video demultiplexing [13], color palette extraction [7], and satellite image analysis [1]. In this paper we provide a detailed description of the FTC algorithm, and we illustrate its application to the extraction of the main colors of a digital image, as proposed in [7] and [3]. The paper is organized as follows: the histogram segmentation algorithm is described in Section 2, the algorithm for color palette extraction is presented in Section 3, several experiments are shown in Section 4, and, finally, some conclusions are summarized in Section 5. # 2 Automatic Location of the Meaningful Modes of a His- togram As commented in the Introduction, a _mode_ of a histogram can be loosely defined as a range of values in which data concentrate. Our goal will be to locate these modes in the 1D case. More formally, we seek to find intervals of values (which we call _segments_ ) on which it is “likely” that the histogram is the realization of a unimodal law . A density function _f_ is said to be unimodal on some interval [ _a, b_ ] if _f_ is increasing on some [ _a, c_ ] and decreasing on [ _c, b_ ], for some _c_ in ( _a, b_ ). Such a segmentation is usually not unique (think of the segmentation defined by all the local minima of the histogram) and we will impose two conditions that lead to a unique result: _•_ in each segment, the histogram is “statistically unimodal”, _•_ no union of consecutive segments is “statistically unimodal”. The notion of “statistically unimodal” histogram is presented next. ## 2.1 Testing a Histogram against a given Probability Law Consider a discrete histogram _h_ = ( _hi_ ) _i_ =1 _...L_, with _N_ samples on _L_ bins _{_ 1 _, . . . L}_ . The number _hi_ is the value of _h_ in bin _i_ and we have that _L_ _i_ =1 _hi_ = _N._ (1) For each discrete interval [ _a, b_ ] of _{_ 1 _, . . . L}_, let _h_ ( _a, b_ ) denote the proportion of points in [ _a, b_ ], _h_ ( _a, b_ ) = <sup><u>1</u></sup> _N_ - _b_ _i_ = _a_ _hi_ _._ (2) Consider now a discrete probability law _p_ = ( _pi_ ) _i_ =1 _...L_ . For each interval [ _a, b_ ] of _{_ 1 _, . . . L}_, let _p_ ( _a, b_ ) be the probability for a point to fall into the interval [ _a, b_ ], _b_ _p_ ( _a, b_ ) = _i_ = _a_ _pi._ (3) We define the relative entropy of an interval [ _a, b_ ] of _h_ with respect to _p_ as <sup>_<u>h</u>_</sup> _p_ ( <sup><u>(</u></sup> _a, b_ <sup>_<u>a, b</u>_</sup> ) <sup><u>)</u></sup> <sup>+ (1</sup> <sup>_−_</sup> <sup>_h_</sup> <sup>(</sup> <sup>_a, b_</sup> <sup>)) log 1</sup> 1 <sup>_<u>−</u>_</sup> _−_ <sup>_<u>h</u>_</sup> _p_ ( <sup><u>(</u></sup> _a, b_ <sup>_<u>a, b</u>_</sup> ) <sup><u>)</u></sup> _Hh,p_ ([ _a, b_ ]) = _h_ ( _a, b_ ) log <sup>_<u>h</u>_</sup> _p_ ( <sup><u>(</u></sup> _a, b_ <sup>_<u>a, b</u>_</sup> ) <sup><u>)</u></sup> (4) <sup><u>1</u></sup> 1 <sup>_<u>−</u>_</sup> _−_ <sup>_<u>h</u>_</sup> _p_ ( <sup><u>(</u></sup> _a, b_ <sup>_<u>a, b</u>_</sup> ) <sup><u>)</u></sup> 77 _Hh,p_ gives a measure of how well _h_ follows the law _p_ in a given interval <sup>2</sup> . If the relative entropy is large we can state that _h_ doesn’t follow the law _p_ . In particular, we say that the interval [ _a, b_ ] is a _ε_ -meaningful rejection of law _p_ if _Hh,p_ ([ _a, b_ ]) _≥_ _N_ <sup><u>1</u></sup> _N_ <sup><u>1</u></sup> <sup>log</sup> <sup>_<u>L</u>_</sup> <sup><u>(</u></sup> <sup>_<u>L</u>_</sup> 2 <sup><u>+ 1)</u></sup> _ε_ (5) 2 <sup><u>+ 1)</u></sup> _ε_ In [3] it is proved that the expected number of intervals [ _a, b_ ] of _h_ that satisfy the previous condition is less than _ε_ when _h_ is indeed following law _p_ in [ _a, b_ ]. In general _ε_ is set to 1. ## 2.2 Testing the Unimodal Hypothesis As commented above, an unimodal law can be described as the concatenation of an increasing function with a decreasing function. More precisely, we say that a histogram _h_ follows the unimodal hypothesis on the interval [ _a, b_ ] if there exists _c ∈_ ( _a, b_ ) such that _h_ follows the increasing hypothesis on [ _a, c_ ] and _h_ follows the decreasing hypothesis on [ _c, b_ ]. Moreover, we say that a histogram _h_ follows the decreasing hypothesis (resp. the increasing hypothesis) on an interval [ _a, b_ ] if the restriction of the histogram to [ _a, b_ ] (i.e. _h|_ [ _a,b_ ] = ( _ha, ha_ +1 _, . . . hb_ )) contains no _ε_ -meaningful rejection for the decreasing (resp. increasing) hypothesis. In particular, we compute _C_ [ _a,b_ ] = _N_ _· H −_ log <sup>_<u>L</u>_</sup> <sup><u>(</u></sup> <sup>_<u>L</u>_</sup> <sup><u>+ 1)</u></sup> (6) 2 _ε_ with _H_ the maximum of the relative entropies of all the subintervals of [ _a, b_ ] with respect to the hypothesis. If _C_ [ _a,b_ ] _≥_ 0 the hypothesis is rejected. The decreasing (resp. increasing) laws against which the intervals of _h_ must be tested can be computed from _h_ itself using the Grenander estimator [12], as explained next. Let _P_ ( _L_ ) be the space of discrete probability distributions on _{_ 1 _, . . . L}_, i.e., the vectors _r_ = ( _ri_ ) _i_ =1 _,...L_ such that _∀i ∈{_ 1 _,_ 2 _, . . ., L},_ _ri_ _≥_ 0 and _L_ _i_ =1 _ri_ = 1 _._ (7) Let _D_ ( _L_ ) _⊂P_ ( _L_ ) be the space of all decreasing densities on _{_ 1 _, . . . L}_ . If _r_ = _N_ <u>1</u> <sup>_h_</sup> <sup>_∈P_</sup> <sup>(</sup> <sup>_L_</sup> <sup>)</sup> <sup>is</sup> <sup>the</sup> normalized histogram of our observations, the decreasing Grenander estimator of _r_, denoted by _r_ ¯, is the only distribution of _D_ ( _L_ ) which achieves the minimal Kullback-Leibler distance from _r_ to _D_ ( _L_ ). This estimator can be computed using the Pool Adjacent Violators algorithm (see [2] and [4]), which is summarized as follows: _1._ _Consider_ _the_ _operator_ _D_ : _P_ ( _L_ ) _→P_ ( _L_ ) _,_ _applied_ _on_ _r_ = ( _ri_ ) _i_ =1 _,...L_ _∈P_ ( _L_ ) _,_ _2._ _For_ _each_ _interval_ [ _i, j_ ] _on_ _which_ _r_ _is_ _increasing,_ i.e. _ri_ _≤_ _ri_ +1 _≤· · ·_ _≤_ _rj_ _and_ _ri−_ 1 _>_ _ri_ _and_ _rj_ +1 _< rj,_ _define_ _D_ _as_ _D_ ( _r_ ) _k_ = <sup>_<u>ri</u>_</sup> <sup><u>+</u></sup> <sup>_<u>· · ·</u>_</sup> <sup><u>+</u></sup> <sup>_<u>rj</u>_</sup> for _k_ _∈_ [ _i, j_ ] _._ (8) _j −_ _i_ + 1 _3._ _Otherwise,_ _define_ _D_ _as_ _D_ ( _r_ ) _k_ = _rk_ This operator _D_ replaces each increasing part of _r_ by a constant value (equal to the mean value on the interval). A similar procedure can be used to compute the increasing Grenander estimator. A detailed description of the method is provided in Algorithm 3. 2More precisely, _Hh,p_ ([ _a, b_ ]) is the Kullback-Leibler distance between the two Bernoulli distributions of respective parameters h(a, b) and p(a, b) (see [5]). 78 ## 2.3 The FTC Algorithm The two conditions stated at the beginning of this section for obtaining an adequate segmentation of a histogram into its modes can be fulfilled by applying the following algorithm, known as Fine to Coarse (or FTC) algorithm: _1._ _Define_ _the_ _initial_ _segmentation,_ _S_ = _{s_ 0 _,...,_ _sn},_ _as_ _the_ _finest_ _segmentation_ _given_ _by_ _the_ _list_ _of_ _all_ _the_ _minima,_ _plus_ _the_ _end_ _points_ _1_ _and_ _L_ _of_ _the_ _histogram._ _2._ _Repeat:_ _(a)_ _For_ _each_ _i,_ _i_ = 0 _, . . ., n −_ 2 _,_ _the_ _cost_ _of_ _the_ _union_ _of_ _interval_ [ _si, si_ +1] _with_ _its_ _successive_ _interval_ [ _si_ +1 _, si_ +2] _is_ _defined_ _as_ _the_ _lowest_ _rejection_ _against_ _the_ _unimodal_ _hypothesis_ _on_ _their_ _union_ _Ci_ = _C_ ([ _si, si_ +1] _∪_ [ _si_ +1 _, si_ +2]) = [ _a,b_ ] _∈_ [ _si,si_ min+1] _∪_ [ _si_ +1 _,si_ +2] <sup>_C_</sup> <sup>[</sup> <sup>_a,b_</sup> <sup>]</sup> <sup>_,_</sup> _with_ _C_ [ _a,b_ ] _as_ _defined_ _in_ _Equation_ (6) _._ _Obtain_ _the_ _list_ _L_ = _{C_ 0 _, . . ., Cn−_ 2 _}._ _(b)_ _Sort_ _the_ _list_ _of_ _costs_ _L,_ _in_ _increasing_ _order._ _(c)_ _Assume_ _that_ _the_ _lower_ _cost_ _is_ _Cj._ _If_ _Cj_ _is_ _lower_ _than_ _0,_ _then_ _merge_ _the_ _intervals_ [ _sj, sj_ +1] _and_ [ _sj_ +1 _, sj_ +2] _._ _(d)_ _Update_ _S._ _Stop_ _when_ _no_ _more_ _pair_ _of_ _successive_ _intervals_ _follows_ _the_ _unimodal_ _hypothesis,_ _that_ _is,_ _when_ _the_ _lower_ _cost_ _is_ _higher_ _than_ _0._ _3._ _Repeat_ _step_ _2_ _with_ _the_ _unions_ _of_ _j_ _segments,_ _j_ _going_ _from_ 3 _to_ _length_ ( _S_ ) _._ A detailed description of the method is provided in Algorithms 1 and 2. Adaptation of FTC to circular histograms. If _h_ = ( _hi_ ) _i_ =1 _...L_ is a circular histogram (e.g. a histogram of angular values), the previous algorithm can be adapted easily by defining an auxiliary histogram _h_ <sup>˜</sup> as the concatenation of three copies of _h_ . The FTC algorithm is applied to _h_ <sup>˜</sup> but only the modes contained in the central part of this new histogram are used as output. The process is described in Algorithm 4. 79 <u>Algorithm</u> <u>1:</u> <u>FTC</u> <u>algorithm</u> Input : input histogram, _h_ = ( _hi_ ) _i_ =1 _···L_ Input : maximum expected number of meaningful rejections of unimodal law, _ε_ (default: _ε_ = 1) Output : segmentation of the histogram into _n_ meaningful modes, _s_ = _{s_ 0 _, · · ·_ _, sn}_, with 1 = _s_ 0 _< s_ 1 _< · · · < sn_ = _L_ ``` //Compute local minima of the histogram (including endpoints) ``` 1 _m_ = _{m_ 1 _, · · ·_ _, mK}_ = GetMinima( _h_ ) `//` _K_ `values,` `with` _m_ 1 = 1 `and` _mK_ = _L_ ``` //Compute local maxima of the histogram ``` 2 _M_ = _{M_ 1 _, · · ·_ _, MK−_ 1 _}_ = GetMaxima( _h_ ) `//` _K −_ 1 `values,` `we` `have` `that` _mi_ _< Mi_ _< mi_ +1 `//Initial` `segmentation:` _s_ = _m_ `//Each` `interval` _Ii_ = [ _mi, mi_ +1] `follows` `the` `unimodal` `law` `//(` [ _mi, Mi_ ] `is` `monotonically` `increasing` `and` [ _Mi, mi_ +1] `is` `monotonically` `decreasing)` `//The` `number` `of` `intervals` `is` _K −_ 1 ``` //Merging of intervals ``` 3 _J_ = 1 `//Number` `of` `consecutive` `intervals` `to` `merge=` 1 + _J_ 4 while _J_ _< K −_ 1 do 5 do `//Compute` `cost` `of` `merging` 1 + _J_ `consecutive` `intervals` `//from` _Ii_ = [ _mi, mi_ +1] `to` _Ii_ + _J_ = [ _mi_ + _J_ _, mi_ + _J_ +1] 6 _C_ _←∅_ `//List` `of` `costs` 7 for _i_ = _{_ 1 _, · · ·_ _, K −_ _J_ _−_ 1 _}_ do `//Compute` `cost` `of` `considering` [ _mi, Mi_ + _J_ ] `monotonically` `increasing` 8 _costI_ = _CostMonotone_ ( _h, mi, Mi_ + _J_ _,_ ‘increasing’ _, ε_ ) `//Algorithm` `2` `//Compute` `cost` `of` `considering` [ _Mi, mi_ + _J_ +1] `monotonically` `decreasing` 9 _costD_ = _CostMonotone_ ( _h, Mi, mi_ + _J_ +1 _,_ ‘decreasing’ _, ε_ ) `//Algorithm` `2` ``` //Final cost is the smallest of both values //Store index, cost and type ``` 10 if _costI_ _< costD_ then 11 _Ci_ = _{i, costI,_ ‘increasing’ _}_ 12 else 13 _Ci_ = _{i, costD,_ ‘decreasing’ _}_ 14 _C_ _←C ∪_ _Ci_ `//Add` `cost` `to` `list` ``` //Find minimum of all costs ``` 15 _{i_ <sup>_∗_</sup> _, mincost, type}_ = _C_ <sup>_∗_</sup> _∈C_ such that _C_ <sup>_∗_</sup> ( _cost_ ) _< Cj_ ( _cost_ ) _∀Cj_ _∈C_ ``` //Merge intervals while no meaningful rejection to monotone hypothesis ``` 16 if _mincost <_ 0 then 17 Update list of minima _m_ : remove from _mi∗_ +1 to _mi∗_ + _J_ . 18 if _type_ == _‘increasing’_ then 19 Update list of maxima _M_ : remove from _Mi∗_ to _Mi∗_ + _J−_ 1. 20 else 21 Update list of maxima _M_ : remove from _Mi∗_ +1 to _Mi∗_ + _J_ . 22 while _mincost <_ 0 ``` //Increase number of intervals to merge ``` 23 _J_ _←_ _J_ + 1 24 _s_ = _m_ `//Return` `final` `list` `of` `minima` `(including` `end` `points)` 25 return _s_ 80 <u>Algorithm</u> <u>2:</u> <u>CostMonotone</u> <u>function</u> Input : input histogram, _h_ = ( _hi_ ) _i_ =1 _···L_ Input : endpoints of an interval of the histogram, _i_ 1, _i_ 2 Input : type of computation, _type ∈_ ‘increasing’ _,_ ‘decreasing’ Input : maximum expected number of meaningful rejections of unimodal law, _ε_ Output : Cost of considering interval [ _i_ 1 _, i_ 2] monotonically increasing or decreasing ``` //The cost is computed w.r.t. a monotonically increasing or decreasing version of ``` `the` `histogram` `in` [ _i_ 1 _, i_ 2] `,` `which` `is` `computed` `using` `the` `Pool` `Adjacent` `Violators` ``` algorithm //Get subhistogram ``` 1 _h_ <sup>_s_</sup> = _{hi_ such that _i ∈{i_ 1 _, · · ·_ _, i_ 2 _}}_ ``` //Number of bins: ``` 2 _L_ = _i_ 2 _−_ _i_ 1 + 1 ``` //Number of samples in subhistogram: ``` 3 _N_ = <sup>�</sup> _i_ <sup>_L_</sup> =1 <sup>_h_</sup> _i_ <sup>_s_</sup> `//Get` `monotone` `version` `of` `subhistogram` `(Grenander` `estimator` `of` _h_ <sup>_s_</sup> `)` 4 _r_ ¯ = _PoolAdjacentV iolators_ ( _hs, type_ ) `//Algorithm` `3` ``` //Normalize histograms ``` 5 _h_ <sup>_s_</sup> _←_ <sup>_<u>hs</u>_</sup> _N_ 6 _r_ ¯ _←_ _<u>r</u>_ <u>¯</u> _N_ `//Compute` `maximum` `relative` `entropy` `between` `all` `possible` `intervals` `of` _h_ <sup>_s_</sup> `and` _r_ ¯ 7 _H_ = max[ _a,b_ ] _∈{_ 1 _,···,L} Hhs,r_ ¯([ _a, b_ ]) `//` _Hhs,r_ ¯([ _a, b_ ]) `is` `defined` `in` `Equation` (4) `//Compute` `cost` _C_ `//` _C_ `assesses` `the` `expected` `number` `of` `rejections` `of` `the` `monotone` `hypothesis` `//If` _C_ _≥_ 0 `the` `monotone` `hypothesis` `is` `meaningfully` `rejected` ``` //Smaller costs mean that the monotone hypothesis is less meaningfully rejected ``` 8 _C_ = _N_ _· H −_ log( _L_ ( _L_ + 1) _/_ 2 _ε_ ) `//Equation` (6) 9 return _C_ 81 <u>Algorithm</u> <u>3:</u> <u>Pool</u> <u>Adjacent</u> <u>Violators</u> <u>Algorithm</u> Input : input histogram, _h_ = ( _hi_ ) _i_ =1 _···L_ Input : type of computation, _type ∈_ ‘increasing’ _,_ ‘decreasing’ Output : output monotone histogram, _r_ ¯ = ( _ri_ ) _i_ =1 _···L_ ``` //Initialize output histogram ``` 1 _r_ ¯ = _h_ 2 do 3 if _type_ == _‘increasing’_ then ``` //List of monotonically decreasing intervals ``` 4 _I_ _←_ Intervals [ _i, j_ ] such that _ri_ _≥_ _ri_ +1 _≥· · · ≥_ _rj_ and _ri_ _> ri−_ 1 and _rj_ _< rj_ +1 5 else ``` //List of monotonically increasing intervals ``` 6 _I_ _←_ Intervals [ _i, j_ ] such that _ri_ _≤_ _ri_ +1 _≤· · · ≤_ _rj_ and _ri_ _< ri−_ 1 and _rj_ _> rj_ +1 ``` //Replace each monotonically decreasing/increasing interval by constant value ``` 7 for _each_ [ _i, j_ ] _∈I_ do 8 for _k_ = _{i, · · ·_ _, j}_ do 9 _rk_ = <sup>_<u>ri</u>_</sup> _j_ <sup><u>+</u></sup> _−_ <sup>_<u>···</u>_</sup> _i_ +1 <sup><u>+</u></sup> <sup>_<u>rj</u>_</sup> 10 while _I_ _is_ _not_ _empty_ 11 return _r_ ¯ Algorithm 4: FTC algorithm (for circular histograms) Input : input circular histogram, _h_ = ( _hi_ ) _i_ =1 _···L_ Input : maximum expected number of meaningful rejections of unimodal law, _ε_ (default: _ε_ = 1) Output : segmentation of the histogram into _n_ + 1 meaningful modes, _s_ = _{s_ 0 _, · · ·_ _, sn}_, with _s_ 0 _< s_ 1 _< · · · < sn_, (last mode in [ _sn, s_ 0]) ``` //Build auxiliary histogram: concatenation of 3 copies of input histogram ``` 1 _h_ aux = _{h, h, h}_ ``` //Segmentation of auxiliary histogram ``` 2 _s_ aux = `FTC` ~~`a`~~ `lgorithm` ( _h_ aux _, ε_ ) ``` //Segmentation of input histogram ``` 3 _s ←−∅_ `//Initialize` `output` `to` `empty` `set` 4 for _each_ _si_ _∈_ _saux_ do 5 if _si_ _> L_ _and_ _si_ _≤_ 2 _L_ then 6 _s ←−_ _s ∪{si −_ _L}_ `//Add` `shifted` `value` `to` `final` `list` 7 return _s_ 82 ## 2.4 Examples Figure 1-top displays two examples of the use of the FTC algorithm for the segmentation of a histogram into its modes, using the default parameter _ε_ = 1. The histograms in both images are identical, but the one on the right has been segmented under the assumption that it is circular (i.e. using Algorithm 4). In the bottom row the histogram has been segmented using a smaller value of _ε_ ( _ε_ = 0 _._ 001), which leads to a coarser segmentation. 10000 8000 6000 4000 2000 0 10000 8000 6000 4000 2000 0 10000 8000 6000 4000 2000 0 10000 8000 6000 4000 2000 0 Figure 1: Top, segmentation of a histogram into its modes using the “classical” (left) and “circular” (right) versions of the FTC algorithm, with _ε_ = 1. Bottom, results with _ε_ = 0 _._ 001. # 3 Color Palette Estimation In this section we describe the application of the FTC algorithm to the analysis of the colors of an image. In particular, we deal with the problem of finding the minimum set of colors needed to describe an image. By analogy between this set of colors and the palette of a painter the problem is usually referred to as _color_ _palette_ _estimation_ . The method presented in this section was proposed in [7] (refer also to [3] for further details). The authors imposed two requirements for the construction of their palette, namely, reduction of redundant colors, and preservation of rare colors. They proposed a hierarchical algorithm in which colors were first discriminated by their hue; next, colors with similar hue were discriminated by their saturation; and finally, colors with similar hue and saturation were discriminated by their intensity. At each step of the algorithm the discrimination between different values of a given magnitude (hue, saturation or illumination) was performed by analyzing the associated 1D histograms using the FTC algorithm. ## 3.1 Color Representation The color palette is estimated from the HSI representation of the image colors. The reason is that hue (H), saturation (S) and intensity (I) are magnitudes that can be interpreted intuitively and have a physical meaning [15]: the hue relates to the visual sensation of color purity, the saturation measures the proportion of white light diluted with pure color, and the intensity is related to the amount of light reflected by an illuminated object. 83 Figure 2: RGB color cube [14] and illustration of H, S and I magnitudes for a given color point _M_ = ( _R, G, B_ ). In [3] the authors redefine the classical formulas for the conversion from RGB to HSI color space. They adapt the formulas to the following intuitive definitions of the three magnitudes: the intensity is the average of the 3 color components; the saturation measures the distance from the color point to the _gray_ _axis_ (locus of points in RGB space having identical color components); finally the hue is an angle around the gray axis <sup>3</sup> . Figure 2 illustrates the previous definitions and the conversion formulas are given by Equations (9)–(11). _S_ = _I_ = <sup>_<u>R</u>_</sup> <sup><u>+</u></sup> <sup>_<u>G</u>_</sup> <sup><u>+</u></sup> <sup>_<u>B</u>_</sup> _,_ (9) 3 ~~�~~ ( _R −_ _I_ ) <sup>2</sup> + ( _G −_ _I_ ) <sup>2</sup> + ( _B −_ _I_ ) <sup>2</sup> _,_ (10) _._ (11) _H_ = sign ( _−_ 2( _R −_ _I_ ) + ( _G −_ _I_ ) + ( _B −_ _I_ )) _·_ arccos - _<u>G −</u>_ _<u>B</u>_ _~~√~~_ 2 _S_ With these definitions, the range of values of intensity, saturation and hue are, respectively, [0 _,_ 255], [0 _,_ 208 _._ 2066] <sup>4</sup>, [ _−π,_ + _π_ ]. ## 3.2 Achromatic Colors From Equation (11) we can see that the hue magnitude cannot be defined for colors in the gray axis (i.e. colors with zero saturation). In practice, the hue component cannot reliably be computed for RGB colors whose saturation is small. For this reason, hue values are only computed for colors with large enough saturation, which are considered as _chromatic_, in contrast with low-saturated colors, which are called _achromatic_ . In [7] the saturation threshold that discriminates chromatic from achromatic colors is computed using a simple argument: for a fixed intensity, at a distance _S_ from the gray axis the maximum allowed number of color points is 2 _πS_, therefore, if we decide to quantize the hue component with _Q_ different values _S_ must be above 2 _<u>Qπ</u>_ <sup>to</sup> <sup>allow</sup> <sup>this</sup> <sup>quantization</sup> _√_ 3The angle is computed with respect to vector _v_ = (0 _,_ 1 _/_ _√_ 2 _, −_ 1 _/_ 3The angle is computed with respect to vector _v_ = (0 _,_ 1 _/_ 2 _, −_ 1 _/_ 2), which is orthonormal to the gray axis (see Figure 2). The angle ranges from 0 to _π_, and a sign is assigned depending on the projection of vector <sup>_−−→_</sup> _PM_ onto ( _−_ 2 _,_ 1 _,_ 1), which is orthogonal to the gray axis and to the previous vector. 4The maximum corresponds to the saturation of pure red, green or blue colors, e.g. (255 _,_ 0 _,_ 0). 84 Figure 3: Illustration of the criterion used to fix the saturation threshold for the computation of hue values. If the saturation is too small ( _R_ ), then the hue magnitude cannot be quantized into _Q_ bins. This can be achieved only when the saturation is large enough ( _R_ <sup>_′_</sup> ). (see Figure 3). The saturation threshold defines a cylinder in RGB space that contains the achromatic colors, the so-called _gray_ _cylinder_ . ## 3.3 Color Palette and Gray+Color Palette In [7] and [3] it was proposed the following hierarchical algorithm for the construction of the color palette: _1._ _Apply_ _the_ _FTC_ _algorithm_ _on_ _the_ _hue_ _histogram_ _of_ _the_ _image_ _(computed_ _from_ _the_ _colors_ _not_ _belonging_ _to_ _the_ _gray-cylinder)._ _Let_ _S_ _be_ _the_ _obtained_ _segmentation._ _2._ _Link_ _each_ _color_ _of_ _the_ _gray_ _cylinder_ _to_ _its_ _corresponding_ _interval_ _Si_ = [ _si, si_ +1] _,_ _according_ _to_ _its_ _hue_ _value._ _If_ _the_ _color_ _belongs_ _to_ _the_ _gray_ _axis,_ _then_ _consider_ _that_ _its_ _hue_ _value_ _is_ _zero._ _3._ _For_ _each_ _i,_ _construct_ _the_ _saturation_ _histogram_ _of_ _all_ _the_ _colors_ _in_ _the_ _image_ _whose_ _hue_ _belongs_ _to_ _Si._ _Take_ _into_ _account_ _the_ _colors_ _of_ _the_ _gray_ _cylinder._ _Apply_ _the_ _FTC_ _algorithm_ _on_ _the_ _corresponding saturation histogram._ _For each i,_ _let {Si,_ 1 _, Si,_ 2 _, . . .} be the obtained segmentation._ _4._ _For_ _each_ _i_ _and_ _each_ _j,_ _compute_ _and_ _segment_ _the_ _intensity_ _histogram_ _of_ _all_ _the_ _colors_ _whose_ _hue_ _and_ _saturation_ _belong_ _to_ _Si_ _and_ _Si,j,_ _including_ _those_ _in_ _the_ _gray_ _cylinder._ Remark that the above algorithm assumes that the input is a color image, and therefore cannot be applied to grayscale images. Moreover, as can be observed in Figures 4 to 6, it can produce palettes with an overrepresentation of dark colors. For these reasons, we propose in the current paper an alternative version of the algorithm in which Step 2 has been modified as follows: _2’)_ _Compute_ _the_ _intensity_ _histogram_ _for_ _the_ _pixels_ _of_ _the_ _gray_ _cylinder_ _and_ _apply_ _the_ _FTC_ _algo-_ _rithm_ _to_ _obtain_ _a_ _palette_ _of_ _gray_ _values._ 85 The rest of steps of the algorithm remain the same (except that all the references to the gray cylinder must now be removed). As a result of this modified algorithm both a gray and a color palette are obtained. In the next section, the images shown in Figures 4, 5 and 6 permit to compare the results of both versions of the algorithm. A complete description of the automatic color palette algorithm (in its two versions) is provided in Algorithm 11. Several auxiliary functions are also described in Algorithms 5 to 9. In particular, the set of gray values that compose the gray palette is computed in Algorithm 6, the segmentation of the hue, saturation and intensity histograms is described in Algorithms 7 and 8. Finally, the hierarchical process for the computation of the color palette is described in Algorithm 9. The only parameters of the algorithm are the sizes of the bins (quantization factors) used to compute the hue, saturation and intensity histograms. The default values for these parameters are, respectively, 6 <sup>_◦_</sup>, 5 and 5, although they can be modified by the user. <u>Algorithm</u> <u>5:</u> <u>Compute</u> <u>histogram</u> Input : array of values _v_, of size _N_ Input : number of histogram bins, _L_ Input : quantization of histogram bins, _q_ Output : histogram, _h_ = ( _hi_ ) _i_ =1 _···L_ ``` //Initialize all bins of histogram to zero ``` 1 _h ←−_ 0 2 for _n_ _from_ 1 _to_ _N_ do 3 _i_ = _⌊v_ [ _n_ ] _/q⌋_ + 1 `//index` `of` `bin,` `from` 1 `to` _L_ `,` _⌊·⌋_ `is` `floor` `operator` 4 _hi_ _←−_ _hi_ + 1 `//increase` `bin` `count` 5 return _h_ The lists of pixels associated to each mode of the histograms obtained with the hierarchical algorithm are recorded during the process. These lists are used to compute the average RGB color of all the pixels contributing to the same mode. These colors are displayed in a _color_ _palette_ _image_, which shows, in successive rows: _•_ the average intensity values of each mode of the histogram of intensities of the achromatic colors (that is, the gray palette), if the new version of the algorithm is used; _•_ the average RGB values of the pixels contributing to the modes of the hue histogram (first step of the algorithm); _•_ the average RGB values of the pixels contributing to the modes of the saturation histograms computed in the third step of the algorithm; _•_ the average RGB values of the pixels contributing to the modes of the intensity histograms computed in the last step of the algorithm (that is, the final color palette). A second output of the algorithm is a segmentation of the input image using the colors in the palette. In [7] the colors in the final palette were used as seeds of a K-means algorithm in order to obtain a segmentation of the original image. In [3] a more direct approach was used: since the set of pixels associated to each mode of the hue, saturation and intensity histograms is known, the average RGB value of each set was computed and applied to all the pixels in the set. This is the approach that has been used in our implementation (see Algorithm 10). The online demo that complements this paper lets the user upload any image, choose the quantization factors for the construction of the histograms, and displays both the color palette image and 86 <u>Algorithm</u> <u>6:</u> <u>Compute</u> <u>palette</u> <u>of</u> <u>grays</u> Input : color or grayscale image ( _u_ = ( _H, S, I_ ), or _u_ = _I_ ) Input : saturation threshold, _S_ min Input : number of bins in Intensity histogram, _L_ Input : quantization of histogram bins, _q_ Input : segmentation of the Intensity histogram into _n_ meaningful modes, _s_ = _{s_ 0 _, · · ·_ _, sn}_, with 1 = _s_ 0 _< s_ 1 _< · · · < sn_ = _L_ Output : gray level palette (list of main gray levels of _u_ ), _G_ = _{G_ 1 _, · · ·_ _, Gn}_ Output : sets of pixels associated to each gray level in the palette, _PG_ = _{PG_ 1 _, · · ·_ _, PGn}_ ``` //Initialize output values ``` 1 _G_ _←−∅_ 2 _PG_ _←−∅_ `//Assign` `labels` `to` `histogram` `bins:` `assign` `same` `label` `to` `all` `bins` `in` `range` [ _si−_ 1 _, si_ ] 3 for _each_ _i ∈{_ 1 _, · · ·_ _, n}_ do 4 for _k_ = _{si−_ 1 _, · · ·_ _, si}_ do 5 `label` [ _k_ ] _←−_ _i_ `//Compute` `average` `gray` `level` `and` `list` `of` `pixels` `associated` `to` `each` `segment` [ _si−_ 1 _, si_ ] ``` //Initialize average values and lists of pixels ``` 6 for _each_ _i ∈{_ 1 _, · · ·_ _, n}_ do 7 _Gi_ = 0 8 _PGi_ _←−∅_ 9 for _each_ _pixel_ _x_ _of_ _image_ _u_ do `//Consider` `gray` `value` `if` `the` `saturation` `of` `the` `pixel` `is` `below` `threshold` _S_ `min` 10 if _S_ ( _x_ ) _≤_ _Smin_ then 11 _k_ = _⌊I_ ( _x_ ) _/q⌋_ + 1 `//bin` `to` `which` `intensity` `value` `at` `pixel` _x_ `contributes` 12 _i_ = `label` [ _k_ ] `//index` `of` `segment` `with` `intensity` `values` `in` `range` [ _qsi−_ 1 _, qsi_ ] 13 _Gi_ = _Gi_ + _I_ ( _x_ ) `//update` `total` `gray` `value` `associated` `to` `segment` _i_ 14 _PGi_ _←−_ _PGi_ _∪_ _x_ `//add` `pixel` `to` `list` `associated` `to` `segment` _i_ ``` //Compute averages ``` 15 for _each_ _i ∈{_ 1 _, · · ·_ _, n}_ do 16 _Gi_ = _Gi/|PGi|_ `//` _| · |_ `denotes` `the` `size` `of` `the` `set` 17 _G_ _←−G ∪_ _Gi_ 18 _PG_ _←−_ _PG_ _∪_ _PGi_ 19 return _G_, _PG_ the segmentation result, for the two versions of the algorithm. It also permits to select the parameter _ε_ of the FTC algorithm, which leads to finer or coarser segmentations of the histograms. 87 <u>Algorithm</u> <u>7:</u> <u>Hue</u> <u>segmentation</u> Input : color image _u_ = ( _H, S, I_ ) Input : saturation threshold, _S_ min Input : number of bins in Hue histogram, _LH_ Input : quantization of Hue histogram bins, _qH_ Input : segmentation of the Hue histogram into _n_ + 1 meaningful modes, _s_ = _{s_ 0 _, · · ·_ _, sn}_, with _s_ 0 _< s_ 1 _< · · · < sn_ (last mode is in [ _sn, s_ 0]) Input : `optionGray` boolean variable, if True compute gray+color palette, else only color palette Output : list of pixels associated to each mode of the Hue histogram, _PH_ ``` //Initialize output: empty list ``` 1 _PH_ _←−∅_ ``` //Assign labels to Hue histogram bins: assign same label to all bins in range ``` [ _si−_ 1 _, si_ ] 2 for _each_ _i ∈{_ 1 _, · · ·_ _, n}_ do 3 for _k_ = _{si−_ 1 _, · · ·_ _, si}_ do 4 `label` [ _k_ ] _←−_ _i_ `//Take` `into` `account` `that` `the` `Hue` `histogram` `is` `circular` `(last` `mode` `is` `in` [ _sn, s_ 0] `)` 5 for _k_ = _{sn, · · ·_ _, LH}_ do 6 `label` [ _k_ ] _←−_ _n_ + 1 7 for _k_ = _{_ 0 _, · · ·_ _, s_ 0 _}_ do 8 `label` [ _k_ ] _←−_ _n_ + 1 ``` //Compute list of pixels associated to each segment of Hue histogram ``` 9 for _each_ _i ∈{_ 1 _, · · ·_ _, n_ + 1 _}_ do 10 _PHi_ _←−∅_ 11 for _each_ _pixel_ _x_ _of_ _image_ _u_ do `//If` `optionGray` `is` `True` `consider` `only` `pixels` `whose` `saturation` `is` `above` _S_ `min,` ``` else use all pixels ``` 12 if `optionGray` _is_ _False_ _or_ _S_ ( _x_ ) _> Smin_ then 13 _k_ = _⌊H_ ( _x_ ) _/qH⌋_ + 1 `//bin` `to` `which` `hue` `value` `at` `pixel` _x_ `contributes` 14 _i_ = `label` [ _k_ ] `//index` `of` `segment` `the` `bin` `belongs` `to` 15 _PHi_ _←−_ _PHi_ _∪_ _x_ `//add` `pixel` `to` `list` `associated` `to` `segment` _i_ 16 for _each_ _i ∈{_ 1 _, · · ·_ _, n_ + 1 _}_ do 17 _PH_ _←−PH ∪_ _PHi_ 18 return _PH_ 88 <u>Algorithm</u> <u>8:</u> <u>Channel</u> <u>segmentation</u> Input : color image _u_ = ( _H, S, I_ ) Input : channel identifier, _C_ _∈{S, I}_, _S_ (saturation) or _I_ (intensity) Input : list of image pixels _P_ <sup>0</sup> Input : number of bins in channel histogram, _L_ Input : quantization of channel histogram bins, _q_ Input : segmentation of the channel histogram into _n_ meaningful modes, _s_ = _{s_ 0 _, · · ·_ _, sn}_, with _s_ 0 _< s_ 1 _< · · · < sn_ Output : list of pixels associated to each mode of the channel histogram, _P_ ``` //Initialize output: empty list ``` 1 _P_ _←−∅_ ``` //Assign labels to channel histogram bins: assign same label to all bins in range ``` [ _si−_ 1 _, si_ ] 2 for _each_ _i ∈{_ 1 _, · · ·_ _, n}_ do 3 for _k_ = _{si−_ 1 _, · · ·_ _, si}_ do 4 `label` [ _k_ ] _←−_ _i_ ``` //Compute list of pixels associated to each segment of channel histogram ``` 5 for _each_ _i ∈{_ 1 _, · · ·_ _, n}_ do 6 _Pi_ _←−∅_ 7 for _each_ _pixel_ _x_ _∈_ _P_ <sup>0</sup> do 8 _k_ = _⌊C_ ( _x_ ) _/q⌋_ + 1 `//bin` `to` `which` `channel` `value` `at` `pixel` _x_ `contributes` 9 _i_ = `label` [ _k_ ] `//index` `of` `segment` `the` `bin` `belongs` `to` 10 _Pi_ _←−_ _Pi ∪_ _x_ `//add` `pixel` `to` `list` `associated` `to` `segment` _i_ 11 for _each_ _i ∈{_ 1 _, · · ·_ _, n}_ do 12 _P_ _←−P_ _∪_ _Pi_ 13 return _P_ 89 <u>Algorithm</u> <u>9:</u> <u>Compute</u> <u>palette</u> <u>of</u> <u>colors</u> Input : color image _u_, RGB and HSI values are known for each pixel Input : saturation threshold, _S_ min Input : number of bins of Hue, Saturation and Intensity histograms, _LH_, _LS_, _LI_ Input : quantization of Hue, Saturation and Intensity histogram bins, _qH_, _qS_, _qI_ Input : segmentation of the Hue histogram into _n_ + 1 meaningful modes, _sH_ = _{s_ 0 _, · · ·_ _, sn}_, with _s_ 0 _< s_ 1 _< · · · < sn_ (last mode is in [ _sn, s_ 0]) Input : parameter of FTC algorithm, _ε_ Input : `optionGray` boolean variable, if True compute gray+color palette, else only color palette Output : color palette (list of main colors of _u_ ), _C_ = _{_ _C_ 1 _, · · ·_ _,_ _C_ _M_ _}_ Output : sets of pixels associated to each color in the palette, _PC_ = _{PC_ 1 _, · · ·_ _, PCN_ _}_ ``` //Obtain list of pixels associated to each mode of the Hue histogram ``` 1 _PH_ _←−_ `Hue` ~~`s`~~ `egmentation` ( _u, S_ min _, LH, qH, sH,_ `optionGray` ) `//Algorithm` `7` ``` //Compute Saturation histogram for each mode of Hue histogram, and segment it ``` 2 for _each_ _PHi_ _∈PH_ do 3 _S_ <sup>_′_</sup> _←−∅_ `//Empty` `array` `of` `saturation` `values` 4 for _each_ _x_ _∈_ _PHi_ do 5 _S_ <sup>_′_</sup> _←−_ _S_ ( _x_ ) `//Add` `value` `to` `array` 6 _hS_ _←−_ `compute` `histogram` ( _S_ <sup>_′_</sup> _, LS, qS_ ) `//Algorithm` `5` ``` //Segment Saturation histogram ``` 7 _sS_ _←−_ `FTC` ~~`a`~~ `lgorithm` ( _hS, ε_ ) `//Algorithm` `1` ``` //Obtain list of pixels associated to each mode of the Saturation histogram ``` 8 _PHS_ _←−_ `channel` ~~`s`~~ `egmentation` ( _u, S, PHi, LS, qS, sS_ ) `//Algorithm` `8` ``` //Compute Intensity histogram for each mode of Saturation histogram, and segment it ``` 9 for _each_ _PHSi_ _∈PHS_ do 10 _I_ <sup>_′_</sup> _←−∅_ `//Empty` `array` `of` `intensity` `values` 11 for _each_ _x_ _∈_ _PHSi_ do 12 _I_ <sup>_′_</sup> _←−_ _I_ ( _x_ ) `//Add` `value` `to` `array` 13 _hI_ _←−_ `compute` ~~`h`~~ `istogram` ( _I_ <sup>_′_</sup> _, LI, qI_ ) `//Algorithm` `5` ``` //Segment Intensity histogram ``` 14 _sI_ _←−_ `FTC` `algorithm` ( _hI, ε_ ) `//Algorithm` `1` ``` //Obtain list of pixels associated to each mode of the Intensity histogram ``` 15 _PHSI_ _←−_ `channel` ~~`s`~~ `egmentation` ( _u, I, PHSi, LI, qI, sI_ ) `//Algorithm` `8` 16 _PC_ _←−_ _PC ∪PHSI_ ``` //Compute average RGB color for each group of pixels ``` 17 _C_ _←−∅_ 18 for _each_ _Pi_ _∈_ _PC_ do 19 _C_ _i_ = ( _Ri, Gi, Bi_ ) _←−_ (0 _,_ 0 _,_ 0) 20 for _each_ _x_ _∈_ _Pi_ do 21 ( _Ri, Gi, Bi_ ) _←−_ ( _Ri, Gi, Bi_ ) + ( _R_ ( _x_ ) _, G_ ( _x_ ) _, B_ ( _x_ )) 22 ( _Ri, Gi, Bi_ ) _←−_ ( _Ri, Gi, Bi_ ) _/|Pi|_ _| · |_ `denotes` `the` `number` `of` `pixels` `in` `the` `set` 23 _C_ _←−C ∪_ _C_ _i_ 24 return _C_, _PC_ 90 <u>Algorithm</u> <u>10:</u> <u>Get</u> <u>segmented</u> <u>image</u> Input : color or gray scale image _u_ Input : gray level palette (list of main gray levels of _u_ ), _G_ = _{G_ 1 _, · · ·_ _, GN_ _}_ Input : color palette (list of main colors of _u_ ), _C_ = _{_ _C_ 1 _, · · ·_ _,_ _C_ _M_ _}_ Input : sets of pixels associated to each gray level in the palette, _PG_ = _{PG_ 1 _, · · ·_ _, PGN_ _}_ Input : sets of pixels associated to each color in the palette, _PC_ = _{PC_ 1 _, · · ·_ _, PCN_ _}_ Output : segmented image _v_ 1 for _each_ _set_ _PGi_ _∈_ _PG_ do 2 for _each_ _pixel_ _x_ _∈_ _PGi_ do 3 _v_ ( _x_ ) = _Gi_ `//Assign` `constant` `gray` `level` `to` `all` `pixels` `in` `set` 4 for _each_ _set_ _PCi_ _∈_ _PC_ do 5 for _each_ _pixel_ _x_ _∈_ _PCi_ do 6 _v_ ( _x_ ) = _C_ _i_ `//Assign` `constant` `color` `to` `all` `pixels` `in` `set` 7 return _v_ 91 <u>Algorithm</u> <u>11:</u> <u>Automatic</u> <u>Color</u> <u>Palette</u> Input : color or grayscale image ( _u_ = ( _R, G, B_ ), or _u_ = _I_ ), with values in range [0 _,_ 255] Input : quantization parameters for the Hue, Saturation and Intensity histograms ( _qH_, _qS_, _qI_ ) Input : parameter of FTC algorithm, _ε_ Input : `optionGray` boolean variable, if True compute gray+color palette, else only color palette Output : color palette (list of main colors and/or gray levels in the image), _L_ Output : segmentation of the input image using the colors in the palette, _v_ 1 if _u_ _is_ _color_ _image_ then `//Convert` `from` `RGB` `to` `HSI` `using` `Equations` (9) `to` (11) ``` //Use degrees to represent angles in the computation of Hue values (range [0, 360)) //Compute number of bins of histograms ``` 2 _LH_ = _⌈_ <sup><u>360</u></sup> _qH_ <sup>_⌉_</sup> `//number` `of` `bins` `in` `Hue` `histogram,` _⌈·⌉_ `is` `ceil` `operator` 3 _LI_ = _⌈_ <sup><u>256</u></sup> _qI_ <sup>_⌉_</sup> `//number` `of` `bins` `in` `Intensity` `histogram,` _⌈·⌉_ `is` `ceil` `operator` 4 _LS_ = _⌈_ <sup><u>208</u></sup> _qS_ <sup>_⌉_</sup> `//number` `of` `bins` `in` `Saturation` `histogram,` _⌈·⌉_ `is` `ceil` `operator` ``` //Compute minimum saturation value that prevents quantization problems in Hue histogram (see Section 3.2 for details) ``` 5 _S_ min = _LH/_ 2 _π_ ``` //Compute histogram of Hue values with enough saturation, and, if optionGray is True, histogram of Intensity values with low saturation ``` 6 _H_ <sup>_′_</sup> _←−∅_ `//Empty` `array` `of` `valid` `Hue` `values` 7 _I_ <sup>_′_</sup> _←−∅_ `//Empty` `array` `of` `low-saturated` `Intensity` `values` 8 for _each_ _pixel_ _x_ _of_ _image_ _u_ do 9 if _S_ ( _x_ ) _> Smin_ then 10 _H_ <sup>_′_</sup> _←−_ _H_ ( _x_ ) `//Add` `value` `to` `array` 11 else 12 if `optionGray` _is_ _True_ then 13 _I_ <sup>_′_</sup> _←−_ _I_ ( _x_ ) `//Add` `value` `to` `array` 14 if `optionGray` _is_ _True_ then 15 _hI_ _←−_ `compute` ~~`h`~~ `istogram` ( _I_ <sup>_′_</sup> _, LI, qI_ ) `//Algorithm` `5` ``` //Segment Intensity histogram ``` 16 _sI_ _←−_ `FTC` ~~`a`~~ `lgorithm` ( _hI, ε_ ) `//Algorithm` `1` ``` //Compute gray palette ``` 17 _G, PG_ _←−_ `Compute` ~~`g`~~ `ray` ~~`p`~~ `alette` ( _u, S_ min _, LI, qI, sI_ ) `//Algorithm` `6` 18 else 19 _G_ _←−∅_, _PG_ _←−∅_ 20 _hH_ _←−_ `compute` ~~`h`~~ `istogram` ( _H_ <sup>_′_</sup> _, LH, qH_ ) `//Algorithm` `5` ``` //Segment Hue histogram ``` 21 _sH_ _←−_ `FTC` ~~`a`~~ `lgorithm` ~~`c`~~ `ircular` ( _hH, ε_ ) `//Algorithm` `4` ``` //Compute color palette ``` 22 _C, PC_ _←−_ `Compute` `color` `palette` ( _u, S_ min _, LH_ _,LS_ _,LI, qH, qS, qI, sH, ε,_ `optionGray` ) `//Algorithm` `9` ``` //Final color palette ``` 23 _L ←−G ∪C_ ``` //Segmented output image ``` 24 _v_ = _←−_ `get` ~~`s`~~ `egmented` ~~`i`~~ `mage` ( _u, G, C, PG, PC_ ) `//Algorithm` `10` 25 return _L_, _v_ 92 # 4 Experimental Results Figures 4, 5 and 6 show the results of applying both versions of the algorithm to different images, using the default values of the parameters. For each version of the algorithm, the following images are displayed: 1) H-segmented image, where the same color has been assigned to all the pixels contributing to the same mode of the hue histogram. The assigned color is the average RGB value of the set of pixels. The colors displayed in this image are the ones shown in the first row of the color palette. If the new version of the algorithm is used, the color of the achromatic pixels contributing to the same mode of the intensity histogram is also replaced by the average intensity value of the set of pixels (the values in the gray palette). 2) HS-segmented image, where the same color has been assigned to all the pixels contributing to the same mode of the saturation histograms computed in the third step of the algorithm. The assigned color is the average RGB value of the set of pixels. The colors displayed in this image are the ones shown in the second row of the color palette. 3) HSI-segmented image, the final segmentation results, whose colors are the ones displayed in the last row of the color palette image. 4) Color palette image. We observe that with the new version of the algorithm we obtain a more compact representation of the image colors: the palette contains less colors and a fewer number of similar low-saturated colors is obtained in the final palette (observe the last row in the color palette images of the three figures). On the other hand, the final segmentations obtained with both versions of the algorithm are very similar. For these reasons, in the following experiments, only the new version of the algorithm (the so-called _gray+color_ version) shall be used. Figures 7, 8 and 9 explore the ability of the algorithm to preserve rare colors in the images, that is, colors corresponding to a small fraction of the image pixels. In Figure 7 we observe that the red color corresponding to the flowers has effectively been preserved. However, this is not the case with the yellow color of the rope in Figure 8 or the red color of the flowers in Figure 9. By observing the first row of the color palettes and the H-segmentations obtained for these images we see that, in the first step of the algorithm, these rare colors have been grouped together with other colors with similar hues, and the subsequent steps of the hierarchical method are unable to discriminate them based on their saturation or intensity. In order to improve the segmentation of the hue values in the first step of the algorithm, a finer quantization can be used. The default quantization factors for hue, saturation and intensity (6 <sup>_◦_</sup>, 5, and 5) provide good results in most cases, as shown in Figures 4 to 7, although in some cases the results can be improved using different factors. Figures 10 to 13 display the segmentation results obtained for different sets of quantization factors. In Figures 10 and 11 decreasing quantization factors for the hue have been used. We observe that the rare colors are correctly represented for finer quantizations. However, a side effect of using a finer hue quantization is that the threshold that separates achromatic from chromatic colors increases (see Section 3.2), and therefore a higher number of colors are considered achromatic and thus represented by gray values. In Figures 12 and 13 different quantizations for the saturation and intensity components have been tested, for a fixed quantization of the hue. We observe that a finer quantization of the saturation permits to distinguish more image details (see the mountains on the left side of the image in Figure 12, or the letters of the boat in Figure 13). As the quantization factor increases less details are visible, 93 Figure 4: Original image and results of applying the original version (left) and the new version (right) of the Automatic Color Palette algorithm. From top to bottom: H-segmented, HS-segmented, HSI-segmented images and color palette image. The palette on the left side contains 36 colors (last row of the palette image), while the one on the right 6+24 (6 for the gray palette and 24 for the color palette). 94 Figure 5: Original image and results of applying the original version (left) and the new version (right) of the Automatic Color Palette algorithm. From top to bottom: H-segmented, HS-segmented, HSI-segmented images and color palette image. The palette on the left side contains 39 colors (last row of the palette image), while the one on the right 5+24 (5 for the gray palette and 24 for the color palette). 95 Figure 6: Original image and results of applying the original version (left) and the new version (right) of the Automatic Color Palette algorithm. From top to bottom: H-segmented, HS-segmented, HSI-segmented images and color palette image. The palette on the left side contains 47 colors (last row of the palette image), while the one on the right 5+30 (5 for the gray palette and 30 for the color palette). 96 Figure 7: From left to right and from top to bottom: original image, final segmentation, H-segmentation, HS-segmentation and gray+color palette. The gray palette is composed of 2 gray levels and the color palette of 13 colors. although little differences can be observed in these images between the results for quantization factors 5 and 10. Similar remarks can be made concerning the quantization factor of the intensity component: for finer quantizations more details are visible in some parts of the images (see the foam in the river, in the bottom-left image of Figure 13), while less colors are obtained as the quantization factor increases. As expected, the number of colors in the palette increases when using finer quantizations. Variations in the saturation quantization affect only to the color palette, but not to the gray palette, while the intensity quantization affects both palettes. Finally, the effect of the parameter _ε_ of the FTC algorithm on the palette results is tested. For the images in Figures 8 and 9, for which the rare colors were not detected using the default parameters, we show the results obtained with increasing values of _ε_, (the quantization parameters are fixed to their default values). We observe that the number of detected colors increases, since the histogram segmentations are finer. Eventually, the rare colors are included in the palette. Conversely, if we want to obtain a palette with less colors, we should decrease the value of the parameter. 97 Figure 8: From left to right and from top to bottom: original image, final segmentation, H-segmentation, HS-segmentation and gray+color palette. The gray palette is composed of 3 gray levels and the color palette of 19 colors. 98 Figure 9: From left to right and from top to bottom: original image, final segmentation, H-segmentation, HS-segmentation and gray+color palette. The gray palette is composed of 1 gray level and the color palette of 12 colors. _qH_ = 3, _qS_ = 5, _qI_ = 5 _qH_ = 2, _qS_ = 5, _qI_ = 5 _qH_ = 1, _qS_ = 5, _qI_ = 5 Figure 10: Effect of the variation of the quantization of the hue values. 99 _qH_ = 3, _qS_ = 5, _qI_ = 5 _qH_ = 2, _qS_ = 5, _qI_ = 5 _qH_ = 1, _qS_ = 5, _qI_ = 5 Figure 11: Effect of the variation of the quantization of the hue values. Original _qH_ = 6, _qS_ = 5, _qI_ = 5 (5+23) _qH_ = 6, _qS_ = 2, _qI_ = 5 (5+33) _qH_ = 6, _qS_ = 10, _qI_ = 5 (5+23) _qH_ = 6, _qS_ = 5, _qI_ = 2 (9+36) _qH_ = 6, _qS_ = 5, _qI_ = 10 (3+21) Figure 12: Effect of the variation of the quantization of the saturation and intensity values. The values in parentheses are the number of colors in the gray and color palettes. 100 Original _qH_ = 6, _qS_ = 5, _qI_ = 5 (5+20) _qH_ = 6, _qS_ = 2, _qI_ = 5 (5+35) _qH_ = 6, _qS_ = 10, _qI_ = 5 (5+19) _qH_ = 6, _qS_ = 5, _qI_ = 2 (11+49) _qH_ = 6, _qS_ = 5, _qI_ = 10 (3+19) Figure 13: Effect of the variation of the quantization of the saturation and intensity values. The values in parentheses are the number of colors in the gray and color palettes. 101 _ε_ = 1 (default) (3+19) _ε_ = 10 (3+24) _ε_ = 100 (8+44) Figure 14: Effect of the variation of the parameter _ε_ of the FTC algorithm. The values in parentheses are the number of colors in the gray and color palettes. _ε_ = 1 (default) (1+12) _ε_ = 10 (1+25) _ε_ = 100 (1+64) Figure 15: Effect of the variation of the parameter _ε_ of the FTC algorithm. The values in parentheses are the number of colors in the gray and color palettes. 102 # 5 Conclusions We have presented in this paper a detailed description of an algorithm for the automatic parsing of a 1D histogram into its meaningful modes, that is, intervals where the histogram follows a unimodal distribution. This algorithm has then been used to analyze, in a hierarchical way, the histograms of the hue, saturation and intensity components of a digital image, in order to compute a minimum representation of the image colors, the so-called color palette. A slight modification of the original color palette estimation method (published in [7]) has been proposed, involving the treatment of the achromatic colors of the image, which leads to a gray+color palette which, in general, provides a more compact representation than the original method. Several experiments show that the presented method is able, in general, to obtain a minimum and accurate description of the image colors, although rare colors are sometimes missed. Further improvements of the method (such as the combination of the palettes obtained with different quantization factors) could permit the preservation of these colors in the final result. # Acknowledgment The authors acknowledge the Ministerio de Ciencia, Innovaci´on y Universidades (MCIU), the Agencia Estatal de Investigaci´on (AEI) and the European Regional Development Funds (ERDF) for its support to the project TIN2017-85572-P. This work has also been sponsored by the Comunitat Autonoma de les Illes Balears through the Direcci´o General de Pol´ıtica Universit`aria i Recerca with funds from the Tourist Stay Tax Law ITS 2017-006 (PRD2018/26). # Image Credits Kodak image dataset <sup>5</sup> Wikimedia commons CC0 <sup>6</sup> # References [1] M. Alvioli, A. C. Mondini, F. Fiorucci, M. Cardinali, and I. Marchesini, _Topography-driven_ _satellite_ _imagery_ _analysis_ _for_ _landslide_ _mapping_, Geomatics, Natural Hazards and Risk, 9 (2018), pp. 544–567. `[https://doi.org/10.1080/19475705.2018.1458050](https://doi.org/10.1080/19475705.2018.1458050)` . [2] M. Ayer, H. Brunk, G. Ewing, W. Reid, and E. Silverman, _An_ _empirical_ _distribution_ _function for sampling with incomplete information_, Annals of Mathematical Statistics, 26 (1955), pp. 641–647. [3] Ana Bel´en Petro Balaguer, _Analytical_ _methods_ _for_ _the_ _study_ _of_ _color_ _in_ _digital_ _images_, PhD thesis, Universitat de les Illes Balears, 2006. [4] L. Birg´e, _The_ _Grenander_ _estimator:_ _A_ _nonasymptotic_ _approach_, Annals of Mathematical Statistics, 17 (1989), pp. 1532–1549. `[https://doi.org/10.1214/aos/1176347380](https://doi.org/10.1214/aos/1176347380)` . 5 `[http://www.cs.albany.edu/~xypan/research/snr/Kodak.html](http://www.cs.albany.edu/~xypan/research/snr/Kodak.html)` 6 `[https://commons.wikimedia.org/wiki/File:Tomato_plants_growing_July_2013_in_garbage_cans.JPG](https://commons.wikimedia.org/wiki/File:Tomato_plants_growing_July_2013_in_garbage_cans.JPG)` 103 [5] T.M. Cover and J.A. Thomas, _Elements_ _of_ _Information_ _Theory_, John Wiley & Sons Inc., 1991. ISBN 978-0-471-24195-9. [6] J. Delon, A. Desolneux, J.L. Lisani, and A.B. Petro, _Histogram_ _analysis_ _and_ _its_ _appli-_ _cations_ _to_ _fast_ _camera_ _stabilization_, in 11th International Conference on Signals and Electronic Systems (IWSSIP), 2004. [7] ~~,~~ _Automatic_ _color_ _palette_, Inverse Problems & Imaging, 1 (2007), pp. 265–287. `[https:](https://doi.org/10.3934/ipi.2007.1.265)` `[//doi.org/10.3934/ipi.2007.1.265](https://doi.org/10.3934/ipi.2007.1.265)` . [8] ~~,~~ _A_ _nonparametric_ _approach_ _for_ _histogram_ _segmentation_, IEEE Transactions on Image Processing, 16 (2007), pp. 253–261. `[https://doi.org/10.1109/TIP.2006.884951](https://doi.org/10.1109/TIP.2006.884951)` . [9] A. Desolneux, L. Moisan, and J-M. Morel, _Meaningful alignments_, International Journal of Computer Vision, 40 (2000), pp. 7–23. `[https://doi.org/10.1023/A:1026593302236](https://doi.org/10.1023/A:1026593302236)` . [10] ~~,~~ _A_ _grouping_ _principle_ _and_ _four_ _applications_, IEEE Transactions on Pattern Analysis and Machine Intelligence, 25 (2003), pp. 508–513. `[https://doi.org/10.1109/TPAMI.2003.](https://doi.org/10.1109/TPAMI.2003.1190576)` `[1190576](https://doi.org/10.1109/TPAMI.2003.1190576)` . [11] A. Desolneux, L. Moisan, and J-M. Morel, _From_ _Gestalt_ _theory_ _to_ _image_ _analysis:_ _a_ _probabilistic_ _approach_, Interdisciplinary Applied Mathematics, Springer, 2008. ISBN 978-0-38774378-3. [12] U. Grenander, _Abstract_ _Inference_, Wiley, 1981. [13] J.L. Lisani, L. Rudin, P. Monasse, J-M. Morel, and P. Yu, _Meaningful_ _automatic_ _video_ _demultiplexing_ _with_ _unknown_ _number_ _of_ _cameras,_ _contrast_ _changes,_ _and_ _motion_, in IEEE Conference on Advanced Video and Signal Based Surveillance, 2005. [14] J.L. Lisani, T.Buades, and J-M. Morel, _Image_ _Color_ _Cube_ _Dimensional_ _Filtering_ _and_ _Visualization_, Image Processing On Line, 1 (2011), pp. 57–69. `[https://doi.org/10.5201/](https://doi.org/10.5201/ipol.2011.blm-cdf)` `[ipol.2011.blm-cdf](https://doi.org/10.5201/ipol.2011.blm-cdf)` . [15] G. Wyszecki and W.S. Stiles, _Color_ _Science:_ _Concepts_ _and_ _Methods,_ _Quantitative_ _Data_ _and_ _Formulae_, Wiley, 1984, ch. 3. ISBN 978-0-471-39918-6. 104

섹션 본문

섹션 본문이 없습니다.

참고문헌 11건

  1. From Gestalt Theory to Image Analysis: A Probabilistic Approach HAL (Le Centre pour la Communication Scientifique Directe) · Le Centre pour la Communication Scientifique Directe · 2008
  2. The Grenader Estimator: A Nonasymptotic Approach The Annals of Statistics · Institute of Mathematical Statistics · 1989 10.1214/aos/1176347380
  3. A Nonparametric Approach for Histogram Segmentation IEEE Transactions on Image Processing · Institute of Electrical and Electronics Engineers · 2006 10.1109/tip.2006.884951
  4. An Empirical Distribution Function for Sampling with Incomplete Information The Annals of Mathematical Statistics · Institute of Mathematical Statistics · 1955 10.1214/aoms/1177728423
  5. Image Color Cube Dimensional Filtering and Visualization Image Processing On Line · Image Processing On Line · 2011 10.5201/ipol.2011.blm-cdf
  6. Meaningful automatic video demultiplexing with unknown number of cameras, contrast changes, and motion 2006 10.1109/avss.2005.1577337
  7. Automatic color palette Inverse Problems and Imaging · American Institute of Mathematical Sciences · 2007 10.3934/ipi.2007.1.265
  8. Topography-driven satellite imagery analysis for landslide mapping Geomatics Natural Hazards and Risk · Taylor & Francis · 2018 10.1080/19475705.2018.1458050
  9. Elements of Information Theory Birkhäuser Basel eBooks · Birkhäuser Basel · 1992 10.1007/978-3-0348-8645-1_7
  10. (제목 없음) International Journal of Computer Vision · Springer Science+Business Media · 2000 10.1023/a:1026593302236
  11. A grouping principle and four applications IEEE Transactions on Pattern Analysis and Machine Intelligence · IEEE Computer Society · 2003 10.1109/tpami.2003.1190576