IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17330


Ignore:
Timestamp:
Apr 4, 2008, 4:46:25 PM (18 years ago)
Author:
Paul Price
Message:

Adding test for psImageConvolveMaskFFT.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/imageops/tap_psImageConvolve2.c

    r17320 r17330  
    88#define KERNEL_SIZE 3
    99#define TOL 1.0e-6
     10#define MASK_INITIAL 0x0f
     11#define MASK_FINAL   0xf0
    1012
    1113
     
    1719    image->data.F32[IMAGE_SIZE/2][IMAGE_SIZE/2] = 1.0;
    1820    return image;
     21}
     22
     23// Generate mask with single pixel set
     24static psImage *generateMask(void)
     25{
     26    psImage *mask = psImageAlloc(IMAGE_SIZE, IMAGE_SIZE, PS_TYPE_MASK);
     27    psImageInit(mask, 0);
     28    mask->data.PS_TYPE_MASK_DATA[IMAGE_SIZE/2][IMAGE_SIZE/2] = MASK_INITIAL;
     29    return mask;
    1930}
    2031
     
    5869}
    5970
     71// Check the convolved mask matches the kernel
     72static bool checkConvolvedMask(const psImage *mask)
     73{
     74    bool correct = true;
     75    for (int y = 0; y < IMAGE_SIZE; y++) {
     76        for (int x = 0; x < IMAGE_SIZE; x++) {
     77            if (x < IMAGE_SIZE/2 - KERNEL_SIZE || x > IMAGE_SIZE/2 + KERNEL_SIZE ||
     78                y < IMAGE_SIZE/2 - KERNEL_SIZE || y > IMAGE_SIZE/2 + KERNEL_SIZE) {
     79                if (mask->data.PS_TYPE_MASK_DATA[y][x] != 0) {
     80                    diag("%d,%d --> %d", x, y, mask->data.PS_TYPE_MASK_DATA[y][x]);
     81                    correct = false;
     82                }
     83            } else if (x == IMAGE_SIZE/2 && y == IMAGE_SIZE/2) {
     84                if (mask->data.PS_TYPE_MASK_DATA[y][x] != (MASK_INITIAL | MASK_FINAL)) {
     85                    diag("%d,%d --> %d", x, y, mask->data.PS_TYPE_MASK_DATA[y][x]);
     86                    correct = false;
     87                }
     88            } else if (mask->data.PS_TYPE_MASK_DATA[y][x] != MASK_FINAL) {
     89                diag("%d,%d --> %d", x, y, mask->data.PS_TYPE_MASK_DATA[y][x]);
     90                correct = false;
     91            }
     92        }
     93    }
     94    return correct;
     95}
     96
    6097
    6198int main(int argc, char *argv[])
    6299{
    63     plan_tests(10);
     100    plan_tests(15);
    64101
    65102    diag("psImageConvolve tests");
     
    111148    }
    112149
     150    {
     151        // FFT mask convolution: 5 tests
     152        psMemId id = psMemGetId();
     153
     154        psImage *mask = generateMask();
     155
     156        psImage *convolved = psImageConvolveMaskFFT(NULL, mask, MASK_INITIAL, MASK_FINAL,
     157                                                    -KERNEL_SIZE, KERNEL_SIZE, -KERNEL_SIZE, KERNEL_SIZE,
     158                                                    0.5);
     159        ok(convolved, "convolution result");
     160        skip_start(!convolved, 3, "convolution failed");
     161        ok(convolved->type.type == PS_TYPE_MASK, "output type");
     162        ok(convolved->numCols == IMAGE_SIZE && convolved->numRows == IMAGE_SIZE, "output size %dx%d",
     163           convolved->numCols, convolved->numRows);
     164        ok(checkConvolvedMask(convolved), "convolved mask correct");
     165        psFree(convolved);
     166        skip_end();
     167
     168        psFree(mask);
     169
     170        ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks");
     171    }
     172
    113173
    114174    return exit_status();
Note: See TracChangeset for help on using the changeset viewer.