IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 1249


Ignore:
Timestamp:
Jul 21, 2004, 1:38:27 PM (22 years ago)
Author:
desonia
Message:

added tests for psImageRotate.

File:
1 edited

Legend:

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

    r1225 r1249  
    66 *  @author Robert DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-07-15 19:58:24 $
     8 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-07-21 23:38:27 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2727static int testImageRebin(void);
    2828static int testImageRoll(void);
     29static int testImageRotate(void);
    2930
    3031testDescription tests[] = {
     
    3435                              {testImageRebin,559,"psImageRebin",0,false},
    3536                              {testImageRoll,562,"psImageRoll",0,false},
     37                              {testImageRotate,560,"psImageRotate",0,false},
    3638                              {NULL}
    3739                          };
     
    390392    }
    391393
    392     psLogMsg(__func__,PS_LOG_INFO,"Following should error as overlay isn't within image boundaries");
     394    psLogMsg(__func__,PS_LOG_INFO,"Following should error as overlay isn't "
     395             "within image boundaries");
    393396    retVal = psImageOverlaySection(img,img2,c/4,r/4,"+");
    394397    if (retVal == 0) {
     
    470473
    471474    /*
    472     This function shall generate a rescaled version of a psImage structure derived from a specified statistics method.
     475    This function shall generate a rescaled version of a psImage structure
     476    derived from a specified statistics method.
    473477    */
    474478
     
    481485
    482486    /*
    483     Verify the returned psImage structure contains expected values, if the input parameter input contains known data, the input scale is a known value with a known statistical method specified in stats. Cases should include at least two different scales and statistical methods. Comparison of expected values should include a delta to allow testing on different platforms.
     487    Verify the returned psImage structure contains expected values, if the
     488    input parameter input contains known data, the input scale is a known
     489    value with a known statistical method specified in stats. Cases should
     490    include at least two different scales and statistical methods. Comparison
     491    of expected values should include a delta to allow testing on different
     492    platforms.
    484493    */
    485494
     
    518527
    519528    if (out->numRows != 4 || out->numCols != 4) {
    520         psError(__func__,"psImageRebin didn't produce the proper size image (%d x %d).",
     529        psError(__func__,"psImageRebin didn't produce the proper size image "
     530                "(%d x %d).",
    521531                out->numCols, out->numRows);
    522532        return 2;
     
    528538        for (int col = 0; col<4; col++) {
    529539            if (fabsf(outRow[col]-truthRow[col]) > FLT_EPSILON) {
    530                 psError(__func__,"psImageRebin didn't produce the proper result at (%d,%d) [%f vs %f].",
     540                psError(__func__,"psImageRebin didn't produce the proper "
     541                        "result at (%d,%d) [%f vs %f].",
    531542                        col,row,outRow[col],truthRow[col]);
    532543                return 3;
     
    538549    out2 = psImageRebin(out,in,3,&stats);
    539550
    540     // Verify the returned psImage structure is equal to the input parameter out if specified.
     551    // Verify the returned psImage structure is equal to the input parameter
     552    // out if specified.
    541553    if (out != out2) {
    542554        psError(__func__,"psImageRebin didn't recycle a psImage properly!?");
     
    550562
    551563    if (out->numRows != 6 || out->numCols != 6) {
    552         psError(__func__,"psImageRebin didn't produce the proper size image (%d x %d).",
     564        psError(__func__,"psImageRebin didn't produce the proper size image "
     565                "(%d x %d).",
    553566                out->numCols, out->numRows);
    554567        return 5;
     
    560573        for (int col = 0; col<6; col++) {
    561574            if (fabsf(outRow[col]-truthRow[col]) > FLT_EPSILON) {
    562                 psError(__func__,"psImageRebin didn't produce the proper result at (%d,%d) [%f vs %f].",
     575                psError(__func__,"psImageRebin didn't produce the proper "
     576                        "result at (%d,%d) [%f vs %f].",
    563577                        col,row,outRow[col],truthRow[col]);
    564578                return 6;
     
    573587
    574588    if (out2 != NULL) {
    575         psError(__func__,"psImageRebin returned an image though the input was NULL!?");
     589        psError(__func__,"psImageRebin returned an image though the input was "
     590                "NULL!?");
    576591        return 8;
    577592    }
     
    583598
    584599    if (out2 != NULL) {
    585         psError(__func__,"psImageRebin returned an image though the scale was zero!?");
     600        psError(__func__,"psImageRebin returned an image though the scale was "
     601                "zero!?");
    586602        return 9;
    587603    }
     
    593609
    594610    if (out2 != NULL) {
    595         psError(__func__,"psImageRebin returned an image though the stats was NULL!?");
     611        psError(__func__,"psImageRebin returned an image though the stats was "
     612                "NULL!?");
    596613        return 10;
    597614    }
     
    606623
    607624    if (out2 != NULL) {
    608         psError(__func__,"psImageRebin returned an image though the stats options was zero!?");
     625        psError(__func__,"psImageRebin returned an image though the stats "
     626                "options was zero!?");
    609627        return 11;
    610628    }
     
    615633
    616634    if (out2 != NULL) {
    617         psError(__func__,"psImageRebin returned an image though the stats options was PS_STAT_USE_RANGE!?");
     635        psError(__func__,"psImageRebin returned an image though the stats "
     636                "options was PS_STAT_USE_RANGE!?");
    618637        return 12;
    619638    }
     
    627646
    628647    if (out2 != NULL) {
    629         psError(__func__,"psImageRebin returned an image though the stats options was PS_STAT_SAMPLE_MEAN+PS_STAT_MAX!?");
     648        psError(__func__,"psImageRebin returned an image though the stats "
     649                "options was PS_STAT_SAMPLE_MEAN+PS_STAT_MAX!?");
    630650        return 13;
    631651    }
     
    792812    return 0;
    793813}
     814
     815int testImageRotate(void)
     816{
     817    /*
     818
     819    This function shall calculate a new psImage structure based upon the
     820    rotation of a given psImage structure. The center of rotation shall be the
     821    center pixel of the input image.
     822
     823    The following steps of the testpoint are done manually via inspection of
     824    temp/fOut.fits & temp/sOut.fits.
     825
     826        * Verify the returned psImage structure contains expected values, if
     827          the input parameter psImage contains known values. Cases should
     828          include rotations of 0, 60, 90, 120, 180, 240, 360 and at leat one
     829          other arbitrary angle. Cases of the input image should include image
     830          with a center pixel and an image without a center pixel.
     831        * Verify the returned psImage structure contains pixels set to TBD, if
     832          the rotation and input psImage to not correspond to the output image.
     833
     834    */
     835
     836    psImage* fOut = NULL;
     837    psImage* sOut = NULL;
     838    psImage* fTruth = NULL;
     839    psImage* sTruth = NULL;
     840    int rows = 100;
     841    int cols = 75;
     842    psImage* fImg = psImageAlloc(cols,rows,PS_TYPE_F32);
     843    psImage* sImg = psImageAlloc(cols,rows,PS_TYPE_S16);
     844
     845    for(int row=0;row<rows;row++) {
     846        psF32* fRow = fImg->data.F32[row];
     847        psS16* sRow = sImg->data.S16[row];
     848        for (int col=0;col<cols;col++) {
     849            fRow[col] = (psF32)(row)+(psF32)(col)/100.0f;
     850            sRow[col] = row-2*col;
     851        }
     852    }
     853
     854    // since interpolation is involved, etc., the simplist way to verify things
     855    // is to verify the results manually and bless it for automated comparison
     856    // thereafter
     857
     858
     859    // write results of various rotates to a file and verify with truth images
     860    remove
     861        ("temp/fOut.fits");
     862    remove
     863        ("temp/sOut.fits");
     864    int index = 0;
     865    bool fail = false;
     866    for (int rot=-180;rot<=180;rot+=30) {
     867        psImage* oldOut = fOut;
     868        fOut = psImageRotate(fOut,fImg,rot,-1.0,PS_INTERPOLATE_FLAT);
     869        // Verify the returned psImage structure is equal to the input
     870        // parameter out if provided.
     871        if (oldOut != NULL && oldOut != fOut) {
     872            psError(__func__,"the output recycle functionality failed");
     873            return 2;
     874        }
     875        sOut = psImageRotate(sOut,sImg,rot,-1.0,PS_INTERPOLATE_FLAT);
     876        psImageWriteSection(fOut,0,0,0,NULL,index,"temp/fOut.fits");
     877        psImageWriteSection(sOut,0,0,0,NULL,index,"temp/sOut.fits");
     878
     879        // now, let's compare this with the verified file
     880        fTruth = psImageReadSection(fTruth,0,0,0,0,0,NULL,index,"verified/fOut.fits");
     881        sTruth = psImageReadSection(sTruth,0,0,0,0,0,NULL,index,"verified/sOut.fits");
     882
     883        if (fTruth == NULL) {
     884            psError(__func__,"verified psF32 image failed to be read (%d deg. rotation)",
     885                    rot);
     886            fail = true;
     887        } else {
     888            if (fTruth->numRows != fOut->numRows || fTruth->numCols != fOut->numCols) {
     889                psError(__func__,"Rotated float image size did not match truth "
     890                        "image for %d deg rotation.");
     891                fail = true;
     892            } else {
     893                for (int row=0;row<fTruth->numRows;row++) {
     894                    psF32* truthRow = fTruth->data.F32[row];
     895                    psF32* outRow = fOut->data.F32[row];
     896                    for (int col=0;col<fTruth->numCols;col++) {
     897                        if (fabsf(truthRow[col]-outRow[col]) > FLT_EPSILON) {
     898                            psError(__func__,"Float Image mismatch (%f vs %f) at %d,%d.",
     899                                    outRow[col], truthRow[col],col,row);
     900                            fail = true;
     901                        }
     902                    }
     903                }
     904            }
     905        }
     906
     907        if (sTruth == NULL) {
     908            psError(__func__,"verified psS16 image failed to be read "
     909                    "(%d deg. rotation)",rot);
     910            fail = true;
     911        } else {
     912            if (sTruth->numRows != sOut->numRows ||
     913                    sTruth->numCols != sOut->numCols) {
     914                psError(__func__,"Rotated short image size did not match truth "
     915                        "image for %d deg rotation.");
     916                fail = true;
     917            } else {
     918                for (int row=0;row<sTruth->numRows;row++) {
     919                    psS16* truthRow = sTruth->data.S16[row];
     920                    psS16* outRow = sOut->data.S16[row];
     921                    for (int col=0;col<sTruth->numCols;col++) {
     922                        if (fabsf(truthRow[col]-outRow[col]) > 1) {
     923                            psError(__func__,"Short Image mismatch (%d vs %d) "
     924                                    "at %d,%d.",
     925                                    outRow[col], truthRow[col],col,row);
     926                            fail = true;
     927                        }
     928                    }
     929                }
     930            }
     931        }
     932
     933
     934        index++;
     935    }
     936
     937    if (fail) {
     938        psError(__func__,"One or more images didn't match truth or truth did "
     939                "not exist.");
     940        return 10;
     941    }
     942
     943
     944    // Verify the returned psImage structure pointer is null and program
     945    // execution doesn't stop, if the input parameter input is null.
     946    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error");
     947    fOut = psImageRotate(fOut,NULL,0,0,PS_INTERPOLATE_FLAT);
     948    if (fOut != NULL) {
     949        psError(__func__,"NULL wasn't returned though the input image was NULL.");
     950        return 3;
     951    }
     952
     953    psFree(sOut);
     954    psFree(fImg);
     955    psFree(sImg);
     956    psFree(fTruth);
     957    psFree(sTruth);
     958
     959    return 0;
     960}
Note: See TracChangeset for help on using the changeset viewer.