IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 ++;
Note: See TracChangeset for help on using the changeset viewer.