/*
 * File         : thresholdCal.h
 * Author       : Timothy Wiley
 * Version      :
 * Created      : 31/03/2010
 * Description  : Calculate the threshold for thermal images
 * Copyright    :
 */

#ifndef THERMAL_BLOBBER_THRESHOLDCAL_H_
#define THERMAL_BLOBBER_THRESHOLDCAL_H_

#include <crosbot/data.hpp>
#include <crosbot/handle.hpp>
#include <crosbot/geometry.hpp>

#define ELEMENT_THRESHOLDCAL "ThresholdCal"

// Threshold constants
#define MAX_GREY_LEVEL 255
#define NO_GREY_LEVELS (MAX_GREY_LEVEL + 1)

using namespace crosbot;

namespace casualty {

class ThresholdCal : public HandledObject {
public:
    ThresholdCal();
    ~ThresholdCal();

    // Returns the current threshold
    unsigned char threshold(ImagePtr image);

private:
    // internal for efficiency
    double pi[NO_GREY_LEVELS];

    // Generates a normalised probability distribution histogram of the given image
    void generateHistogram(ImagePtr processImage, double pi[]);

    // Calculates the threshold using the Ostu method
    unsigned char ostuThreshold(double pi[]);
};
typedef Handle<ThresholdCal> ThresholdCalPtr;

} // namespace casualty

#endif /* THERMAL_BLOBBER_THRESHOLDCAL_H_ */
