IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 16910


Ignore:
Timestamp:
Mar 10, 2008, 2:41:30 PM (18 years ago)
Author:
Paul Price
Message:

Adding psImageShiftMask --- allows mask to follow the image when shifting. Used in pmSourcePhotometry.c

Location:
trunk/psLib/src/imageops
Files:
2 edited

Legend:

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

    r12815 r16910  
    1010 *  @author Ross Harman, MHPCC
    1111 *
    12  *  @version $Revision: 1.41 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2007-04-12 18:55:10 $
     12 *  @version $Revision: 1.42 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2008-03-11 00:41:30 $
    1414 *
    1515 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    659659}
    660660
     661bool psImageShiftMask(psImage **out, psImage **outMask, const psImage* in, const psImage *inMask,
     662                      psMaskType maskVal, float dx, float dy, double exposed, psMaskType blank,
     663                      psImageInterpolateMode mode)
     664{
     665    PS_ASSERT(out, false);
     666    PS_ASSERT_IMAGE_NON_NULL(in, false);
     667    if (inMask) {
     668        PS_ASSERT_IMAGE_NON_NULL(inMask, false);
     669        PS_ASSERT_IMAGES_SIZE_EQUAL(in, inMask, false);
     670        PS_ASSERT_IMAGE_TYPE(inMask, PS_TYPE_MASK, false);
     671    }
     672
     673    int numRows = in->numRows, numCols = in->numCols; // Size of image
     674    psElemType type = in->type.type;    // Type of image
     675
     676    *out = psImageRecycle(*out, numCols, numRows, type);
     677    if (outMask) {
     678        *outMask = psImageRecycle(*outMask, numCols, numRows, PS_TYPE_MASK);
     679    }
     680
     681    psImageInterpolateOptions *interp = psImageInterpolateOptionsAlloc(PS_INTERPOLATE_BICUBE, in, NULL,
     682                                                                       inMask, maskVal, exposed, NAN, blank,
     683                                                                       blank, 0.0);
     684
     685    #define PSIMAGE_SHIFT_MASK_CASE(TYPE) \
     686case PS_TYPE_##TYPE: \
     687    if (exposed < PS_MIN_##TYPE || \
     688            exposed > PS_MAX_##TYPE || \
     689            exposed < PS_MIN_##TYPE || \
     690            exposed > PS_MAX_##TYPE) { \
     691        psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
     692                _("Specified exposed value, %g%+gi, is not the the range of input image's " \
     693                  "valid pixel values (%s), i.e. [%g:%g]."), \
     694                exposed, exposed, \
     695                PS_TYPE_##TYPE##_NAME,  \
     696                (double)PS_MIN_##TYPE,(double)PS_MAX_##TYPE); \
     697        psFree(out); \
     698        out = NULL; \
     699        break; \
     700    } \
     701    /* note: output(i,j) = input(i+0.5-dx,j+0.5-dy) */ \
     702    /* positive dx,dy moves pixel i-dx,j-dy to i,y */ \
     703    /* also: pixel center is 0.5,0.5 */ \
     704    for (int row = 0; row < numRows; row++) { \
     705        ps##TYPE* outRow = (*out)->data.TYPE[row]; \
     706        psMaskType *outMaskRow = (outMask ? (*outMask)->data.PS_TYPE_MASK_DATA[row] : NULL); \
     707        float y = row + 0.5 - dy; \
     708        for (int col = 0; col < numCols; col++) { \
     709            float x = col + 0.5 - dx; \
     710            double value; \
     711            psMaskType valueMask; \
     712            if (!psImageInterpolate(&value, NULL, &valueMask, x, y, interp)) { \
     713                psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image."); \
     714                psFree(interp); \
     715                return false; \
     716            } \
     717            outRow[col] = value; \
     718            if (outMask) { \
     719                outMaskRow[col] = valueMask; \
     720            } \
     721        } \
     722    } \
     723    break;
     724
     725    switch (type) {
     726        PSIMAGE_SHIFT_MASK_CASE(U8);
     727        PSIMAGE_SHIFT_MASK_CASE(U16);
     728        PSIMAGE_SHIFT_MASK_CASE(U32);
     729        PSIMAGE_SHIFT_MASK_CASE(U64);
     730        PSIMAGE_SHIFT_MASK_CASE(S8);
     731        PSIMAGE_SHIFT_MASK_CASE(S16);
     732        PSIMAGE_SHIFT_MASK_CASE(S32);
     733        PSIMAGE_SHIFT_MASK_CASE(S64);
     734        PSIMAGE_SHIFT_MASK_CASE(F32);
     735        PSIMAGE_SHIFT_MASK_CASE(F64);
     736      default: {
     737          char* typeStr;
     738          PS_TYPE_NAME(typeStr,type);
     739          psError(PS_ERR_BAD_PARAMETER_TYPE, true, _("Specified psImage type, %s, is not supported."),
     740                  typeStr);
     741          psFree(interp);
     742          return false;
     743        }
     744    }
     745
     746    psFree(interp);
     747    return true;
     748}
     749
    661750psImage* psImageTransform(psImage *output,
    662751                          psPixels** blankPixels,
     
    745834        // create the output image.
    746835        output = psImageRecycle(output, numCols, numRows, input->type.type);
    747         P_PSIMAGE_SET_COL0(output, region.x0);
    748         P_PSIMAGE_SET_ROW0(output, region.y0);
     836        P_PSIMAGE_SET_COL0(output, region.x0);
     837        P_PSIMAGE_SET_ROW0(output, region.y0);
    749838    } else { // size of output is determined by output parameter
    750839        numRows = output->numRows;
  • trunk/psLib/src/imageops/psImageGeomManip.h

    r12745 r16910  
    66 * @author Robert DeSonia, MHPCC
    77 *
    8  * @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
    9  * @date $Date: 2007-04-05 00:17:29 $
     8 * @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
     9 * @date $Date: 2008-03-11 00:41:30 $
    1010 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
    1111 */
     
    9898);
    9999
     100/// Apply a translation to an image
     101///
     102/// This function is very much like psImageShift, except that it applies the same shifts to the mask
     103bool psImageShiftMask(
     104    psImage **out,                      ///< Output shifted image
     105    psImage **outMask,                  ///< Output shifted mask, or NULL
     106    const psImage* in,                  ///< Input image
     107    const psImage *inMask,              ///< Input mask, or NULL
     108    psMaskType maskVal,                 ///< Value to mask
     109    float dx, float dy,                 ///< Shift to apply
     110    double exposed,                     ///< Value to give exposed pixels
     111    psMaskType blank,                   ///< Mask value for exposed pixels
     112    psImageInterpolateMode mode         ///< Interpolation mode
     113    );
     114
    100115/** Roll image by an integer number of pixels in either direction.
    101116 *
Note: See TracChangeset for help on using the changeset viewer.