| 1 | #include <stdio.h>
|
|---|
| 2 | #include "pslib.h"
|
|---|
| 3 |
|
|---|
| 4 | #define SIZE 100
|
|---|
| 5 |
|
|---|
| 6 | int main(int argc, char **argv)
|
|---|
| 7 | {
|
|---|
| 8 | psImage *image = psImageAlloc(SIZE, SIZE, PS_TYPE_F32);
|
|---|
| 9 |
|
|---|
| 10 | // Noise
|
|---|
| 11 | for (int j = 0; j < SIZE; j++) {
|
|---|
| 12 | for (int i = 0; i < SIZE; i++) {
|
|---|
| 13 | image->data.F32[j][i] = (float)rand()/(float)RAND_MAX;
|
|---|
| 14 | }
|
|---|
| 15 | }
|
|---|
| 16 |
|
|---|
| 17 | // Imbed other stuff
|
|---|
| 18 | for (int j = SIZE/4; j < 3*SIZE/4; j++) {
|
|---|
| 19 | for (int i = SIZE/4; i < 3*SIZE/4; i++) {
|
|---|
| 20 | image->data.F32[j][i] += 100.0;
|
|---|
| 21 | }
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | psImage *subImage = psImageSubset(image, SIZE/4, SIZE/4, 3*SIZE/4, 3*SIZE/4);
|
|---|
| 25 | psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV);
|
|---|
| 26 | (void)psImageStats(stats, subImage, NULL, 0);
|
|---|
| 27 | printf("Sub-image:\n\tMean: %f\n\tStandard Deviation: %f\n", stats->sampleMean, stats->sampleStdev);
|
|---|
| 28 |
|
|---|
| 29 | psImage *subImageCopy = psImageCopy(NULL, subImage, PS_TYPE_F32);
|
|---|
| 30 | (void)psImageStats(stats, subImageCopy, NULL, 0);
|
|---|
| 31 | printf("Copy of sub-image:\n\tMean: %f\n\tStandard Deviation: %f\n", stats->sampleMean, stats->sampleStdev);
|
|---|
| 32 |
|
|---|
| 33 | psFree(stats);
|
|---|
| 34 | psFree(image);
|
|---|
| 35 | psFree(subImageCopy);
|
|---|
| 36 |
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|