/*********************************************************************
 * This file is part of the PRAPI library.
 *
 * Copyright (C) 2001-2003 Topi Mäenpää
 * Copyright (C) 2001 Jaakko Viertola
 * All rights reserved.
 *
 * This program is free software. You can redistribute and/or modify
 * it under the terms of the free software licence found in the
 * accompanying file "COPYING". The licence terms must always be
 * redistributed with this source file. The above copyright notice
 * must be reproduced in all modified and unmodified copies of this
 * source file.
 *
 * $Revision: 1.3 $
 *********************************************************************/

#ifndef _VARIANCE_H
#define _VARIANCE_H

#include "../FeatureExtractor.h"
#include "../ImageTransform.h"
#include "CircularLocalSampler.h"
#include <Math.h>

namespace prapi { namespace texture {
	
	/**
	 * A class for calculating local variance. The variance for a pixel
	 * is defined to be the variance of the surrounding pixels, i.e.
	 * C=1/N*sum<sub>i=1..N</sub>((p<sub>i</sub>-m)<sup>2</sup>), where
	 * N is the number of circular neighbors for a pixel, p<sub>i</sub>
	 * is the <i>i</i>th circular neighbor, and m is the mean value of
	 * the neighborhood, i.e. m=1/N*sum<sub>i=1..N</sub>(p<sub>i</sub>).
	 **/
	class Variance : public CircularLocalSampler<double, double>
	{
	public:
		Variance(unsigned int samples=8, int predicate=1, bool interpolate=true) :
			CircularLocalSampler<double,double>(samples,predicate,interpolate) {}

		double getValue(double center, List<double>& surrounding)
		{ return util::Math::variance(surrounding,Math::VAR_BIASED); }
	};
}}

#endif
