IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 16, 2008, 3:38:20 PM (18 years ago)
Author:
Paul Price
Message:

Adding separable version of psImageConvolveMask. Mask convolution should go a lot faster than it currently is, and hopefully this will do it.

File:
1 edited

Legend:

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

    r17365 r17726  
    77/// @author Eugene Magnier, IfA
    88///
    9 /// @version $Revision: 1.66 $ $Name: not supported by cvs2svn $
    10 /// @date $Date: 2008-04-07 20:30:38 $
     9/// @version $Revision: 1.67 $ $Name: not supported by cvs2svn $
     10/// @date $Date: 2008-05-17 01:38:20 $
    1111///
    1212/// Copyright 2004-2007 Institute for Astronomy, University of Hawaii
     
    755755    return true;
    756756}
     757
     758
     759
     760
     761psImage *psImageConvolveMask(psImage *out, const psImage *mask, psMaskType maskVal,
     762                             psMaskType setVal, int xMin, int xMax, int yMin, int yMax)
     763{
     764    PS_ASSERT_IMAGE_NON_NULL(mask, NULL);
     765    PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_MASK, NULL);
     766    if (out) {
     767        PS_ASSERT_IMAGE_NON_NULL(out, NULL);
     768        PS_ASSERT_IMAGE_TYPE(out, PS_TYPE_MASK, NULL);
     769        PS_ASSERT_IMAGES_SIZE_EQUAL(out, mask, NULL);
     770        if (out == mask && ((maskVal & setVal) || !setVal)) {
     771            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     772                    "Can't convolve mask in-place if values to set contains values to convolve.");
     773            return NULL;
     774        }
     775    }
     776
     777    if (yMin > yMax) {
     778        psWarning("Specified yMin, %d, was greater than yMax, %d.  Values swapped.",
     779                 yMin, yMax);
     780
     781        int temp = yMin;
     782        yMin = yMax;
     783        yMax = temp;
     784    }
     785    if (xMin > xMax) {
     786        psWarning("Specified xMin, %d, was greater than xMax, %d.  Values swapped.",
     787                 xMin, xMax);
     788
     789        int temp = xMin;
     790        xMin = xMax;
     791        xMax = temp;
     792    }
     793
     794    int numRows = mask->numRows;        // Number of rows
     795    int numCols = mask->numCols;        // Number of columns
     796
     797    if (!out) {
     798        // Propagate the non-masked values
     799        out = (psImage*)psBinaryOp(NULL, (const psPtr)mask, "&", psScalarAlloc(~maskVal, PS_TYPE_MASK));
     800    }
     801
     802    if (!setVal) {
     803        setVal = maskVal;
     804    }
     805
     806    // Dereference mask images
     807    psMaskType **maskData = mask->data.PS_TYPE_MASK_DATA;
     808    psMaskType **outData = out->data.PS_TYPE_MASK_DATA;
     809
     810    // Since we're just masking everything inside a square, it's separable
     811    for (int y = 0; y < numRows; y++) {
     812        int min = 0, max = 0;           // Minimum and maximum points to mask
     813        bool masking = false;           // Currently masking?
     814        for (int x = 0; x < numCols; x++) {
     815            if (maskData[y][x] & maskVal) {
     816                if (!masking) {
     817                    masking = true;
     818                    min = x + xMin;
     819                    max = x + xMax;
     820                } else {
     821                    max++;
     822                }
     823            } else if (masking) {
     824                // Do the masking
     825                masking = false;
     826                min = PS_MAX(0, min);
     827                max = PS_MIN(numCols - 1, max);
     828                for (int i = min; i < max; i++) {
     829                    outData[y][i] |= setVal;
     830                }
     831            }
     832        }
     833    }
     834    for (int x = 0; x < numCols; x++) {
     835        int min = 0, max = 0;           // Minimum and maximum points to mask
     836        bool masking = false;           // Currently masking?
     837        for (int y = 0; y < numRows; y++) {
     838            if (maskData[y][x] & maskVal) {
     839                if (!masking) {
     840                    masking = true;
     841                    min = y + yMin;
     842                    max = y + yMax;
     843                } else {
     844                    max++;
     845                }
     846            } else if (masking) {
     847                // Do the masking
     848                masking = false;
     849                min = PS_MAX(0, min);
     850                max = PS_MIN(numRows - 1, max);
     851                for (int i = min; i < max; i++) {
     852                    outData[i][x] |= setVal;
     853                }
     854            }
     855        }
     856    }
     857
     858    return out;
     859}
Note: See TracChangeset for help on using the changeset viewer.