IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 2105


Ignore:
Timestamp:
Oct 13, 2004, 3:22:59 PM (22 years ago)
Author:
desonia
Message:

added test for psImageResample.

Location:
trunk/psLib
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/image/psImage.c

    r2067 r2105  
    1010 *  @author Ross Harman, MHPCC
    1111 *
    12  *  @version $Revision: 1.49 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-10-13 00:10:50 $
     12 *  @version $Revision: 1.50 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-10-14 01:22:59 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    441441        psF64 unexposedValue) \
    442442{ \
    443     int intX = (int) round((psF64)(x) - 0.5); \
    444     int intY = (int) round((psF64)(y) - 0.5); \
     443    int intX = (int) round((psF64)(x) - 0.5 + FLT_EPSILON); \
     444    int intY = (int) round((psF64)(y) - 0.5 + FLT_EPSILON); \
    445445    int lastX = input->numCols - 1; \
    446446    int lastY = input->numRows - 1; \
  • trunk/psLib/src/image/psImage.h

    r2067 r2105  
    1111 *  @author Ross Harman, MHPCC
    1212 *
    13  *  @version $Revision: 1.40 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2004-10-13 00:10:50 $
     13 *  @version $Revision: 1.41 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2004-10-14 01:22:59 $
    1515 *
    1616 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3131 */
    3232typedef enum {
    33     PS_INTERPOLATE_FLAT,               ///< 'flat' interpolation (nearest pixel)
     33    PS_INTERPOLATE_FLAT = 1,           ///< 'flat' interpolation (nearest pixel)
    3434    PS_INTERPOLATE_BILINEAR,           ///< bi-linear interpolation
    3535    PS_INTERPOLATE_BICUBIC,            ///< bi-cubic interpolation
    36     PS_INTERPOLATE_SINC                ///< sinc interpolation
     36    PS_INTERPOLATE_SINC,               ///< sinc interpolation
     37    PS_INTERPOLATE_NUM_MODES           ///< end-marker of list of modes; not a valid interpolation mode
    3738} psImageInterpolateMode;
    3839
  • trunk/psLib/src/image/psImageExtraction.c

    r2093 r2105  
    99 *  @author Robert DeSonia, MHPCC
    1010 *
    11  *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-10-13 23:34:57 $
     11 *  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-10-14 01:22:59 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    543543    }
    544544
     545    if (mode < PS_INTERPOLATE_FLAT || mode >= PS_INTERPOLATE_NUM_MODES) {
     546        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageResample",
     547                   PS_ERR_BAD_PARAMETER_VALUE, true,
     548                   PS_ERRORTEXT_psImageManip_INTERPOLATION_MODE_UNSUPPORTED,
     549                   mode);
     550        psFree(out);
     551        return NULL;
     552    }
     553
    545554    if (mask != NULL) {
    546555        if (numRows != mask->numRows || numCols != mask->numCols) {
  • trunk/psLib/src/image/psImageManip.c

    r1941 r2105  
    1010 *  @author Ross Harman, MHPCC
    1111 *
    12  *  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-10-02 02:08:00 $
     12 *  @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-10-14 01:22:59 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    569569        return NULL;
    570570    }
     571
     572    if (scale < 1) {
     573        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageResample",
     574                   PS_ERR_BAD_PARAMETER_VALUE, true,
     575                   PS_ERRORTEXT_psImageManip_SCALE_NOT_POSITIVE,
     576                   scale);
     577        psFree(out);
     578        return NULL;
     579    }
     580
     581    if (mode < PS_INTERPOLATE_FLAT || mode >= PS_INTERPOLATE_NUM_MODES) {
     582        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageResample",
     583                   PS_ERR_BAD_PARAMETER_VALUE, true,
     584                   PS_ERRORTEXT_psImageManip_INTERPOLATION_MODE_UNSUPPORTED,
     585                   mode);
     586        psFree(out);
     587        return NULL;
     588    }
     589
    571590    // create an output image of the same size
    572591    // and type
     
    582601            float inRow = (float)row * invScale; \
    583602            for (int col=0;col<outCols;col++) { \
    584                 rowData[col] = psImagePixelInterpolate(in,inRow,(float)col*invScale,NULL,0,0,mode); \
     603                rowData[col] = psImagePixelInterpolate(in,(float)col*invScale,inRow,NULL,0,0,mode); \
    585604            } \
    586605        }  \
  • trunk/psLib/src/mathtypes/psImage.c

    r2067 r2105  
    1010 *  @author Ross Harman, MHPCC
    1111 *
    12  *  @version $Revision: 1.49 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-10-13 00:10:50 $
     12 *  @version $Revision: 1.50 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-10-14 01:22:59 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    441441        psF64 unexposedValue) \
    442442{ \
    443     int intX = (int) round((psF64)(x) - 0.5); \
    444     int intY = (int) round((psF64)(y) - 0.5); \
     443    int intX = (int) round((psF64)(x) - 0.5 + FLT_EPSILON); \
     444    int intY = (int) round((psF64)(y) - 0.5 + FLT_EPSILON); \
    445445    int lastX = input->numCols - 1; \
    446446    int lastY = input->numRows - 1; \
  • trunk/psLib/src/mathtypes/psImage.h

    r2067 r2105  
    1111 *  @author Ross Harman, MHPCC
    1212 *
    13  *  @version $Revision: 1.40 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2004-10-13 00:10:50 $
     13 *  @version $Revision: 1.41 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2004-10-14 01:22:59 $
    1515 *
    1616 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3131 */
    3232typedef enum {
    33     PS_INTERPOLATE_FLAT,               ///< 'flat' interpolation (nearest pixel)
     33    PS_INTERPOLATE_FLAT = 1,           ///< 'flat' interpolation (nearest pixel)
    3434    PS_INTERPOLATE_BILINEAR,           ///< bi-linear interpolation
    3535    PS_INTERPOLATE_BICUBIC,            ///< bi-cubic interpolation
    36     PS_INTERPOLATE_SINC                ///< sinc interpolation
     36    PS_INTERPOLATE_SINC,               ///< sinc interpolation
     37    PS_INTERPOLATE_NUM_MODES           ///< end-marker of list of modes; not a valid interpolation mode
    3738} psImageInterpolateMode;
    3839
  • trunk/psLib/test/image/tst_psImageManip.c

    r1943 r2105  
    66 *  @author Robert DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-10-02 02:23:05 $
     8 *  @version $Revision: 1.29 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-10-14 01:22:59 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3434static int testImageShift(void);
    3535static int testImageShiftCase(int cols, int rows, float colShift,float rowShift);
     36static int testImageResample(void);
    3637
    3738testDescription tests[] = {
     
    4445                              {testImageRotate,560,"psImageRotate",0,false},
    4546                              {testImageShift,561,"psImageShift",0,false},
     47                              {testImageResample,743,"psImageResample",0,false},
    4648                              {NULL}
    4749                          };
     
    17041706    return 0;
    17051707}
     1708
     1709static int testImageResample(void)
     1710{
     1711
     1712    int rows = 60;
     1713    int cols = 80;
     1714    psImage* result = NULL;
     1715    int scale = 4;
     1716    psErr* err;
     1717
     1718    psImage* image = psImageAlloc(cols,rows,PS_TYPE_F32);
     1719    for(int row=0;row<rows;row++) {
     1720        psF32* imageRow = image->data.F32[row];
     1721        for (int col=0;col<cols;col++) {
     1722            imageRow[col] = row+2*col;
     1723        }
     1724    }
     1725    result = psImageCopy(NULL,image,PS_TYPE_F64);
     1726    psImage* orig = result;
     1727    result = psImageResample(result,image,scale,PS_INTERPOLATE_FLAT);
     1728
     1729    if (result == NULL) {
     1730        psLogMsg(__func__,PS_LOG_ERROR,
     1731                 "NULL return unexpected");
     1732        return 1;
     1733    }
     1734
     1735    if (result != orig) {
     1736        psLogMsg(__func__,PS_LOG_ERROR,"failure to recycle image.");
     1737        return 2;
     1738    }
     1739
     1740    if (result->type.type != PS_TYPE_F32) {
     1741        psLogMsg(__func__,PS_LOG_ERROR,"unexpected type");
     1742        return 3;
     1743    }
     1744
     1745
     1746    if (result->numCols != image->numCols*scale ||
     1747            result->numRows != image->numRows*scale) {
     1748        psLogMsg(__func__,PS_LOG_ERROR,"The size of the result is %dx%d, but %dx%d was expected.",
     1749                 result->numCols,result->numRows,
     1750                 image->numCols*scale, image->numRows*scale);
     1751        return 4;
     1752    }
     1753
     1754    psF32 truthValue;
     1755    for(int row=0;row<result->numRows;row++) {
     1756        for (int col=0;col<result->numCols;col++) {
     1757            truthValue = psImagePixelInterpolate(image,
     1758                                                 (float)col/(float)scale,(float)row/(float)scale,
     1759                                                 NULL,0,-1,PS_INTERPOLATE_FLAT);
     1760            if (fabs(truthValue - result->data.F32[row][col]) > FLT_EPSILON) {
     1761                psLogMsg(__func__,PS_LOG_ERROR,"value bad at (%d,%d).  Got %g, expected %g.",
     1762                         col,row,result->data.F32[row][col], truthValue);
     1763                return 5;
     1764            }
     1765        }
     1766    }
     1767
     1768    // verify that image=null is handled properly.
     1769    psErrorClear();
     1770    result = psImageResample(result,NULL,scale,PS_INTERPOLATE_FLAT);
     1771
     1772    if (result != NULL) {
     1773        psLogMsg(__func__,PS_LOG_ERROR,
     1774                 "return was not NULL, as expected.");
     1775        return 6;
     1776    }
     1777    err = psErrorLast();
     1778    if (err->code != PS_ERR_BAD_PARAMETER_NULL) {
     1779        psLogMsg(__func__,PS_LOG_ERROR,
     1780                 "error message was not appropriate type.");
     1781        return 7;
     1782    }
     1783    psFree(err);
     1784
     1785    // verify that scale < 1 is handled properly
     1786    psErrorClear();
     1787    result = psImageResample(result,image,0,PS_INTERPOLATE_FLAT);
     1788
     1789    if (result != NULL) {
     1790        psLogMsg(__func__,PS_LOG_ERROR,
     1791                 "return was not NULL, as expected.");
     1792        return 8;
     1793    }
     1794    err = psErrorLast();
     1795    if (err->code != PS_ERR_BAD_PARAMETER_VALUE) {
     1796        psLogMsg(__func__,PS_LOG_ERROR,
     1797                 "error message was not appropriate type.");
     1798        return 9;
     1799    }
     1800    psFree(err);
     1801
     1802    // verify that invalid interpolation mode is handled properly
     1803    psErrorClear();
     1804    result = psImageResample(result,image,2,0);
     1805
     1806    if (result != NULL) {
     1807        psLogMsg(__func__,PS_LOG_ERROR,
     1808                 "return was not NULL, as expected.");
     1809        return 10;
     1810    }
     1811    err = psErrorLast();
     1812    if (err->code != PS_ERR_BAD_PARAMETER_VALUE) {
     1813        psLogMsg(__func__,PS_LOG_ERROR,
     1814                 "error message was not appropriate type.");
     1815        return 11;
     1816    }
     1817    psFree(err);
     1818
     1819    psFree(image);
     1820    psFree(result);
     1821
     1822    return 0;
     1823}
     1824
  • trunk/psLib/test/image/verified/tst_psImageExtraction.stderr

    r2095 r2105  
    138138    Following should be an error.
    139139<DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
    140     Input psImage mask size, 2000x1000, does not match psImage input size, 1869636978x1635018016.
    141 <DATE><TIME>|<HOST>|I|testImageSlice
    142     Following should be an error.
    143 <DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
    144     Input psImage mask size, 2000x1000, does not match psImage input size, 1869636978x1635018016.
     140    Input psImage mask size, 2000x1000, does not match psImage input size, 1919250543x543519841.
     141<DATE><TIME>|<HOST>|I|testImageSlice
     142    Following should be an error.
     143<DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
     144    Input psImage mask size, 2000x1000, does not match psImage input size, 1919250543x543519841.
    145145<DATE><TIME>|<HOST>|I|testImageSlice
    146146    Following should be an error.
     
    150150    Following should be an error.
    151151<DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
    152     Input psImage mask size, 2000x1000, does not match psImage input size, 1869636978x1635018016.
    153 <DATE><TIME>|<HOST>|I|testImageSlice
    154     Following should be an error.
    155 <DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
    156     Input psImage mask size, 2000x1000, does not match psImage input size, 1869636978x1635018016.
    157 <DATE><TIME>|<HOST>|I|testImageSlice
    158     Following should be an error.
    159 <DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
    160     Input psImage mask size, 2000x1000, does not match psImage input size, 1869636978x1635018016.
    161 <DATE><TIME>|<HOST>|I|testImageSlice
    162     Following should be an error.
    163 <DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
    164     Input psImage mask size, 2000x1000, does not match psImage input size, 1869636978x1635018016.
    165 <DATE><TIME>|<HOST>|I|testImageSlice
    166     Following should be an error.
    167 <DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
    168     Input psImage mask size, 2000x1000, does not match psImage input size, 1869636978x1635018016.
     152    Input psImage mask size, 2000x1000, does not match psImage input size, 1919250543x543519841.
     153<DATE><TIME>|<HOST>|I|testImageSlice
     154    Following should be an error.
     155<DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
     156    Input psImage mask size, 2000x1000, does not match psImage input size, 1919250543x543519841.
     157<DATE><TIME>|<HOST>|I|testImageSlice
     158    Following should be an error.
     159<DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
     160    Input psImage mask size, 2000x1000, does not match psImage input size, 1919250543x543519841.
     161<DATE><TIME>|<HOST>|I|testImageSlice
     162    Following should be an error.
     163<DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
     164    Input psImage mask size, 2000x1000, does not match psImage input size, 1919250543x543519841.
     165<DATE><TIME>|<HOST>|I|testImageSlice
     166    Following should be an error.
     167<DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
     168    Input psImage mask size, 2000x1000, does not match psImage input size, 1919250543x543519841.
    169169<DATE><TIME>|<HOST>|I|testImageSlice
    170170    Following should be an error mask size != image size.
  • trunk/psLib/test/image/verified/tst_psImageManip.stderr

    r1943 r2105  
    307307---> TESTPOINT PASSED (psImage{psImageShift} | tst_psImageManip.c)
    308308
     309/***************************** TESTPOINT ******************************************\
     310*             TestFile: tst_psImageManip.c                                         *
     311*            TestPoint: psImage{psImageResample}                                   *
     312*             TestType: Positive                                                   *
     313\**********************************************************************************/
     314
     315<DATE><TIME>|<HOST>|E|psLib.image.psImageResample
     316    Can not operate on a NULL psImage.
     317<DATE><TIME>|<HOST>|E|psLib.image.psImageResample
     318    Specified scale value, 0, must be a positive value.
     319<DATE><TIME>|<HOST>|E|psLib.image.psImageResample
     320    Specified interpolation mode, 0, is unsupported.
     321
     322---> TESTPOINT PASSED (psImage{psImageResample} | tst_psImageManip.c)
     323
Note: See TracChangeset for help on using the changeset viewer.