#include <stdio.h>
#include "pslib.h"

#define SIZE 100

int main(int argc, char **argv)
{
    psImage *image = psImageAlloc(SIZE, SIZE, PS_TYPE_F32);

    // Noise
    for (int j = 0; j < SIZE; j++) {
	for (int i = 0; i < SIZE; i++) {
	    image->data.F32[j][i] = (float)rand()/(float)RAND_MAX;
	}
    }

    // Imbed other stuff
    for (int j = SIZE/4; j < 3*SIZE/4; j++) {
	for (int i = SIZE/4; i < 3*SIZE/4; i++) {
	    image->data.F32[j][i] += 100.0;
	}
    }

    psImage *subImage = psImageSubset(image, SIZE/4, SIZE/4, 3*SIZE/4, 3*SIZE/4);
    psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV);
    (void)psImageStats(stats, subImage, NULL, 0);
    printf("Sub-image:\n\tMean: %f\n\tStandard Deviation: %f\n", stats->sampleMean, stats->sampleStdev);

    psImage *subImageCopy = psImageCopy(NULL, subImage, PS_TYPE_F32);
    (void)psImageStats(stats, subImageCopy, NULL, 0);
    printf("Copy of sub-image:\n\tMean: %f\n\tStandard Deviation: %f\n", stats->sampleMean, stats->sampleStdev);

    psFree(stats);
    psFree(image);
    psFree(subImageCopy);

}

