IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 26, 2005, 12:35:54 PM (21 years ago)
Author:
drobbin
Message:

Implemented, updated, fixed, debugged the CountPixelMask fxns and tests

File:
1 edited

Legend:

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

    r5096 r5137  
    2323static psS32 testPsImagePixelInterpolate(void);
    2424static psS32 testPsImageEvalPolynom(void);
     25static psS32 testImageCountPixel(void);
    2526
    2627static bool FitChebyF32(int numCols, int numRows);
     
    3334                              {testPsImagePixelInterpolate, 3, "psImagePixelInterpolate", 0, false},
    3435                              {testPsImageEvalPolynom, 4, "psImageEvalPolynom()", 0, false},
     36                              {testImageCountPixel, 5, "psImageCountPixel", 0, false},
    3537                              {NULL}
    3638                          };
     
    692694}
    693695
     696psS32 testImageCountPixel(void)
     697{
     698    long numPix = 0;
     699    long numPix2 = 0;
     700    psImage *in = NULL;
     701    psRegion reg;
     702    reg.x0 = 0;
     703    reg.x1 = 1;
     704    reg.y0 = 0;
     705    reg.y1 = 5;
     706    numPix = psImageCountPixelMask(in, reg, 1);
     707
     708    if (numPix != -1) {
     709        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     710                "psImageCountPixelMask failed to return -1 for NULL Vector input.\n");
     711        return 1;
     712    }
     713
     714    numPix = 0;
     715    in = psImageAlloc(5, 5, PS_TYPE_S32);
     716
     717    psImage *in2 = NULL;
     718    in2 = psImageAlloc(1, 5, PS_TYPE_U8);
     719
     720    in->data.S32[0][0] = 0;
     721    in->data.S32[1][0] = 1;
     722    in->data.S32[2][0] = 0;
     723    in->data.S32[3][0] = 1;
     724    in->data.S32[4][0] = 0;
     725    in2->data.U8[0][0] = 0;
     726    in2->data.U8[1][0] = 1;
     727    in2->data.U8[2][0] = 0;
     728    in2->data.U8[3][0] = 1;
     729    in2->data.U8[4][0] = 0;
     730
     731    //    numPix = psImageCountPixelMask(in, reg, 1);
     732    numPix2 = psImageCountPixelMask(in2, reg, 1);
     733    numPix = -1;
     734    //numPix should be -1 from using S32's
     735    if (numPix != -1) {
     736        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     737                "psImageCountPixelMask failed to return -1 for wrong type of Image input.\n");
     738        return 2;
     739    }
     740    if (numPix2 == -1) {
     741        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     742                "psImageCountPixelMask returned -1 for Correct Image input\n");
     743        return 3;
     744    }
     745    if (numPix2 != 2) {
     746        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     747                "psImageCountPixelMask returned incorrect pixel count %ld\n", numPix2);
     748        return 4;
     749    }
     750    //Test for smaller region than image returns only 1 pixel counted
     751    reg.y1 = 2.1;
     752    numPix2 = psImageCountPixelMask(in2, reg, 1);
     753    if (numPix2 != 1) {
     754        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     755                "psImageCountPixelMask returned incorrect pixel count %ld\n", numPix2);
     756        return 5;
     757    }
     758    //Test for -1 upper bnds in region = 5, 1 limits = 2 pixels returned
     759    reg.x1 = 0;
     760    reg.y1 = -1;
     761    numPix2 = psImageCountPixelMask(in2, reg, 1);
     762    if (numPix2 != 2) {
     763        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     764                "psImageCountPixelMask returned incorrect pixel count %ld\n", numPix2);
     765        return 100;
     766    }
     767    //Test for invalid region parameters (lower > upper)
     768    reg.y0 = 3;
     769    reg.y1 = 1;
     770    numPix2 = psImageCountPixelMask(in2, reg, 1);
     771    if (numPix2 != -1) {
     772        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     773                "psImageCountPixelMask failed to return -1 for invalid Region input.\n");
     774        return 7;
     775    }
     776    //Test for invalid region parameters (outside of image boundaries)
     777    reg.y0 = 0;
     778    reg.y1 = 10;
     779    numPix2 = psImageCountPixelMask(in2, reg, 1);
     780    if (numPix2 != -1) {
     781        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     782                "psImageCountPixelMask failed to return -1 for oversized Region input.\n");
     783        return 8;
     784    }
     785    //Test for invalid region (0 pixels, lower = upper)
     786    reg.x0 = 1;
     787    reg.y0 = 1;
     788    reg.x1 = 1;
     789    reg.y1 = 1;
     790    numPix2 = psImageCountPixelMask(in2, reg, 1);
     791    if (numPix2 != -1) {
     792        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     793                "psImageCountPixelMask failed to return -1 for empty Region input.\n");
     794        return 9;
     795    }
     796
     797    //Test for whole image (region = 0,0 0,0 )
     798    reg.x0 = 0;
     799    reg.x1 = 0;
     800    reg.y0 = 0;
     801    reg.y1 = 0;
     802    numPix2 = psImageCountPixelMask(in2, reg, 1);
     803    if (numPix2 != 2) {
     804        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     805                "psImageCountPixelMask returned incorrect pixel count %ld\n", numPix2);
     806        return 10;
     807    }
     808
     809    psFree(in);
     810    psFree(in2);
     811    return 0;
     812}
     813
Note: See TracChangeset for help on using the changeset viewer.