IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6750


Ignore:
Timestamp:
Mar 31, 2006, 4:43:57 PM (20 years ago)
Author:
drobbin
Message:

Made several changes to image functions/tests w.r.t. subimage v. parent image issue.

Location:
trunk/psLib
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/imageops/psImageGeomManip.c

    r6484 r6750  
    1010 *  @author Ross Harman, MHPCC
    1111 *
    12  *  @version $Revision: 1.20 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2006-02-24 23:43:15 $
     12 *  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2006-04-01 02:43:57 $
    1414 *
    1515 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    749749        col0 = region.x0;
    750750        col1 = region.x1;
     751        //If [0,0,0,0] specified, the whole image is to be included
     752        if (row0 == 0 && col0 == 0 && row1 == 0 && col1 == 0) {
     753            row0 = input->row0;
     754            col0 = input->col0;
     755            row1 = input->row0 + input->numRows;
     756            col1 = input->col0 + input->numCols;
     757        }
    751758        if (col1 < 1) {
    752             col1 += input->numCols;
     759            col1 += input->col0 + input->numCols;
    753760        }
    754761
    755762        if (row1 < 1) {
    756             row1 += input->numRows;
     763            row1 += input->row0 + input->numRows;
    757764        }
    758765
  • trunk/psLib/src/imageops/psImageGeomManip.h

    r6354 r6750  
    88 *  @author Robert DeSonia, MHPCC
    99 *
    10  *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2006-02-08 01:03:35 $
     10 *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2006-04-01 02:43:57 $
    1212 *
    1313 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    150150    const psPlaneTransform *outToIn,   ///< the transform to apply
    151151    psRegion region,                   ///< the size of the transformed image
    152     const psPixels* pixels,            /**< if not NULL, consists of psPixelCoords and specifies which pixels in
    153                                                                                  *  output image shall be transformed; otherwise, entire image generated*/
     152    const psPixels* pixels,            /**< if not NULL, consists of psPixelCoords and specifies
     153                                            * which pixels in output image shall be transformed;
     154                                            * otherwise, entire image generated*/
    154155    psImageInterpolateMode mode,       ///< the interpolation scheme to be used
    155     double exposedValue                   ///< Exposed value to which non-corresponding pixels are set
     156    double exposedValue                ///< Exposed value to which non-corresponding pixels are set
    156157);
    157158
  • trunk/psLib/src/imageops/psImagePixelExtract.c

    r6631 r6750  
    88 *  @author Robert DeSonia, MHPCC
    99 *
    10  *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2006-03-17 20:38:19 $
     10 *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2006-04-01 02:43:57 $
    1212 *
    1313 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    5757        return NULL;
    5858    }
    59     PS_ASSERT_INT_NONNEGATIVE(input->col0, NULL);
    60     PS_ASSERT_INT_NONNEGATIVE(input->row0, NULL);
    61     PS_ASSERT_INT_POSITIVE(input->numCols, NULL);
    62     PS_ASSERT_INT_POSITIVE(input->numRows, NULL);
     59    if (input->col0 < 0) {
     60        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     61                "psImage input is invalid.  col0 cannot be negative.\n");
     62        psFree(out);
     63        return NULL;
     64    }
     65    if (input->row0 < 0) {
     66        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     67                "psImage input is invalid.  row0 cannot be negative.\n");
     68        psFree(out);
     69        return NULL;
     70    }
     71    if (input->numCols < 1) {
     72        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     73                "psImage input is invalid.  numCols must be greater than 0.\n");
     74        psFree(out);
     75        return NULL;
     76    }
     77    if (input->numRows < 1) {
     78        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     79                "psImage input is invalid.  numRows must be greater than 0.\n");
     80        psFree(out);
     81        return NULL;
     82    }
    6383    if (row >= (input->numRows + input->row0) ) {
    6484        psError(PS_ERR_BAD_PARAMETER_NULL, true,
    6585                "Specified row number is out of range for specified image.\n");
     86        psFree(out);
    6687        return NULL;
    6788    } else if ( row < input->row0 && row >= 0 ) {
    6889        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    6990                "Specified row number is out of range for specified image.\n");
     91        psFree(out);
    7092        return NULL;
    7193    } else if ( row < 0 ) {
     
    7496            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    7597                    "Specified row number is out of range for specified image.\n");
     98            psFree(out);
    7699            return NULL;
    77100        }
     
    164187        return NULL;
    165188    }
    166     PS_ASSERT_INT_NONNEGATIVE(input->col0, NULL);
    167     PS_ASSERT_INT_NONNEGATIVE(input->row0, NULL);
    168     PS_ASSERT_INT_POSITIVE(input->numCols, NULL);
    169     PS_ASSERT_INT_POSITIVE(input->numRows, NULL);
     189    if (input->col0 < 0) {
     190        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     191                "psImage input is invalid.  col0 cannot be negative.\n");
     192        psFree(out);
     193        return NULL;
     194    }
     195    if (input->row0 < 0) {
     196        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     197                "psImage input is invalid.  row0 cannot be negative.\n");
     198        psFree(out);
     199        return NULL;
     200    }
     201    if (input->numCols < 1) {
     202        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     203                "psImage input is invalid.  numCols must be greater than 0.\n");
     204        psFree(out);
     205        return NULL;
     206    }
     207    if (input->numRows < 1) {
     208        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     209                "psImage input is invalid.  numRows must be greater than 0.\n");
     210        psFree(out);
     211        return NULL;
     212    }
    170213    if (column >= (input->numCols + input->col0) ) {
    171214        psError(PS_ERR_BAD_PARAMETER_NULL, true,
    172215                "Specified column number is out of range for specified image.\n");
     216        psFree(out);
    173217        return NULL;
    174218    } else if ( column < input->col0 && column >= 0 ) {
    175219        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    176220                "Specified column number is out of range for specified image.\n");
     221        psFree(out);
    177222        return NULL;
    178223    } else if ( column < 0 ) {
     
    181226            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    182227                    "Specified column number is out of range for specified image.\n");
     228            psFree(out);
    183229            return NULL;
    184230        }
     
    263309        return NULL;
    264310    }
    265     PS_ASSERT_INT_NONNEGATIVE(input->col0, NULL);
    266     PS_ASSERT_INT_NONNEGATIVE(input->row0, NULL);
    267     PS_ASSERT_INT_POSITIVE(input->numCols, NULL);
    268     PS_ASSERT_INT_POSITIVE(input->numRows, NULL);
     311    if (input->col0 < 0) {
     312        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     313                "psImage input is invalid.  col0 cannot be negative.\n");
     314        psFree(out);
     315        return NULL;
     316    }
     317    if (input->row0 < 0) {
     318        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     319                "psImage input is invalid.  row0 cannot be negative.\n");
     320        psFree(out);
     321        return NULL;
     322    }
     323    if (input->numCols < 1) {
     324        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     325                "psImage input is invalid.  numCols must be greater than 0.\n");
     326        psFree(out);
     327        return NULL;
     328    }
     329    if (input->numRows < 1) {
     330        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     331                "psImage input is invalid.  numRows must be greater than 0.\n");
     332        psFree(out);
     333        return NULL;
     334    }
    269335    /*
    270336        if (col1 < 1) {
    271337            col1 += input->numCols;
    272338        }
    273      
     339
    274340        if (row1 < 1) {
    275341            row1 += input->numRows;
    276342        }
    277      
     343
    278344        if (    col0 < 0 ||
    279345                row0 < 0 ||
     
    296362        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    297363                "Specified psRegion parameter, x0=%f, is out of range [%d,%d].\n",
    298                 region.x0, input->col0, input->col0+input->numCols);
     364                region.x0, input->col0, input->col0+input->numCols-1);
    299365        return NULL;
    300366    }
     
    305371        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    306372                "Specified psRegion parameter, y0=%f, is out of range [%d,%d].\n",
    307                 region.y0, input->row0, input->row0+input->numRows);
     373                region.y0, input->row0, input->row0+input->numRows-1);
    308374        return NULL;
    309375    }
     
    315381            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    316382                    "Specified psRegion parameter, x1=%f=%d, is out of range [%d,%d].\n",
    317                     region.x1, col1+input->col0, input->col0, input->col0+input->numCols);
     383                    region.x1, col1+input->col0, input->col0, input->col0+input->numCols-1);
    318384            return NULL;
    319385        }
     
    323389        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    324390                "Specified psRegion parameter, x1=%f=%d, is out of range [%d,%d].\n",
    325                 region.x1, col1, input->col0, input->col0+input->numCols);
     391                region.x1, col1, input->col0, input->col0+input->numCols-1);
    326392        return NULL;
    327393    }
     
    332398            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    333399                    "Specified psRegion parameter, y1=%f=%d, is out of range [%d,%d].\n",
    334                     region.y1, row1+input->row0, input->row0, input->row0+input->numRows);
     400                    region.y1, row1+input->row0, input->row0, input->row0+input->numRows-1);
    335401            return NULL;
    336402        }
     
    340406        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    341407                "Specified psRegion parameter, y1=%f=%d, is out of range [%d,%d].\n",
    342                 region.y1, row1, input->row0, input->row0+input->numRows);
     408                region.y1, row1, input->row0, input->row0+input->numRows-1);
    343409        return NULL;
    344410    }
     
    583649        return NULL;
    584650    }
    585     //    PS_ASSERT_INT_NONNEGATIVE(input->col0, NULL);
    586     //    PS_ASSERT_INT_NONNEGATIVE(input->row0, NULL);
    587     //    PS_ASSERT_INT_POSITIVE(input->numCols, NULL);
    588     //    PS_ASSERT_INT_POSITIVE(input->numRows, NULL);
     651    if (input->col0 < 0) {
     652        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     653                "psImage input is invalid.  col0 cannot be negative.\n");
     654        psFree(out);
     655        return NULL;
     656    }
     657    if (input->row0 < 0) {
     658        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     659                "psImage input is invalid.  row0 cannot be negative.\n");
     660        psFree(out);
     661        return NULL;
     662    }
     663    if (input->numCols < 1) {
     664        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     665                "psImage input is invalid.  numCols must be greater than 0.\n");
     666        psFree(out);
     667        return NULL;
     668    }
     669    if (input->numRows < 1) {
     670        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     671                "psImage input is invalid.  numRows must be greater than 0.\n");
     672        psFree(out);
     673        return NULL;
     674    }
    589675    psS32 numCols = input->numCols;
    590676    psS32 numRows = input->numRows;
     
    598684    }
    599685
    600 
    601     float startCol = region.x0;
    602     float startRow = region.y0;
    603     float endCol = region.x1;
    604     float endRow = region.y1;
    605     if (startCol < 0 || startCol >= numCols ||
    606             startRow < 0 || startRow >= numRows ||
    607             endCol < 0 || endCol >= numCols ||
    608             endRow < 0 || endRow >= numRows) {
    609         psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    610                 PS_ERRORTEXT_psImage_LINE_NOT_IN_IMAGE,
    611                 startCol,startRow,endCol,endRow,
    612                 numCols-1,numRows-1);
    613         psFree(out);
    614         return NULL;
    615     }
     686    float col0 = region.x0;
     687    float row0 = region.y0;
     688    float col1 = region.x1;
     689    float row1 = region.y1;
     690
     691    //Make sure x0 of region is inside image.  If so, set col0 to corresponding index number.
     692    if (col0 >= input->col0 && col0 < (input->col0 + input->numCols) ) {
     693        col0 -= input->col0;
     694    } else {
     695        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     696                "Specified psRegion parameter, x0=%f, is out of range [%d,%d].\n",
     697                region.x0, input->col0, input->col0+input->numCols);
     698        psFree(out);
     699        return NULL;
     700    }
     701    //Make sure y0 of region is inside image.  If so, set row0 to corresponding index number.
     702    if (row0 >= input->row0 && row0 < (input->row0 + input->numRows) ) {
     703        row0 -= input->row0;
     704    } else {
     705        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     706                "Specified psRegion parameter, y0=%f, is out of range [%d,%d].\n",
     707                region.y0, input->row0, input->row0+input->numRows);
     708        psFree(out);
     709        return NULL;
     710    }
     711    /*
     712        //Make sure x1 of region is valid.  If negative, index from tail (if valid).
     713        if (col1 < 0) {
     714            col1 += input->numCols;
     715            if (col1 < 0) {
     716                psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     717                        "Specified psRegion parameter, x1=%f=%f, is out of range [%d,%d].\n",
     718                        region.x1, col1+input->col0, input->col0, input->col0+input->numCols);
     719                psFree(out);
     720                return NULL;
     721            }
     722        } else if (col1 >= input->col0 && col1 < (input->col0 + input->numCols) ) {
     723            col1 -= input->col0;
     724        } else {
     725            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     726                    "Specified psRegion parameter, x1=%f=%f, is out of range [%d,%d].\n",
     727                    region.x1, col1, input->col0, input->col0+input->numCols);
     728            psFree(out);
     729            return NULL;
     730        }
     731        //Make sure y1 of region is valid.  If negative, index from tail (if valid).
     732        if (row1 < 0) {
     733            row1 += input->numRows;
     734            if (row1 < 0) {
     735                psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     736                        "Specified psRegion parameter, y1=%f=%f, is out of range [%d,%d].\n",
     737                        region.y1, row1+input->row0, input->row0, input->row0+input->numRows);
     738                psFree(out);
     739                return NULL;
     740            }
     741        } else if (row1 >= input->row0 && row1 < (input->row0 + input->numRows) ) {
     742            row1 -= input->row0;
     743        } else {
     744            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     745                    "Specified psRegion parameter, y1=%f=%f, is out of range [%d,%d].\n",
     746                    region.y1, row1, input->row0, input->row0+input->numRows);
     747            psFree(out);
     748            return NULL;
     749        }
     750    */
     751    /*    //Now make sure that the region makes sense.
     752        if (col0 > col1 || row0 > row1) {
     753            if (col0 > col1) {
     754                psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     755                        "Invalid psRegion specified.  x0=%f=%f is greater than x1=%f=%f.\n",
     756                        region.x0, col0, region.x1, col1);
     757            } else {
     758                psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     759                        "Invalid psRegion specified.  y0=%f=%f is greater than y1=%f=%f.\n",
     760                        region.y0, row0, region.y1, row1);
     761            }
     762            psFree(out);
     763            return NULL;
     764        } else if (col0 == col1 && row0 == row1) {
     765            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     766                    "Invalid psRegion specified.  Region contains only 1 pixel.\n");
     767            psFree(out);
     768            return NULL;
     769        }
     770    */
     771    if (col1 < 0 || row1 < 0 || col0 < 0 || row0 < 0 || col0 >= numCols || col1 >= numCols ||
     772            row0 >= numRows || row1 >= numRows) {
     773        psFree(out);
     774        return NULL;
     775    }
     776    float startCol = col0;
     777    float startRow = row0;
     778    float endCol = col1;
     779    float endRow = row1;
     780    /*
     781        float startCol = region.x0;
     782        float startRow = region.y0;
     783        float endCol = region.x1;
     784        float endRow = region.y1;
     785        if (startCol < 0 || startCol >= numCols ||
     786                startRow < 0 || startRow >= numRows ||
     787                endCol < 0 || endCol >= numCols ||
     788                endRow < 0 || endRow >= numRows) {
     789            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     790                    PS_ERRORTEXT_psImage_LINE_NOT_IN_IMAGE,
     791                    startCol,startRow,endCol,endRow,
     792                    numCols-1,numRows-1);
     793            psFree(out);
     794            return NULL;
     795        }
     796    */
    616797
    617798    if (mode < PS_INTERPOLATE_FLAT ) {
  • trunk/psLib/src/imageops/psImageStats.c

    r6346 r6750  
    99 *  @author GLG, MHPCC
    1010 *
    11  *  @version $Revision: 1.90 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2006-02-07 23:14:21 $
     11 *  @version $Revision: 1.91 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2006-04-01 02:43:57 $
    1313 *
    1414 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    267267    // We scale the pixel positions to values
    268268    // between -1.0 and 1.0
    269     rScalingFactors = calcScaleFactors(input->numRows);
    270     cScalingFactors = calcScaleFactors(input->numCols);
     269    //    rScalingFactors = calcScaleFactors(input->numRows);
     270    //    cScalingFactors = calcScaleFactors(input->numCols);
     271    rScalingFactors = calcScaleFactors(input->row0 + input->numRows);
     272    cScalingFactors = calcScaleFactors(input->col0 + input->numCols);
    271273
    272274    // Determine how many Chebyshev polynomials
     
    283285        for (j = 0; j < (1 + coeffs->nY); j++) {
    284286            sums[i][j] = 0.0;
    285             for (x = 0; x < input->numRows; x++) {
    286                 for (y = 0; y < input->numCols; y++) {
     287            //            for (x = 0; x < input->numRows; x++) {
     288            //                for (y = 0; y < input->numCols; y++) {
     289            for (x = input->row0; x < (input->row0 + input->numRows); x++) {
     290                for (y = input->col0; y < (input->col0 + input->numCols); y++) {
    287291                    double pixel = 0.0;
    288292                    if (input->type.type == PS_TYPE_S8) {
     
    399403            //            nodes->data.F64[x][y] = psImagePixelInterpolate(input, yNode, xNode, NULL, 0, 0.0, PS_INTERPOLATE_BILINEAR);
    400404            //            nodes->data.F64[x][y] = psImagePixelInterpolate(input, yTmp, xTmp, NULL, 0, 0.0, PS_INTERPOLATE_BILINEAR);
    401             nodes->data.F64[x][y] = psImagePixelInterpolate(input, yOrig, xOrig, NULL, 0, 0.0, PS_INTERPOLATE_BILINEAR);
     405            nodes->data.F64[x][y] = psImagePixelInterpolate(input, yOrig, xOrig, NULL,
     406                                    0, 0.0, PS_INTERPOLATE_BILINEAR);
    402407        }
    403408    }
     
    505510    // We scale the pixel positions to values between -1.0 and 1.0
    506511    // Use static data structures here.
    507     rScalingFactors = calcScaleFactors(input->numRows);
    508     cScalingFactors = calcScaleFactors(input->numCols);
     512    //    rScalingFactors = calcScaleFactors(input->numRows);
     513    //    cScalingFactors = calcScaleFactors(input->numCols);
     514    rScalingFactors = calcScaleFactors(input->numRows+input->row0);
     515    cScalingFactors = calcScaleFactors(input->numCols+input->col0);
    509516
    510517    // Determine how many Chebyshev polynomials
     
    517524    chebPolys = p_psCreateChebyshevPolys(maxChebyPoly + 1);
    518525
    519     for (x = 0; x < input->numRows; x++) {
    520         for (y = 0; y < input->numCols; y++) {
     526    //    for (x = 0; x < input->numRows; x++) {
     527    //        for (y = 0; y < input->numCols; y++) {
     528    for (x = input->row0; x < (input->row0 + input->numRows); x++) {
     529        for (y = input->col0; y < (input->col0 + input->numCols); y++) {
    521530            polySum = 0.0;
    522531            for (i = 0; i < (1 + coeffs->nX); i++) {
     
    563572        for (int col = 0; col < input->numCols ; col++) {
    564573            if (input->type.type == PS_TYPE_S8) {
    565                 input->data.S8[row][col] = (psS8) psPolynomial2DEval(coeffs, (psF32) row, (psF32) col);
     574                input->data.S8[row][col] = (psS8) psPolynomial2DEval(coeffs,
     575                                           (psF32) (row + input->row0), (psF32) (col + input->col0));
    566576            } else if (input->type.type == PS_TYPE_U16) {
    567                 input->data.U16[row][col] = (psS16) psPolynomial2DEval(coeffs, (psF32) row, (psF32) col);
     577                input->data.U16[row][col] = (psS16) psPolynomial2DEval(coeffs,
     578                                            (psF32) (row + input->row0), (psF32) (col + input->col0));
    568579            } else if (input->type.type == PS_TYPE_F32) {
    569                 input->data.F32[row][col] = psPolynomial2DEval(coeffs, (psF32) row, (psF32) col);
     580                input->data.F32[row][col] = psPolynomial2DEval(coeffs,
     581                                            (psF32) (row + input->row0), (psF32) (col + input->col0));
    570582            } else if (input->type.type == PS_TYPE_F64) {
    571                 input->data.F64[row][col] = (psF64) psPolynomial2DEval(coeffs, (psF32) row, (psF32) col);
     583                input->data.F64[row][col] = (psF64) psPolynomial2DEval(coeffs,
     584                                            (psF32) (row + input->row0), (psF32) (col + input->col0));
    572585            }
    573586        }
     
    617630    int y1 = 0;
    618631    psElemType type;
    619     if (mask == NULL) {
    620         psError(PS_ERR_BAD_PARAMETER_NULL, true,
    621                 PS_ERRORTEXT_psImage_IMAGE_NULL);
    622         return -1;
    623     }
    624632
    625633    // this is not a valid error: a psRegion with ranges outside the valid pixels
     
    641649
    642650    // rationalize the region
    643     region = psRegionForImage(mask, region);
    644 
    645     if (region.x0 == region.x1 || region.y0 == region.y1) {
    646         psError(PS_ERR_BAD_PARAMETER_SIZE, true,
    647                 "psRegion input contains 0 pixels\n");
     651
     652    /*
     653        if (mask == NULL) {
     654            psError(PS_ERR_BAD_PARAMETER_NULL, true,
     655                    PS_ERRORTEXT_psImage_IMAGE_NULL);
     656            return -1;
     657        }
     658        region = psRegionForImage(mask, region);
     659     
     660        if (region.x0 == region.x1 || region.y0 == region.y1) {
     661            psError(PS_ERR_BAD_PARAMETER_SIZE, true,
     662                    "psRegion input contains 0 pixels\n");
     663            return -1;
     664        }
     665    */
     666    PS_ASSERT_IMAGE_NON_NULL(mask, -1);
     667    PS_ASSERT_INT_NONNEGATIVE(mask->col0, -1);
     668    PS_ASSERT_INT_NONNEGATIVE(mask->row0, -1);
     669    PS_ASSERT_INT_POSITIVE(mask->numCols, -1);
     670    PS_ASSERT_INT_POSITIVE(mask->numRows, -1);
     671
     672    /*    x0 = (int)(roundf(region.x0));
     673        x1 = (int)(roundf(region.x1));
     674        y0 = (int)(roundf(region.y0));
     675        y1 = (int)(roundf(region.y1));
     676    */
     677    int col0 = (int)(roundf(region.x0));
     678    int col1 = (int)(roundf(region.x1));
     679    int row0 = (int)(roundf(region.y0));
     680    int row1 = (int)(roundf(region.y1));
     681    //If (0,0,0,0) specified, the whole image is to be used.
     682    if (col0 == 0 && col1 == 0 && row0 == 0 && row1 == 0) {
     683        col0 = mask->col0;
     684        col1 = mask->col0 + mask->numCols - 1;
     685        row0 = mask->row0;
     686        row1 = mask->row0 + mask->numRows - 1;
     687    }
     688
     689    //Make sure x0 of region is inside image.  If so, set col0 to corresponding index number.
     690    if (col0 >= mask->col0 && col0 < (mask->col0 + mask->numCols) ) {
     691        col0 -= mask->col0;
     692    } else {
     693        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     694                "Specified psRegion parameter, x0=%f, is out of range [%d,%d].\n",
     695                region.x0, mask->col0, mask->col0+mask->numCols-1);
    648696        return -1;
    649697    }
    650 
    651     x0 = (int)(roundf(region.x0));
    652     x1 = (int)(roundf(region.x1));
    653     y0 = (int)(roundf(region.y0));
    654     y1 = (int)(roundf(region.y1));
     698    //Make sure y0 of region is inside image.  If so, set row0 to corresponding index number.
     699    if (row0 >= mask->row0 && row0 < (mask->row0 + mask->numRows) ) {
     700        row0 -= mask->row0;
     701    } else {
     702        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     703                "Specified psRegion parameter, y0=%f, is out of range [%d,%d].\n",
     704                region.y0, mask->row0, mask->row0+mask->numRows-1);
     705        return -1;
     706    }
     707
     708    //Make sure x1 of region is valid.  If negative, index from tail (if valid).
     709    if (col1 < 0) {
     710        col1 += mask->numCols;
     711        if (col1 < 0) {
     712            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     713                    "Specified psRegion parameter, x1=%f=%d, is out of range [%d,%d].\n",
     714                    region.x1, col1+mask->col0, mask->col0, mask->col0+mask->numCols-1);
     715            return -1;
     716        }
     717    } else if (col1 >= mask->col0 && col1 < (mask->col0 + mask->numCols) ) {
     718        col1 -= mask->col0;
     719    } else {
     720        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     721                "Specified psRegion parameter, x1=%f=%d, is out of range [%d,%d].\n",
     722                region.x1, col1, mask->col0, mask->col0+mask->numCols-1);
     723        return -1;
     724    }
     725    //Make sure y1 of region is valid.  If negative, index from tail (if valid).
     726    if (row1 < 0) {
     727        row1 += mask->numRows;
     728        if (row1 < 0) {
     729            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     730                    "Specified psRegion parameter, y1=%f=%d, is out of range [%d,%d].\n",
     731                    region.y1, row1+mask->row0, mask->row0, mask->row0+mask->numRows-1);
     732            return -1;
     733        }
     734    } else if (row1 >= mask->row0 && row1 < (mask->row0 + mask->numRows) ) {
     735        row1 -= mask->row0;
     736    } else {
     737        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     738                "Specified psRegion parameter, y1=%f=%d, is out of range [%d,%d].\n",
     739                region.y1, row1, mask->row0, mask->row0+mask->numRows-1);
     740        return -1;
     741    }
     742    //Now make sure that the region makes sense.
     743    if (col0 > col1 || row0 > row1) {
     744        if (col0 > col1) {
     745            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     746                    "Invalid psRegion specified.  x0=%f=%d is greater than x1=%f=%d.\n",
     747                    region.x0, col0, region.x1, col1);
     748        } else {
     749            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     750                    "Invalid psRegion specified.  y0=%f=%d is greater than y1=%f=%d.\n",
     751                    region.y0, row0, region.y1, row1);
     752        }
     753        return -1;
     754    }/* else if (col0 == col1 && row0 == row1) {
     755            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     756                    "Invalid psRegion specified.  Region contains only 1 pixel.\n");
     757            return -1;
     758        }
     759    */
     760    x0 = col0;
     761    x1 = col1;
     762    y0 = row0;
     763    y1 = row1;
    655764
    656765    type = mask->type.type;
     
    664773    case PS_TYPE_U8:
    665774    case PS_TYPE_U16:
    666         for (long j = y0; j < y1; j++) {
    667             for (long i = x0; i < x1; i++) {
     775        for (long j = y0; j <= y1; j++) {
     776            for (long i = x0; i <= x1; i++) {
    668777                if (mask->data.PS_TYPE_MASK_DATA[j][i] & value) {
    669778                    Npixels ++;
  • trunk/psLib/src/mathtypes/psImage.c

    r6631 r6750  
    99 *  @author Ross Harman, MHPCC
    1010 *
    11  *  @version $Revision: 1.99 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2006-03-17 20:38:19 $
     11 *  @version $Revision: 1.100 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2006-04-01 02:43:57 $
    1313 *
    1414 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    173173{
    174174
    175     if (image == NULL) {
    176         return in;
     175    //    if (image == NULL) {
     176    //        return in;
     177    //    }
     178    PS_ASSERT_IMAGE_NON_NULL(image, in);
     179    //if the region is [0,0,0,0], the whole image (or subimage) is to be included.
     180    if (in.x0 == 0 && in.x1 == 0 && in.y0 == 0 && in.y1 == 0) {
     181        in.x0 = image->col0;
     182        in.x1 = image->col0 + image->numCols - 1;
     183        in.y0 = image->row0;
     184        in.y1 = image->row0 + image->numRows - 1;
     185        return (in);
    177186    }
    178187
     
    195204    // flip start and end if out of order
    196205    if (in.x0 > in.x1) {
     206        psError (PS_ERR_BAD_PARAMETER_VALUE, true,
     207                 "Invalid region in psRegionForImage.  x0 > x1.  Values have been swapped.\n");
    197208        PS_SWAP (in.x0, in.x1);
    198209    }
    199210    if (in.y0 > in.y1) {
     211        psError (PS_ERR_BAD_PARAMETER_VALUE, true,
     212                 "Invalid region in psRegionForImage.  y0 > y1.  Values have been swapped.\n");
    200213        PS_SWAP (in.y0, in.y1);
    201214    }
     
    717730{
    718731
    719     if (input == NULL) {
    720         psError(PS_ERR_BAD_PARAMETER_NULL,true,
    721                 PS_ERRORTEXT_psImage_IMAGE_NULL);
    722         return unexposedValue;
     732    /*    if (input == NULL) {
     733            psError(PS_ERR_BAD_PARAMETER_NULL,true,
     734                    PS_ERRORTEXT_psImage_IMAGE_NULL);
     735            return unexposedValue;
     736        }
     737    */
     738    PS_ASSERT_IMAGE_NON_NULL(input, unexposedValue);
     739    if (input->row0 != 0 || input->col0 != 0) {
     740        x += input->col0;
     741        y += input->row0;
    723742    }
    724743
  • trunk/psLib/src/types/psPixels.c

    r6500 r6750  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2006-02-28 02:53:03 $
     9 *  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2006-04-01 02:43:57 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    168168    float y1 = region.y1;
    169169
     170    if ( (x0 < 0 || x1 < 0) || (y0 < 0 || y1 < 0) ) {
     171        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     172                PS_ERRORTEXT_psPixels_REGION_INVALID,
     173                (int)y0,(int)y1,(int)x0,(int)x1);
     174        psFree(out);
     175        return NULL;
     176    }
     177
    170178    // determine the output image size
    171179    int numRows = y1-y0;
    172180    int numCols = x1-x0;
     181    numRows += 1;
     182    numCols += 1;
    173183    if (numRows < 1 || numCols < 1) {
    174184        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     
    205215        float y = data[p].y;
    206216        // pixel in region?
    207         if (x >= x0 && x < x1 && y >= y0 && y < y1) {
     217        if (x >= x0 && x <= x1 && y >= y0 && y <= y1) {
    208218            outData[(int)(y-y0)][(int)(x-x0)] |= maskVal;
    209219        }
  • trunk/psLib/test/imageops/tst_psImagePixelExtract.c

    r6484 r6750  
    66*  @author Robert DeSonia, MHPCC
    77*
    8 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    9 *  @date $Date: 2006-02-24 23:43:15 $
     8*  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     9*  @date $Date: 2006-04-01 02:43:57 $
    1010*
    1111*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2121static psS32 testImageCut(void);
    2222static psS32 testImageRadialCut(void);
     23static psS32 testImageRowColError(void);
    2324static psS32 testImageRowColF32(void);
    2425static psS32 testImageRowColF64(void);
     
    3738                              {testImageSlice, 552, "psImageSlice", 0, false},
    3839                              {testImageCut, 555, "psImageCut", 0, false},
    39                               {testImageRadialCut, 557, "psImageRadialCut", 0, false},
     40                              {testImageRadialCut, 556, "psImageRadialCut", 0, false},
     41                              {testImageRowColError, 557, "testImageRowColError", 0, false},
    4042                              {testImageRowColF32, 558, "psImageRowColF32", 0, false},
    4143                              {testImageRowColF64, 559, "psImageRowColF64", 0, false},
     
    765767}
    766768
    767 psS32 testImageRowColF64(void)
    768 {
    769     psVector *rowcol = NULL;
    770     psVector *empty = NULL;
     769psS32 testImageRowColError(void)
     770{
    771771    psImage *image = NULL;
    772     psImage *emptyImage = NULL;
     772    psVector *out = NULL;
     773    int num = 0;
     774
     775    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message");
     776    out = psImageRow(NULL, image, num);
     777    if (out != NULL) {
     778        return 1;
     779    }
     780
    773781
    774782    image = psImageAlloc(3, 3, PS_TYPE_F64);
    775     rowcol = psVectorAlloc(3, PS_TYPE_F64);
    776 
     783    *(psS32*)&(image->row0) = 5;
     784    *(psS32*)&(image->col0) = 10;
    777785    image->data.F64[0][0] = 666.666;
    778786    image->data.F64[1][0] = 66.6;
     
    785793    image->data.F64[2][2] = 66.66;
    786794
     795
     796
     797    psFree(out);
     798    psFree(image);
     799    return 0;
     800}
     801
     802psS32 testImageRowColF64(void)
     803{
     804    psVector *rowcol = NULL;
     805    psVector *empty = NULL;
     806    psImage *image = NULL;
     807    psImage *emptyImage = NULL;
     808
     809    image = psImageAlloc(3, 3, PS_TYPE_F64);
     810    rowcol = psVectorAlloc(3, PS_TYPE_F64);
     811
     812    image->data.F64[0][0] = 666.666;
     813    image->data.F64[1][0] = 66.6;
     814    image->data.F64[2][0] = 6.66;
     815    image->data.F64[0][1] = 6.6;
     816    image->data.F64[1][1] = 6.666;
     817    image->data.F64[2][1] = 66.666;
     818    image->data.F64[0][2] = 666.6;
     819    image->data.F64[1][2] = 666.66;
     820    image->data.F64[2][2] = 66.66;
     821
    787822    //Test for error with NULL image
    788823    empty = psImageCol(empty, emptyImage, 0);
  • trunk/psLib/test/imageops/tst_psImageStats.c

    r6306 r6750  
    543543    psRegion reg;
    544544    reg.x0 = 0;
    545     reg.x1 = 1;
     545    reg.x1 = 0;
    546546    reg.y0 = 0;
    547     reg.y1 = 5;
     547    reg.y1 = 4;
     548
     549    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message");
    548550    numPix = psImageCountPixelMask(in, reg, 1);
    549 
    550551    if (numPix != -1) {
    551552        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     
    587588    if (numPix2 != 2) {
    588589        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    589                 "psImageCountPixelMask returned incorrect pixel count %ld\n", numPix2);
     590                "psImageCountPixelMask returned incorrect pixel count %ld (!=2)\n", numPix2);
    590591        return 4;
    591592    }
     
    613614    reg.x1 = 1;
    614615    reg.y1 = 1;
     616    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message");
    615617    numPix2 = psImageCountPixelMask(in2, reg, 1);
    616618    if (numPix2 != -1) {
  • trunk/psLib/test/imageops/verified/tst_psImageInterpolate.stderr

    r4547 r6750  
    1717    Following should generate an error message
    1818<DATE><TIME>|<HOST>|E|psImagePixelInterpolate (FILE:LINENO)
    19     Can not operate on a NULL psImage.
     19    Unallowable operation: psImage input or its data is NULL.
    2020<DATE><TIME>|<HOST>|I|testInterpolateError
    2121    Following should generate an error message
  • trunk/psLib/test/imageops/verified/tst_psImagePixelExtract.stderr

    r6631 r6750  
    2424    Following should be an error.
    2525<DATE><TIME>|<HOST>|E|psImageSlice (FILE:LINENO)
    26     Specified psRegion parameter, x0=301.000000, is out of range [0,300].
    27 <DATE><TIME>|<HOST>|I|testImageSlice
    28     Following should be an error.
    29 <DATE><TIME>|<HOST>|E|psImageSlice (FILE:LINENO)
    30     Specified psRegion parameter, y0=201.000000, is out of range [0,200].
    31 <DATE><TIME>|<HOST>|I|testImageSlice
    32     Following should be an error.
    33 <DATE><TIME>|<HOST>|E|psImageSlice (FILE:LINENO)
    34     Specified psRegion parameter, x1=301.000000=301, is out of range [0,300].
    35 <DATE><TIME>|<HOST>|I|testImageSlice
    36     Following should be an error.
    37 <DATE><TIME>|<HOST>|E|psImageSlice (FILE:LINENO)
    38     Specified psRegion parameter, y1=201.000000=201, is out of range [0,200].
     26    Specified psRegion parameter, x0=301.000000, is out of range [0,299].
     27<DATE><TIME>|<HOST>|I|testImageSlice
     28    Following should be an error.
     29<DATE><TIME>|<HOST>|E|psImageSlice (FILE:LINENO)
     30    Specified psRegion parameter, y0=201.000000, is out of range [0,199].
     31<DATE><TIME>|<HOST>|I|testImageSlice
     32    Following should be an error.
     33<DATE><TIME>|<HOST>|E|psImageSlice (FILE:LINENO)
     34    Specified psRegion parameter, x1=301.000000=301, is out of range [0,299].
     35<DATE><TIME>|<HOST>|I|testImageSlice
     36    Following should be an error.
     37<DATE><TIME>|<HOST>|E|psImageSlice (FILE:LINENO)
     38    Specified psRegion parameter, y1=201.000000=201, is out of range [0,199].
    3939<DATE><TIME>|<HOST>|I|testImageSlice
    4040    Following should be an error.
     
    6161    The following should be an error.
    6262<DATE><TIME>|<HOST>|E|psImageCut (FILE:LINENO)
    63     Specified line, (-1.000000,10.000000)->(240.000000,180.000000), does not entirely lie in psImage's boundaries, [0:299,0:199].
    64 <DATE><TIME>|<HOST>|I|testImageCut
    65     The following should be an error.
    66 <DATE><TIME>|<HOST>|E|psImageCut (FILE:LINENO)
    67     Specified line, (300.000000,10.000000)->(240.000000,180.000000), does not entirely lie in psImage's boundaries, [0:299,0:199].
    68 <DATE><TIME>|<HOST>|I|testImageCut
    69     The following should be an error.
    70 <DATE><TIME>|<HOST>|E|psImageCut (FILE:LINENO)
    71     Specified line, (20.000000,10.000000)->(-1.000000,180.000000), does not entirely lie in psImage's boundaries, [0:299,0:199].
    72 <DATE><TIME>|<HOST>|I|testImageCut
    73     The following should be an error.
    74 <DATE><TIME>|<HOST>|E|psImageCut (FILE:LINENO)
    75     Specified line, (20.000000,10.000000)->(300.000000,180.000000), does not entirely lie in psImage's boundaries, [0:299,0:199].
    76 <DATE><TIME>|<HOST>|I|testImageCut
    77     The following should be an error.
    78 <DATE><TIME>|<HOST>|E|psImageCut (FILE:LINENO)
    79     Specified line, (20.000000,-1.000000)->(240.000000,180.000000), does not entirely lie in psImage's boundaries, [0:299,0:199].
    80 <DATE><TIME>|<HOST>|I|testImageCut
    81     The following should be an error.
    82 <DATE><TIME>|<HOST>|E|psImageCut (FILE:LINENO)
    83     Specified line, (20.000000,200.000000)->(240.000000,180.000000), does not entirely lie in psImage's boundaries, [0:299,0:199].
    84 <DATE><TIME>|<HOST>|I|testImageCut
    85     The following should be an error.
    86 <DATE><TIME>|<HOST>|E|psImageCut (FILE:LINENO)
    87     Specified line, (20.000000,10.000000)->(240.000000,-1.000000), does not entirely lie in psImage's boundaries, [0:299,0:199].
    88 <DATE><TIME>|<HOST>|I|testImageCut
    89     The following should be an error.
    90 <DATE><TIME>|<HOST>|E|psImageCut (FILE:LINENO)
    91     Specified line, (20.000000,10.000000)->(240.000000,200.000000), does not entirely lie in psImage's boundaries, [0:299,0:199].
     63    Specified psRegion parameter, x0=-1.000000, is out of range [0,300].
     64<DATE><TIME>|<HOST>|I|testImageCut
     65    The following should be an error.
     66<DATE><TIME>|<HOST>|E|psImageCut (FILE:LINENO)
     67    Specified psRegion parameter, x0=300.000000, is out of range [0,300].
     68<DATE><TIME>|<HOST>|I|testImageCut
     69    The following should be an error.
     70<DATE><TIME>|<HOST>|I|testImageCut
     71    The following should be an error.
     72<DATE><TIME>|<HOST>|I|testImageCut
     73    The following should be an error.
     74<DATE><TIME>|<HOST>|E|psImageCut (FILE:LINENO)
     75    Specified psRegion parameter, y0=-1.000000, is out of range [0,200].
     76<DATE><TIME>|<HOST>|I|testImageCut
     77    The following should be an error.
     78<DATE><TIME>|<HOST>|E|psImageCut (FILE:LINENO)
     79    Specified psRegion parameter, y0=200.000000, is out of range [0,200].
     80<DATE><TIME>|<HOST>|I|testImageCut
     81    The following should be an error.
     82<DATE><TIME>|<HOST>|I|testImageCut
     83    The following should be an error.
    9284<DATE><TIME>|<HOST>|I|testImageCut
    9385    Following should be an error (NULL image).
     
    148140/***************************** TESTPOINT ******************************************\
    149141*             TestFile: tst_psImagePixelExtract.c                                  *
     142*            TestPoint: psImage{testImageRowColError}                              *
     143*             TestType: Positive                                                   *
     144\**********************************************************************************/
     145
     146<DATE><TIME>|<HOST>|I|testImageRowColError
     147    Following should generate error message
     148<DATE><TIME>|<HOST>|E|psImageRow (FILE:LINENO)
     149    Can not operate on a NULL psImage.
     150
     151---> TESTPOINT PASSED (psImage{testImageRowColError} | tst_psImagePixelExtract.c)
     152
     153/***************************** TESTPOINT ******************************************\
     154*             TestFile: tst_psImagePixelExtract.c                                  *
    150155*            TestPoint: psImage{psImageRowColF32}                                  *
    151156*             TestType: Positive                                                   *
  • trunk/psLib/test/imageops/verified/tst_psImageStats.stderr

    r5839 r6750  
    622622\**********************************************************************************/
    623623
     624<HOST>|I|testImageCountPixel
     625    Following should generate error message
    624626<HOST>|E|psImageCountPixelMask (FILE:LINENO)
    625     Can not operate on a NULL psImage.
     627    Unallowable operation: psImage mask or its data is NULL.
     628<HOST>|I|testImageCountPixel
     629    Following should generate error message
    626630<HOST>|E|psImageCountPixelMask (FILE:LINENO)
    627     psRegion input contains 0 pixels
     631    Specified psRegion parameter, x0=1.000000, is out of range [0,0].
    628632
    629633---> TESTPOINT PASSED (psImage{psImageCountPixel} | tst_psImageStats.c)
  • trunk/psLib/test/types/tst_psPixels.c

    r6500 r6750  
    55 *  @author Robert DeSonia, MHPCC
    66 *
    7  *  @version $Revision: 1.4 $
     7 *  @version $Revision: 1.5 $
    88 *           $Name: not supported by cvs2svn $
    9  *  @date $Date: 2006-02-28 02:53:03 $
     9 *  @date $Date: 2006-04-01 02:43:57 $
    1010 *
    1111 *  Copyright 2005 Maui High Performance Computing Center, University of Hawaii
     
    378378        psError(PS_ERR_UNKNOWN,true,"Did not expect non-NULL for invalid range");
    379379        return 21;
     380    }
     381    // Test for invalid region
     382    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error for invalid range");
     383    mask = psPixelsToMask(mask,pixels,psRegionSet(0,-1,0,10),1);
     384    if(mask != NULL) {
     385        psError(PS_ERR_UNKNOWN,true,"Did not expect non-NULL for invalid range");
     386        return 22;
    380387    }
    381388
  • trunk/psLib/test/types/verified/tst_psPixels.stderr

    r6500 r6750  
    4444<DATE><TIME>|<HOST>|E|psPixelsToMask (FILE:LINENO)
    4545    Specified psRegion, [10:0,10:0], does not specify a valid region.
     46<DATE><TIME>|<HOST>|I|testPixelsToMask
     47    Following should generate an error for invalid range
     48<DATE><TIME>|<HOST>|E|psPixelsToMask (FILE:LINENO)
     49    Specified psRegion, [0:10,0:-1], does not specify a valid region.
    4650
    4751---> TESTPOINT PASSED (psPixels{psPixelsToMask} | tst_psPixels.c)
Note: See TracChangeset for help on using the changeset viewer.