/ *   
 
   *   P R O J E C T :   N y A R T o o l k i t C S ( E x t e n s i o n ) 
 
   *   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
   *   T h e   N y A R T o o l k i t C S   i s   J a v a   e d i t i o n   A R T o o l K i t   c l a s s   l i b r a r y . 
 
   *   C o p y r i g h t   ( C ) 2 0 0 8 - 2 0 0 9   R y o   I i z u k a 
 
   * 
 
   *   T h i s   p r o g r a m   i s   f r e e   s o f t w a r e :   y o u   c a n   r e d i s t r i b u t e   i t   a n d / o r   m o d i f y 
 
   *   i t   u n d e r   t h e   t e r m s   o f   t h e   G N U   G e n e r a l   P u b l i c   L i c e n s e   a s   p u b l i s h e d   b y 
 
   *   t h e   F r e e   S o f t w a r e   F o u n d a t i o n ,   e i t h e r   v e r s i o n   3   o f   t h e   L i c e n s e ,   o r 
 
   *   ( a t   y o u r   o p t i o n )   a n y   l a t e r   v e r s i o n . 
 
   *   
 
   *   T h i s   p r o g r a m   i s   d i s t r i b u t e d   i n   t h e   h o p e   t h a t   i t   w i l l   b e   u s e f u l , 
 
   *   b u t   W I T H O U T   A N Y   W A R R A N T Y ;   w i t h o u t   e v e n   t h e   i m p l i e d   w a r r a n t y   o f 
 
   *   M E R C H A N T A B I L I T Y   o r   F I T N E S S   F O R   A   P A R T I C U L A R   P U R P O S E .     S e e   t h e 
 
   *   G N U   G e n e r a l   P u b l i c   L i c e n s e   f o r   m o r e   d e t a i l s . 
 
   * 
 
   *   Y o u   s h o u l d   h a v e   r e c e i v e d   a   c o p y   o f   t h e   G N U   G e n e r a l   P u b l i c   L i c e n s e 
 
   *   a l o n g   w i t h   t h i s   p r o g r a m .     I f   n o t ,   s e e   < h t t p : / / w w w . g n u . o r g / l i c e n s e s / > . 
 
   *   
 
   *   F o r   f u r t h e r   i n f o r m a t i o n   p l e a s e   c o n t a c t . 
 
   * 	 h t t p : / / n y a t l a . j p / n y a t o o l k i t / 
 
   * 	 < a i r m a i l ( a t ) e b o n y . p l a l a . o r . j p >   o r   < n y a t l a ( a t ) n y a t l a . j p > 
 
   *   
 
   * / 
 
 u s i n g   S y s t e m ; 
 
 n a m e s p a c e   j p . n y a t l a . n y a r t o o l k i t . c s . c o r e 
 
 { 
 
 
 
 
 
 
 
 
 
         / * * 
 
           *   S0n0000o00k i t t l e r T h r e s h o l d 0(uD0f0weE\$P0Bl00_j0cOW0~0Y00
 
           * / 
 
         p u b l i c   c l a s s   N y A R H i s t o g r a m A n a l y z e r _ K i t t l e r T h r e s h o l d   :   I N y A R H i s t o g r a m A n a l y z e r _ T h r e s h o l d 
 
         { 
 
                 / * * 
 
                   *   S0n0peo00k i t t l e r T h r e s h o l d 0(uD0f0weE\$P01 PBl0~0Y00weE\$Pn0{Vo00i _ h i s t o g r a m _pen0{Vh0TX0g0Y00
 
                   * / 
 
                 p u b l i c   i n t   g e t T h r e s h o l d ( N y A R H i s t o g r a m   i _ h i s t o g r a m ) 
 
                 { 
 
                         i n t   i ; 
 
                         d o u b l e   m i n   =   D o u b l e . M a x V a l u e ; 
 
                         i n t   t h   =   0 ; 
 
                         i n t   d a ,   s a ,   d b ,   s b ,   p a ,   p b ; 
 
                         d o u b l e   o a ,   o b ; 
 
 
 
                         i n t [ ]   h i s t   =   i _ h i s t o g r a m . d a t a ; 
 
                         i n t   n   =   i _ h i s t o g r a m . l e n g t h ; 
 
                         / / L o w tP
 
                         d a   =   p a   =   0 ; 
 
                         i n t   h ; 
 
                         f o r   ( i   =   0 ;   i   <   n ;   i + + ) 
 
                         { 
 
                                 h   =   h i s t [ i ] ; 
 
                                 d a   + =   h   *   i ; 	 / / i * h [ i ] 
 
                                 p a   + =   h   *   i   *   i ; 	 / / i * i * h [ i ] 
 
                         } 
 
                         s a   =   i _ h i s t o g r a m . t o t a l _ o f _ d a t a ; 
 
                         / / H i g h tP( i = n - 1 ) 
 
                         d b   =   0 ; 
 
                         s b   =   0 ; 
 
                         p b   =   0 ; 
 
 
 
 
 
                         f o r   ( i   =   n   -   1 ;   i   >   0 ;   i - - ) 
 
                         { 
 
                                 / / !kn00000000{
 
                                 i n t   h i s t _ c o u n t   =   h i s t [ i ] ; / / h [ i ] 
 
                                 i n t   h i s t _ v a l   =   h i s t _ c o u n t   *   i ;     / / h [ i ] * i 
 
                                 i n t   h i s t _ v a l 2   =   h i s t _ v a l   *   i ;         / / h [ i ] * i * i 
 
                                 d a   - =   h i s t _ v a l ; 
 
                                 s a   - =   h i s t _ c o u n t ; 
 
                                 p a   - =   h i s t _ v a l 2 ; 
 
                                 d b   + =   h i s t _ v a l ; 
 
                                 s b   + =   h i s t _ c o u n t ; 
 
                                 p b   + =   h i s t _ v a l 2 ; 
 
 
 
                                 / / RgS
 
                                 d o u b l e   w a   =   ( d o u b l e ) s a   /   ( s a   +   s b ) ; 
 
                                 d o u b l e   w b   =   ( d o u b l e ) s b   /   ( s a   +   s b ) ; 
 
                                 i f   ( w a   = =   0   | |   w b   = =   0 ) 
 
                                 { 
 
                                         c o n t i n u e ; 
 
                                 } 
 
 
 
                                 o a   =   o b   =   0 ; 
 
                                 d o u b l e   m a   =   s a   ! =   0   ?   ( d o u b l e ) d a   /   s a   :   0 ; 
 
                                 / / ( i - m a ) ^ 2 * h [ i ] = ( i ^ 2 * h [ i ] ) + ( m a ^ 2 * h [ i ] ) - ( 2 * i * m a * h [ i ] ) 
 
                                 o a   =   ( ( d o u b l e ) ( p a   +   m a   *   m a   *   s a   -   2   *   m a   *   d a ) )   /   s a ; 
 
 
 
                                 d o u b l e   m b   =   s b   ! =   0   ?   ( d o u b l e ) d b   /   s b   :   0 ; 
 
                                 / / ( i - m b ) ^ 2 * h [ i ] = ( i ^ 2 * h [ i ] ) + ( m b ^ 2 * h [ i ] ) - ( 2 * i * m b * h [ i ] ) 
 
                                 o b   =   ( ( d o u b l e ) ( p b   +   m b   *   m b   *   s b   -   2   *   m b   *   d b ) )   /   s b ; 
 
 
 
                                 d o u b l e   k a i   =   w a   *   M a t h . L o g ( o a   /   w a )   +   w b   *   M a t h . L o g ( o b   /   w b ) ; 
 
                                 i f   ( k a i   >   0   & &   m i n   >   k a i ) 
 
                                 { 
 
                                         m i n   =   k a i ; 
 
                                         t h   =   i ; 
 
                                 } 
 
                                 / / S y s t e m . o u t . p r i n t l n ( k a i ) ; 
 
 
 
                         } 
 
                         r e t u r n   t h ; / / 1 2 9 / / 7 . 5 0 6 7 1 3 8 7 2 7 3 8 8 7 3 
 
                 } 
 
                 / * * 
 
                   *   0000(upe
 
                   *   @ p a r a m   a r g s 
 
                   *   m a i n pe_pe
 
                   * / 
 
                 p u b l i c   s t a t i c   v o i d   m a i n ( s t r i n g [ ]   a r g s ) 
 
                 { 
 
                         N y A R H i s t o g r a m   d a t a   =   n e w   N y A R H i s t o g r a m ( 2 5 6 ) ; 
 
                         f o r   ( i n t   i   =   0 ;   i   <   2 5 6 ;   i + + ) 
 
                         { 
 
                                 d a t a . d a t a [ i ]   =   1 2 8   -   i   >   0   ?   1 2 8   -   i   :   i   -   1 2 8 ; 
 
                         } 
 
                         d a t a . t o t a l _ o f _ d a t a   =   d a t a . g e t T o t a l ( 0 ,   2 5 5 ) ; 
 
                         N y A R H i s t o g r a m A n a l y z e r _ K i t t l e r T h r e s h o l d   a n   =   n e w   N y A R H i s t o g r a m A n a l y z e r _ K i t t l e r T h r e s h o l d ( ) ; 
 
                         i n t   t h   =   a n . g e t T h r e s h o l d ( d a t a ) ; 
 
                         / / S y s t e m . o u t . p r i n t ( t h ) ; 
 
                         r e t u r n ; 
 
                 } 
 
         } 
 
 } 
 
 