IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 2074


Ignore:
Timestamp:
Oct 12, 2004, 4:40:13 PM (22 years ago)
Author:
desonia
Message:

added test for psImageTrim.

Location:
trunk/psLib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/dataManip/psStats.c

    r2058 r2074  
    99 *  @author GLG, MHPCC
    1010 *
    11  *  @version $Revision: 1.66 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-10-12 20:53:02 $
     11 *  @version $Revision: 1.67 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-10-13 02:40:13 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    388388        }
    389389    } else {
    390         rangeMin = stats->min;
    391         rangeMax = stats->max;
    392390        if (maskVector != NULL) {
    393391            for (i = 0; i < myVector->n; i++) {
  • trunk/psLib/src/image/psImageExtraction.c

    r2067 r2074  
    99 *  @author Robert DeSonia, MHPCC
    1010 *
    11  *  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-10-13 00:10:50 $
     11 *  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-10-13 02:40:13 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    195195    }
    196196
     197    if (col1 < 1) {
     198        col1 += image->numCols;
     199    }
     200
     201    if (row1 < 1) {
     202        row1 += image->numRows;
     203    }
     204
    197205    if (    col0 < 0 ||
    198206            row0 < 0 ||
    199             col1 >= image->numCols ||
    200             row1 >= image->numRows ||
    201             col0 > col1 ||
    202             row0 > row1 ) {
     207            col1 > image->numCols ||
     208            row1 > image->numRows ||
     209            col0 >= col1 ||
     210            row0 >= row1 ) {
    203211        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageTrim",
    204212                   PS_ERR_BAD_PARAMETER_VALUE, true,
    205213                   PS_ERRORTEXT_psImage_SUBSET_RANGE_INVALID,
    206                    col0, col1, row0, row1,
    207                    image->numCols, image->numRows);
     214                   col0, col1-1, row0, row1-1,
     215                   image->numCols-1, image->numRows-1);
     216        psFree(image);
    208217        return NULL;
    209218    }
     
    212221
    213222    unsigned int elementSize = PSELEMTYPE_SIZEOF(image->type.type);
    214     unsigned int numCols = col1-col0+1;
    215     unsigned int numRows = row1-row0+1;
     223    unsigned int numCols = col1-col0;
     224    unsigned int numRows = row1-row0;
    216225    unsigned int rowSize = elementSize*numCols;
    217226    unsigned int colOffset = elementSize * col0;
    218     void* imageData = image->rawDataBuffer;
     227    psU8* imageData = image->rawDataBuffer;
    219228    for (int row = row0; row < row1; row++) {
    220229        memmove(imageData,image->data.U8[row] + colOffset,rowSize);
    221         imageData = (psU8*)imageData + rowSize;
     230        imageData += rowSize;
    222231    }
    223232
     
    265274    }
    266275
    267     if (col1 < 0) {
     276    if (col1 < 1) {
    268277        col1 += in->numCols;
    269278    }
    270279
    271     if (row1 < 0) {
     280    if (row1 < 1) {
    272281        row1 += in->numRows;
    273282    }
     
    275284    if (    col0 < 0 ||
    276285            row0 < 0 ||
    277             col1 >= in->numCols ||
    278             row1 >= in->numRows ||
     286            col1 > in->numCols ||
     287            row1 > in->numRows ||
    279288            col0 >= col1 ||
    280289            row0 >= row1) {
  • trunk/psLib/src/math/psStats.c

    r2058 r2074  
    99 *  @author GLG, MHPCC
    1010 *
    11  *  @version $Revision: 1.66 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-10-12 20:53:02 $
     11 *  @version $Revision: 1.67 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-10-13 02:40:13 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    388388        }
    389389    } else {
    390         rangeMin = stats->min;
    391         rangeMax = stats->max;
    392390        if (maskVector != NULL) {
    393391            for (i = 0; i < myVector->n; i++) {
  • trunk/psLib/test/image/tst_psImageExtraction.c

    r2067 r2074  
    66*  @author Robert DeSonia, MHPCC
    77*
    8 *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
    9 *  @date $Date: 2004-10-13 00:10:50 $
     8*  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
     9*  @date $Date: 2004-10-13 02:40:13 $
    1010*
    1111*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    4242    const int r = 1000;
    4343    const int c = 2000;
    44     const int m = r / 2;
    45     const int n = r / 4;
     44    const int m = r / 2 -1;
     45    const int n = r / 4 -1;
    4646    psVector* out = NULL;
    4747    psImage* image = psImageAlloc( c, r, PS_TYPE_F32 );
     
    7777            imageRow[ col ] = ( psF32 ) col + rowOffset;
    7878            imgU8Row[ col ] = (psU8) col;
    79             if ( row == r/10 ) {
    80                 maskRow[ col ] = 1;
    81             } else {
    82                 maskRow[ col ] = 0;
    83             }
    84             //            maskRow[ col ] = 0;
     79            maskRow[ col ] = 0;
    8580            maskS8Row[ col ] = 0;
    8681            maskSzRow[ col ] = 0;
    8782        }
    8883    }
    89 
    90     // test MxN case
    9184
    9285    #define PSIMAGESLICE_TEST1(M,N,DIRECTION,TRUTH_SIZE,TRUTHPIX_X,TRUTHPIX_Y,TESTNUM) \
     
    10699    \
    107100    for (int i=0;i<out->n;i++) { \
    108         if (abs(out->data.F64[i]-image->data.F32[r/10+TRUTHPIX_Y][c/10+TRUTHPIX_X]) > 1.0/(psF32)r) { \
    109             psError(__func__,"Improper result at position %d.",i); \
     101        if (fabs(out->data.F64[i]-image->data.F32[r/10+TRUTHPIX_Y][c/10+TRUTHPIX_X]) > 1.0/(psF32)r) { \
     102            psError(__func__,"Improper result at position %d.  Got %g, expected %g",i, \
     103                    out->data.F64[i],image->data.F32[r/10+TRUTHPIX_Y][c/10+TRUTHPIX_X]); \
    110104            return TESTNUM*4+3; \
    111105        } \
     
    751745    int r = 200;
    752746    int c = 300;
    753     int quarterR = r/4;
    754     int quarterC = c/4;
     747    int qtrR = r/4;
     748    int qtrC = c/4;
    755749    int halfR = r/2;
     750    int halfC = c/2;
     751
    756752    psImage* image = psImageAlloc(c,r,PS_TYPE_F32);
    757753    for (int row = 0; row < image->numRows; row++) {
    758754        for (int col = 0; col < image->numCols; col++) {
    759             image->data.F32[row][col] = ((psF32)row+1.0f)/((psF32)col+1.0f);
    760         }
    761     }
    762 
     755            image->data.F32[row][col] = (psF32)col + (psF32)row/1000.0f;
     756        }
     757    }
     758
     759    /*
     760        1. invoke psImageTrim with non-NULL image, and a valid region
     761           x0,y0->x1,y1 (using only positive values). Verify that:
     762            a. the return psImage is the same as the input psImage.
     763            b. the size of the psImage is x1-x0 by y1-y0.
     764            c. the pixel values coorespond to the region [x0:x1-1,y0:y1-1].
     765    */
    763766    psImage* image1 = psImageCopy(NULL,image,PS_TYPE_F32);
    764     psImage* image2 = psImageTrim(image1,c/4,r/4,c*3/4,r*3/4);
    765 
    766 
    767 
     767    psImage* image2 = psImageTrim(image1,qtrC,qtrR,qtrC+halfC,qtrR+halfR);
     768
     769    if (image1 != image2) {
     770        psLogMsg(__func__,PS_LOG_ERROR,
     771                 "Return value not same as input value.  Not done in-place?");
     772        return 1;
     773    }
     774
     775    if (image2->numCols != halfC ||
     776            image2->numRows != halfR) {
     777        psLogMsg(__func__,PS_LOG_ERROR,
     778                 "The resulting image size was %dx%d, but should be %dx%d.",
     779                 image2->numCols, image2->numRows,
     780                 halfC, halfR);
     781        return 2;
     782    }
     783
     784    for (int row = 0; row < image2->numRows; row++) {
     785        for (int col = 0; col < image2->numCols; col++) {
     786            if (fabsf(image2->data.F32[row][col] - image->data.F32[row+qtrR][col+qtrC]) > FLT_EPSILON) {
     787                psLogMsg(__func__,PS_LOG_ERROR,
     788                         "The value at (%d,%d) was %g, but should be %g.",
     789                         col,row,
     790                         image2->data.F32[row][col],
     791                         image->data.F32[row+qtrR][col+qtrC]);
     792                return 3;
     793            }
     794        }
     795    }
     796
     797    /*
     798        2. invoke psImageTrim with non-NULL image and valid region where x1=0,
     799           y1=0. Verify that:
     800            a. the return psImage size is numCols-x0 by numRows-y0
     801            b. the pixel values coorespond to the region
     802               [x0:numCols-1,y0:numRows-1].
     803    */
     804    image1 = psImageCopy(image1,image,PS_TYPE_F32);
     805    image2 = psImageTrim(image1,qtrC,qtrR,0,0);
     806
     807    if (image1 != image2) {
     808        psLogMsg(__func__,PS_LOG_ERROR,
     809                 "Return value not same as input value.  Not done in-place?");
     810        return 11;
     811    }
     812
     813    if (image2->numCols != image->numCols-qtrC ||
     814            image2->numRows != image->numRows-qtrR) {
     815        psLogMsg(__func__,PS_LOG_ERROR,
     816                 "The resulting image size was %dx%d, but should be %dx%d.",
     817                 image2->numCols, image2->numRows,
     818                 image->numCols-qtrC, image->numRows-qtrR);
     819        return 12;
     820    }
     821
     822    for (int row = 0; row < image2->numRows; row++) {
     823        for (int col = 0; col < image2->numCols; col++) {
     824            if (fabsf(image2->data.F32[row][col] -
     825                      image->data.F32[row+qtrR][col+qtrC]) > FLT_EPSILON) {
     826                psLogMsg(__func__,PS_LOG_ERROR,
     827                         "The value at (%d,%d) was %g, but should be %g.",
     828                         col,row,
     829                         image2->data.F32[row][col],
     830                         image->data.F32[row+qtrR][col+qtrC]);
     831                return 13;
     832            }
     833        }
     834    }
     835
     836    /*
     837        4. invoke psImageTrim with x1<0, y1<0. Verify:
     838            a. the psImage size is (numCols+x1)-x0 by (numRows+y1)-y0.
     839            b. the pixel values coorespond to the region
     840               [x0:numCols+x1-1,y0:numRows+y1-1].
     841
     842    */
     843    image1 = psImageCopy(image1,image,PS_TYPE_F32);
     844    image2 = psImageTrim(image1,qtrC,qtrR,-qtrC,-qtrR);
     845
     846    if (image1 != image2) {
     847        psLogMsg(__func__,PS_LOG_ERROR,
     848                 "Return value not same as input value.  Not done in-place?");
     849        return 21;
     850    }
     851
     852    if (image2->numCols != image->numCols-qtrC-qtrC ||
     853            image2->numRows != image->numRows-qtrR-qtrR) {
     854        psLogMsg(__func__,PS_LOG_ERROR,
     855                 "The resulting image size was %dx%d, but should be %dx%d.",
     856                 image2->numCols, image2->numRows,
     857                 image->numCols-qtrC, image->numRows-qtrR);
     858        return 22;
     859    }
     860
     861    for (int row = 0; row < image2->numRows; row++) {
     862        for (int col = 0; col < image2->numCols; col++) {
     863            if (fabsf(image2->data.F32[row][col] -
     864                      image->data.F32[row+qtrR][col+qtrC]) > FLT_EPSILON) {
     865                psLogMsg(__func__,PS_LOG_ERROR,
     866                         "The value at (%d,%d) was %g, but should be %g.",
     867                         col,row,
     868                         image2->data.F32[row][col],
     869                         image->data.F32[row+qtrR][col+qtrC]);
     870                return 23;
     871            }
     872        }
     873    }
     874
     875    psFree(image2);
     876
     877    /*
     878        6. invoke psImageTrim with image=NULL Verify:
     879            a. execution does not cease.
     880            b. return value is NULL
     881            c. appropriate error is generated.
     882    */
     883
     884    image2 = psImageTrim(NULL,qtrC,qtrR,0,0);
     885
     886    if (image2 != NULL) {
     887        psLogMsg(__func__,PS_LOG_ERROR,
     888                 "psImageTrim did not return NULL given a NULL input image.");
     889        return 31;
     890    }
     891    psErr* err = psErrorLast();
     892    if (err == NULL || err->code != PS_ERR_BAD_PARAMETER_NULL) {
     893        psLogMsg(__func__,PS_LOG_ERROR,
     894                 "psImageTrim did not generate an appropriate error for NULL input image.");
     895        psErrorStackPrint(stderr,"Error Stack:");
     896        return 32;
     897    }
     898    psFree(err);
     899
     900    image1 = psImageCopy(NULL,image,PS_TYPE_F32);
     901    image2 = psImageTrim(image1,-1,0,0,0);
     902
     903    if (image2 != NULL) {
     904        psLogMsg(__func__,PS_LOG_ERROR,
     905                 "psImageTrim did not return NULL given x0=-1.");
     906        return 33;
     907    }
     908    err = psErrorLast();
     909    if (err == NULL || err->code != PS_ERR_BAD_PARAMETER_VALUE) {
     910        psLogMsg(__func__,PS_LOG_ERROR,
     911                 "psImageTrim did not generate an appropriate error for x0=-1.");
     912        psErrorStackPrint(stderr,"Error Stack:");
     913        return 34;
     914    }
     915    psFree(err);
     916
     917    image1 = psImageCopy(NULL,image,PS_TYPE_F32);
     918    image2 = psImageTrim(image1,0,-1,0,0);
     919
     920    if (image2 != NULL) {
     921        psLogMsg(__func__,PS_LOG_ERROR,
     922                 "psImageTrim did not return NULL given y0=-1.");
     923        return 35;
     924    }
     925    err = psErrorLast();
     926    if (err == NULL || err->code != PS_ERR_BAD_PARAMETER_VALUE) {
     927        psLogMsg(__func__,PS_LOG_ERROR,
     928                 "psImageTrim did not generate an appropriate error for y0=-1.");
     929        psErrorStackPrint(stderr,"Error Stack:");
     930        return 36;
     931    }
     932    psFree(err);
     933
     934    image1 = psImageCopy(NULL,image,PS_TYPE_F32);
     935    image2 = psImageTrim(image1,0,0,image->numCols+1,0);
     936
     937    if (image2 != NULL) {
     938        psLogMsg(__func__,PS_LOG_ERROR,
     939                 "psImageTrim did not return NULL given x1=numCols+1.");
     940        return 37;
     941    }
     942    err = psErrorLast();
     943    if (err == NULL || err->code != PS_ERR_BAD_PARAMETER_VALUE) {
     944        psLogMsg(__func__,PS_LOG_ERROR,
     945                 "psImageTrim did not generate an appropriate error for x1=numCols+1.");
     946        psErrorStackPrint(stderr,"Error Stack:");
     947        return 38;
     948    }
     949    psFree(err);
     950
     951    image1 = psImageCopy(NULL,image,PS_TYPE_F32);
     952    image2 = psImageTrim(image1,0,0,0,image->numRows+1);
     953
     954    if (image2 != NULL) {
     955        psLogMsg(__func__,PS_LOG_ERROR,
     956                 "psImageTrim did not return NULL given y1=numRows+1.");
     957        return 39;
     958    }
     959    err = psErrorLast();
     960    if (err == NULL || err->code != PS_ERR_BAD_PARAMETER_VALUE) {
     961        psLogMsg(__func__,PS_LOG_ERROR,
     962                 "psImageTrim did not generate an appropriate error for y1=numRows+1.");
     963        psErrorStackPrint(stderr,"Error Stack:");
     964        return 40;
     965    }
     966    psFree(err);
     967
     968    image1 = psImageCopy(NULL,image,PS_TYPE_F32);
     969    image2 = psImageTrim(image1,0,0,-image->numCols,0);
     970
     971    if (image2 != NULL) {
     972        psLogMsg(__func__,PS_LOG_ERROR,
     973                 "psImageTrim did not return NULL given x1=-numCols.");
     974        return 41;
     975    }
     976    err = psErrorLast();
     977    if (err == NULL || err->code != PS_ERR_BAD_PARAMETER_VALUE) {
     978        psLogMsg(__func__,PS_LOG_ERROR,
     979                 "psImageTrim did not generate an appropriate error for x1=-numCols.");
     980        psErrorStackPrint(stderr,"Error Stack:");
     981        return 42;
     982    }
     983    psFree(err);
     984
     985    image1 = psImageCopy(NULL,image,PS_TYPE_F32);
     986    image2 = psImageTrim(image1,0,0,0,-image->numRows);
     987
     988    if (image2 != NULL) {
     989        psLogMsg(__func__,PS_LOG_ERROR,
     990                 "psImageTrim did not return NULL given y1=-numRows.");
     991        return 41;
     992    }
     993    err = psErrorLast();
     994    if (err == NULL || err->code != PS_ERR_BAD_PARAMETER_VALUE) {
     995        psLogMsg(__func__,PS_LOG_ERROR,
     996                 "psImageTrim did not generate an appropriate error for y1=-numRows.");
     997        psErrorStackPrint(stderr,"Error Stack:");
     998        return 42;
     999    }
     1000    psFree(err);
     1001
     1002    psFree(image);
    7681003    return 0;
    7691004}
Note: See TracChangeset for help on using the changeset viewer.