IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 14, 2005, 2:12:09 PM (21 years ago)
Author:
desonia
Message:

fixed image FFT and image convolution. The FFTW call had the wrong order
of dimensions, and the scaling was incorrect.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/image/tst_psImageConvolve.c

    r3682 r3702  
    55 *  @author Robert DeSonia, MHPCC
    66 *
    7  *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2005-04-07 20:27:42 $
     7 *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2005-04-15 00:12:09 $
    99 *
    1010 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2222static psS32 testKernelAlloc(void);
    2323static psS32 testKernelGenerate(void);
    24 //static psS32 testImageConvolve(void);
     24static psS32 testImageConvolve(void);
    2525
    2626testDescription tests[] = {
    2727                              {testKernelAlloc,731,"psKernelAlloc",0,false},
    2828                              {testKernelGenerate,732,"psKernelGenerate",0,false},
    29                               //                              {testImageConvolve,733,"psImageConvolve",0,false},
     29                              {testImageConvolve,733,"psImageConvolve",0,false},
    3030                              {NULL}
    3131                          };
     
    286286}
    287287
    288 /*
    289288static psS32 testImageConvolve(void)
    290289{
     
    292291    const psS32 c = 300;
    293292    psS32 sum;
    294  
     293
    295294    // approximate a normalized gaussian kernel.
    296295    psKernel* g = psKernelAlloc(-1,1,-1,1);
     
    304303                g->kernel[0][1] = 0.0838;
    305304    g->kernel[0][0] = 0.6193;
    306  
     305
    307306    // create a normalized non-symetric kernel.
    308307    psKernel* nsk = psKernelAlloc(0,2,0,2);
     
    319318        }
    320319    }
    321  
    322  
     320
     321
    323322    psImage* img = psImageAlloc(c,r,PS_TYPE_F32);
    324323    memset(img->data.F32[0],0,c*r*PSELEMTYPE_SIZEOF(PS_TYPE_F32));
     
    326325    img->data.F32[r/2][c/2] = 1.0f;
    327326    img->data.F32[r-1][c/2] = 1.0f;
    328  
     327
    329328    // test spacial convolution of gaussian
    330329    psLogMsg(__func__,PS_LOG_INFO,"Testing direct gaussian convolution");
    331330    psImage* out = psImageConvolve(NULL, img, g, true);
    332  
     331
    333332    if (out == NULL) {
    334333        psError(PS_ERR_UNKNOWN, true, "psImageConvolve returned a NULL for direct gaussian case.");
    335334        return 1;
    336335    }
    337  
     336
    338337    if (out->numCols != c || out->numRows != r) {
    339338        psError(PS_ERR_UNKNOWN, true, "psImageConvolve result image is %dx%d, but expected %dx%d.",
     
    342341        return 2;
    343342    }
    344  
     343
    345344    if (out->type.type != PS_TYPE_F32) {
    346345        char* typeStr;
     
    350349        return 3;
    351350    }
    352  
     351
    353352    // test values
    354353    for (psS32 i=-1;i<1;i++) {
     
    374373        }
    375374    }
    376  
     375
    377376    // test fourier convolution of gaussian
    378377    psLogMsg(__func__,PS_LOG_INFO,"Testing fourier gaussian convolution");
    379     psKernel* gg = psKernelAlloc(1,3,1,3);
    380     gg->kernel[1][1] =
    381         gg->kernel[1][3] =
    382             gg->kernel[3][1] =
    383                 gg->kernel[3][3] = 0.0113;
    384     gg->kernel[3][2] =
    385         gg->kernel[1][2] =
    386             gg->kernel[2][1] =
    387                 gg->kernel[2][3] = 0.0838;
    388     gg->kernel[2][2] = 0.6193;
    389     img->data.F32[0][0] = 0.0f;
    390     img->data.F32[r/2][c/2] = 1.0f;
    391     img->data.F32[r-1][c/2] = 0.0f;
    392     psImage* out2 = psImageConvolve(out, img, gg, false);
    393  
     378    psImage* out2 = psImageConvolve(out, img, g, false);
     379
    394380    if (out == NULL) {
    395381        psError(PS_ERR_UNKNOWN, true, "psImageConvolve returned a NULL for gaussian case.");
    396382        return 10;
    397383    }
    398  
     384
    399385    if (out != out2) {
    400386        psError(PS_ERR_UNKNOWN, true, "psImageConvolve didn't recycle the supplied out image struct.");
    401387        return 11;
    402388    }
    403  
     389
    404390    if (out->numCols != c || out->numRows != r) {
    405391        psError(PS_ERR_UNKNOWN, true, "psImageConvolve result image is %dx%d, but expected %dx%d.",
     
    408394        return 12;
    409395    }
    410  
     396
    411397    if (out->type.type != PS_TYPE_F32) {
    412398        char* typeStr;
     
    416402        return 13;
    417403    }
    418  
    419     psImageWriteSection(out2,0,0,0,NULL,0,"out2.fits");
     404
    420405    // test values
    421406    for (psS32 i=-1;i<1;i++) {
    422407        for (psS32 j=-1;j<1;j++) {
    423             if (fabsf(out->data.F32[r/2+i][c/2+j] - g->kernel[i][j]) > 0.0001) {
     408            if (fabsf(out->data.F32[r/2+i][c/2+j] - g->kernel[i][j]) > 0.01) {
    424409                psError(PS_ERR_UNKNOWN, true,"Convolved image wrong at %d,%d.  Value is %g, expected %g.",
    425410                        c/2+j,r/2+i,
    426411                        out->data.F32[r/2+i][c/2+j], g->kernel[i][j]);
    427                 psImageWriteSection(out,0,0,0,NULL,0,"problem.fits");
    428412                return 14;
    429413            }
    430             if (i >= 0 && j >= 0 && fabsf(out->data.F32[i][j] - g->kernel[i][j]) > 0.0001) {
     414            if (i >= 0 && j >= 0 && fabsf(out->data.F32[i][j] - g->kernel[i][j]) > 0.01) {
    431415                psError(PS_ERR_UNKNOWN, true,"Convolved image wrong at %d,%d.  Value is %g, expected %g.",
    432416                        j,i,
     
    434418                return 15;
    435419            }
    436             if (i <= 0 && fabsf(out->data.F32[r-1+i][c/2+j] - g->kernel[i][j]) > 0.0001) {
     420            if (i <= 0 && fabsf(out->data.F32[r-1+i][c/2+j] - g->kernel[i][j]) > 0.01) {
    437421                psError(PS_ERR_UNKNOWN, true,"Convolved image wrong at %d,%d.  Value is %g, expected %g.",
    438422                        c/2+j,r-1+i,
     
    442426        }
    443427    }
    444  
     428
    445429    psFree(g);
    446430    psFree(img);
     
    449433    return 0;
    450434}
    451 */
    452 
     435
Note: See TracChangeset for help on using the changeset viewer.