IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 18, 2010, 5:06:01 PM (16 years ago)
Author:
watersc1
Message:

Almost working version of the mask-stats/software revision code.

Almost.

Location:
branches/czw_branch/20100427
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20100427

  • branches/czw_branch/20100427/psLib/src/imageops/psImageConvolve.c

    r26892 r28017  
    3737
    3838
     39
    3940static bool threaded = false;           // Run image convolution threaded?
    40 
    41 
     41static pthread_mutex_t threadMutex = PTHREAD_MUTEX_INITIALIZER;
    4242
    4343
    … …  
    871871            psFree(job);
    872872        }
     873        if (!psThreadPoolWait(true)) {
     874            psError(PS_ERR_UNKNOWN, false, "Error waiting for threads.");
     875            psFree(gaussNorm);
     876            psFree(out);
     877            return NULL;
     878        }
    873879    } else if (!imageSmoothMaskPixels(out, image, mask, maskVal, x, y,
    874880                                      gaussNorm, minGauss, size, 0, num)) {
    875881        psError(PS_ERR_UNKNOWN, false, "Unable to smooth pixels.");
    876         psFree(gaussNorm);
    877         psFree(out);
    878         return NULL;
    879     }
    880 
    881     if (threaded && !psThreadPoolWait(true)) {
    882         psError(PS_ERR_UNKNOWN, false, "Error waiting for threads.");
    883882        psFree(gaussNorm);
    884883        psFree(out);
    … …  
    11921191          psImage *calcMask = psImageAlloc(numRows, numCols, PS_TYPE_IMAGE_MASK); /* Mask for calculation image; BW */
    11931192
    1194           /** Smooth in X direction **/
    1195           for (int rowStart = 0; rowStart < numRows; rowStart+=scanRows) {
    1196               int rowStop = PS_MIN (rowStart + scanRows, numRows);
    1197 
    1198               // allocate a job, construct the arguments for this job
    1199               psThreadJob *job = psThreadJobAlloc("PSLIB_IMAGE_SMOOTHMASK_SCANROWS");
    1200               psArrayAdd(job->args, 1, calculation);
    1201               psArrayAdd(job->args, 1, calcMask);
    1202               psArrayAdd(job->args, 1, (psImage *) image); // cast away const
    1203               psArrayAdd(job->args, 1, (psImage *) mask); // cast away const
    1204               PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
    1205               psArrayAdd(job->args, 1, gaussNorm);
    1206               PS_ARRAY_ADD_SCALAR(job->args, minGauss, PS_TYPE_F32);
    1207               PS_ARRAY_ADD_SCALAR(job->args, size,     PS_TYPE_S32);
    1208               PS_ARRAY_ADD_SCALAR(job->args, rowStart, PS_TYPE_S32);
    1209               PS_ARRAY_ADD_SCALAR(job->args, rowStop,  PS_TYPE_S32);
    1210               // -> psImageSmoothMask_ScanRows_F32 (calculation, calcMask, image, mask, maskVal, gauss, minGauss, size, rowStart, rowStop);
    1211 
    1212               // if threading is not active, we simply run the job and return
    1213               if (!psThreadJobAddPending(job)) {
     1193          if (threaded) {
     1194              /** Smooth in X direction **/
     1195              for (int rowStart = 0; rowStart < numRows; rowStart+=scanRows) {
     1196                  int rowStop = PS_MIN (rowStart + scanRows, numRows);
     1197
     1198                  // allocate a job, construct the arguments for this job
     1199                  psThreadJob *job = psThreadJobAlloc("PSLIB_IMAGE_SMOOTHMASK_SCANROWS");
     1200                  psArrayAdd(job->args, 1, calculation);
     1201                  psArrayAdd(job->args, 1, calcMask);
     1202                  psArrayAdd(job->args, 1, (psImage *) image); // cast away const
     1203                  psArrayAdd(job->args, 1, (psImage *) mask); // cast away const
     1204                  PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
     1205                  psArrayAdd(job->args, 1, gaussNorm);
     1206                  PS_ARRAY_ADD_SCALAR(job->args, minGauss, PS_TYPE_F32);
     1207                  PS_ARRAY_ADD_SCALAR(job->args, size,     PS_TYPE_S32);
     1208                  PS_ARRAY_ADD_SCALAR(job->args, rowStart, PS_TYPE_S32);
     1209                  PS_ARRAY_ADD_SCALAR(job->args, rowStop,  PS_TYPE_S32);
     1210                  // -> psImageSmoothMask_ScanRows_F32 (calculation, calcMask, image, mask, maskVal, gauss, minGauss, size, rowStart, rowStop);
     1211
     1212                  // if threading is not active, we simply run the job and return
     1213                  if (!psThreadJobAddPending(job)) {
     1214                      psError(PS_ERR_UNKNOWN, false, "Unable to smooth image");
     1215                      psFree(job);
     1216                      psFree(calculation);
     1217                      psFree(calcMask);
     1218                      psFree(gaussNorm);
     1219                      return false;
     1220                  }
     1221                  psFree(job);
     1222              }
     1223              // wait here for the threaded jobs to finish (NOP if threading is not active)
     1224              if (!psThreadPoolWait(true)) {
    12141225                  psError(PS_ERR_UNKNOWN, false, "Unable to smooth image");
    1215                   psFree(job);
     1226                  psFree(calculation);
     1227                  psFree(calcMask);
     1228                  psFree(gaussNorm);
    12161229                  return false;
    12171230              }
    1218               psFree(job);
    1219 
    1220           }
    1221 
    1222           // wait here for the threaded jobs to finish (NOP if threading is not active)
    1223           if (!psThreadPoolWait(true)) {
     1231          } else if (!psImageSmoothMask_ScanRows_F32(calculation, calcMask, image, mask, maskVal,
     1232                                                     gaussNorm, minGauss, size, 0, numRows)) {
    12241233              psError(PS_ERR_UNKNOWN, false, "Unable to smooth image");
     1234              psFree(calculation);
     1235              psFree(calcMask);
     1236              psFree(gaussNorm);
    12251237              return false;
    12261238          }
    … …  
    12291241
    12301242          /** Smooth in Y direction  **/
    1231           for (int colStart = 0; colStart < numCols; colStart+=scanCols) {
    1232               int colStop = PS_MIN (colStart + scanCols, numCols);
    1233 
    1234               // allocate a job, construct the arguments for this job
    1235               psThreadJob *job = psThreadJobAlloc("PSLIB_IMAGE_SMOOTHMASK_SCANCOLS");
    1236               psArrayAdd(job->args, 1, output);
    1237               psArrayAdd(job->args, 1, calculation);
    1238               psArrayAdd(job->args, 1, calcMask);
    1239               PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
    1240               psArrayAdd(job->args, 1, gaussNorm);
    1241               PS_ARRAY_ADD_SCALAR(job->args, minGauss, PS_TYPE_F32);
    1242               PS_ARRAY_ADD_SCALAR(job->args, size,     PS_TYPE_S32);
    1243               PS_ARRAY_ADD_SCALAR(job->args, colStart, PS_TYPE_S32);
    1244               PS_ARRAY_ADD_SCALAR(job->args, colStop,  PS_TYPE_S32);
    1245               // -> psImageSmoothMask_ScanCols_F32 (output, calculation, calcMask, maskVal, gauss, minGauss, size, colStart, colStop);
    1246 
    1247               // if threading is not active, we simply run the job and return
    1248               if (!psThreadJobAddPending(job)) {
     1243          if (threaded) {
     1244              for (int colStart = 0; colStart < numCols; colStart+=scanCols) {
     1245                  int colStop = PS_MIN (colStart + scanCols, numCols);
     1246
     1247                  // allocate a job, construct the arguments for this job
     1248                  psThreadJob *job = psThreadJobAlloc("PSLIB_IMAGE_SMOOTHMASK_SCANCOLS");
     1249                  psArrayAdd(job->args, 1, output);
     1250                  psArrayAdd(job->args, 1, calculation);
     1251                  psArrayAdd(job->args, 1, calcMask);
     1252                  PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
     1253                  psArrayAdd(job->args, 1, gaussNorm);
     1254                  PS_ARRAY_ADD_SCALAR(job->args, minGauss, PS_TYPE_F32);
     1255                  PS_ARRAY_ADD_SCALAR(job->args, size,     PS_TYPE_S32);
     1256                  PS_ARRAY_ADD_SCALAR(job->args, colStart, PS_TYPE_S32);
     1257                  PS_ARRAY_ADD_SCALAR(job->args, colStop,  PS_TYPE_S32);
     1258                  // -> psImageSmoothMask_ScanCols_F32 (output, calculation, calcMask, maskVal, gauss, minGauss, size, colStart, colStop);
     1259
     1260                  // if threading is not active, we simply run the job and return
     1261                  if (!psThreadJobAddPending(job)) {
     1262                      psError(PS_ERR_UNKNOWN, false, "Unable to smooth image");
     1263                      psFree(job);
     1264                      psFree(calculation);
     1265                      psFree(calcMask);
     1266                      psFree(gaussNorm);
     1267                      return false;
     1268                  }
     1269                  psFree(job);
     1270              }
     1271
     1272              // wait here for the threaded jobs to finish (NOP if threading is not active)
     1273              if (!psThreadPoolWait(true)) {
    12491274                  psError(PS_ERR_UNKNOWN, false, "Unable to smooth image");
    1250                   psFree(job);
     1275                  psFree(calculation);
     1276                  psFree(calcMask);
     1277                  psFree(gaussNorm);
    12511278                  return false;
    12521279              }
    1253               psFree(job);
    1254           }
    1255 
    1256           // wait here for the threaded jobs to finish (NOP if threading is not active)
    1257           if (!psThreadPoolWait(true)) {
     1280          } else if (!psImageSmoothMask_ScanCols_F32(output, calculation, calcMask, maskVal,
     1281                                                     gaussNorm, minGauss, size, 0, numCols)) {
    12581282              psError(PS_ERR_UNKNOWN, false, "Unable to smooth image");
     1283              psFree(calculation);
     1284              psFree(calcMask);
     1285              psFree(gaussNorm);
    12591286              return false;
    12601287          }
     1288
    12611289          psFree(calculation);
    12621290          psFree(calcMask);
    … …  
    15591587            psFree(job);
    15601588        }
     1589        if (!psThreadPoolWait(true)) {
     1590            psError(PS_ERR_UNKNOWN, false, "Error waiting for threads.");
     1591            psFree(conv);
     1592            psFree(out);
     1593            return NULL;
     1594        }
    15611595    } else if (!imageConvolveMaskColumns(conv, mask, 0, numRows, maskVal, xMin, xMax)) {
    15621596        psError(PS_ERR_UNKNOWN, false, "Unable to convolve mask columns.");
    1563         psFree(conv);
    1564         psFree(out);
    1565         return NULL;
    1566     }
    1567 
    1568     if (threaded && !psThreadPoolWait(true)) {
    1569         psError(PS_ERR_UNKNOWN, false, "Error waiting for threads.");
    15701597        psFree(conv);
    15711598        psFree(out);
    … …  
    15971624            psFree(job);
    15981625        }
     1626        if (!psThreadPoolWait(true)) {
     1627            psError(PS_ERR_UNKNOWN, false, "Error waiting for threads.");
     1628            psFree(conv);
     1629            psFree(out);
     1630            return NULL;
     1631        }
    15991632    } else if (!imageConvolveMaskRows(out, conv, 0, numCols, setVal, yMin, yMax)) {
    16001633        psError(PS_ERR_UNKNOWN, false, "Unable to convolve mask columns.");
    1601         psFree(conv);
    1602         psFree(out);
    1603         return NULL;
    1604     }
    1605 
    1606     if (threaded && !psThreadPoolWait(true)) {
    1607         psError(PS_ERR_UNKNOWN, false, "Error waiting for threads.");
    16081634        psFree(conv);
    16091635        psFree(out);
    … …  
    16791705bool psImageConvolveSetThreads(bool set)
    16801706{
     1707    pthread_mutex_lock(&threadMutex);
    16811708    bool old = threaded;                // Old value
    16821709    if (set && !threaded) {
    … …  
    17111738    }
    17121739    threaded = set;
     1740    pthread_mutex_unlock(&threadMutex);
    17131741    return old;
    17141742}
  • branches/czw_branch/20100427/psLib/src/imageops/psImageCovariance.c

    r27702 r28017  
    1111#include "psMemory.h"
    1212#include "psConstants.h"
     13#include "psImageStructManip.h"
     14#include "psImagePixelManip.h"
    1315#include "psImageConvolve.h"
    1416#include "psTrace.h"
    … …  
    1618#include "psScalar.h"
    1719#include "psThread.h"
     20#include "psImageInterpolate.h"
    1821
    1922#include "psImageCovariance.h"
    2023
    2124static bool threaded = false;           // Run threaded?
    22 
    2325
    2426psKernel *psImageCovarianceNone(void)
    … …  
    530532
    531533
     534psKernel *psImageCovarianceScale(const psKernel *in, float scale)
     535{
     536    // Trivial cases
     537    if (!in) {
     538        psKernel *out = psKernelAlloc(0, 0, 0, 0); // Output covariance
     539        out->kernel[0][0] = 1.0;
     540        return out;
     541    }
     542    PS_ASSERT_KERNEL_NON_NULL(in, NULL);
     543    if (scale == 1.0) {
     544        psImage *copy = psImageCopy(NULL, in->image, PS_TYPE_F32); // Copy of input covariance
     545        psKernel *out = psKernelAllocFromImage(copy, -in->xMin, -in->yMin); // Output covariance
     546        psFree(copy);
     547        return out;
     548    }
     549
     550    int xMinIn = in->xMin, xMaxIn = in->xMax, yMinIn = in->yMin, yMaxIn = in->yMax; // Input size
     551    int xMinOut = (float)xMinIn / scale - 0.5, xMaxOut = (float)xMaxIn / scale + 0.5;     // Output size in x
     552    int yMinOut = (float)yMinIn / scale - 0.5, yMaxOut = (float)yMaxIn / scale + 0.5;     // Output size in y
     553
     554    // Over-fill the covariance matrix so we're not troubled by edge effects
     555    psKernel *overfill = psKernelAlloc(xMinIn - 1, xMaxIn + 1, yMinIn - 1, yMaxIn + 1); // Overfilled covar
     556    psImageInit(overfill->image, 0.0);
     557    int numOverlay = (xMaxIn - xMinIn + 1) * (yMaxIn - yMinIn + 1); // Number of pixels to overlay
     558    if (psImageOverlaySection(overfill->image, in->image, 1, 1, "=") != numOverlay) {
     559        psError(psErrorCodeLast(), false, "Unable to overfill covariance matrix.");
     560        psFree(overfill);
     561        return NULL;
     562    }
     563
     564    psImageInterpolation *interp = psImageInterpolationAlloc(PS_INTERPOLATE_BILINEAR, overfill->image,
     565                                                             NULL, NULL, 0, NAN, NAN, 0xFF, 0xFF,
     566                                                             0.0, 0); // Interpolation
     567    psFree(overfill);
     568
     569    // In transforming the positions, we get +0.5 to account for the centre of the pixels being at 0.5
     570    // and +1 to account for the overfill.
     571
     572    psKernel *out = psKernelAlloc(xMinOut, xMaxOut, yMinOut, yMaxOut); // Output covariance
     573    for (int y = yMinOut; y <= yMaxOut; y++) {
     574        float yIn = y * scale + 0.5 - yMinIn + 1; // Position on input image (not the kernel)
     575        for (int x = xMinOut; x <= xMaxOut; x++) {
     576            float xIn = x * scale + 0.5 - xMinIn + 1; // Position on input (not the kernel)
     577            double value;                                     // Value on output
     578            if (!psImageInterpolate(&value, NULL, NULL, xIn, yIn, interp)) {
     579                psError(psErrorCodeLast(), false, "Unable to interpolate kernel.");
     580                return false;
     581            }
     582            out->kernel[y][x] = value;
     583        }
     584    }
     585
     586    psFree(interp);
     587
     588    return out;
     589}
     590
     591
    532592bool psImageCovarianceSetThreads(bool set)
    533593{
  • branches/czw_branch/20100427/psLib/src/imageops/psImageCovariance.h

    r27697 r28017  
    9090    );
    9191
     92
     93/// Rescale a covariance matrix following a change in plate scale
     94///
     95/// The covariance matrix is stretched or shrunk to match the new plate scale.
     96psKernel *psImageCovarianceScale(
     97    const psKernel *in,                 ///< Input covariance pseudo-matrix
     98    float scale                         ///< Scale factor (output plate scale relative to input plate scale)
     99    );
     100
    92101/// Control threading for image covariance functions
    93102///
  • branches/czw_branch/20100427/psLib/src/mathtypes/psImage.h

    r19056 r28017  
    6666#define P_PSIMAGE_SET_ROW0(img,r0) {*(int*)&img->row0 = r0;}
    6767#define P_PSIMAGE_SET_TYPE(img,t) {*(psMathType*)&img->type = t;}
     68#define P_PSIMAGE_GET_TYPE(img) ((img)->type->type)
    6869
    6970/** Create an image of the specified size and type.
  • branches/czw_branch/20100427/psLib/src/sys/psConfigure.c

    r23793 r28017  
    6666}
    6767
     68psString psLibRevision(void)
     69{
     70    char *value = NULL;
     71    psStringAppend(&value, "%s", PSLIB_VERSION);
     72    return value;
     73}
     74
    6875psString psLibSource(void)
    6976{
  • branches/czw_branch/20100427/psLib/src/sys/psConfigure.h

    r23148 r28017  
    3232 */
    3333psString psLibVersion(void);
     34
     35/** Get current psLib revision number
     36 *
     37 *  Returns the current psLib revision number as a string.
     38 *
     39 *  @return psString: String with revision number.
     40 */
     41psString psLibRevision(void);
    3442
    3543/** Get current psLib source
  • branches/czw_branch/20100427/psLib/src/types/psMetadataHeader.c

    r27784 r28017  
    1717    psString version = psLibVersion();  // Software version
    1818    psString source = psLibSource();    // Software source
    19 
    20     psMetadataAddStr(header, PS_LIST_TAIL, "PSLIB_V", 0, NULL, source);
     19    psString revision = psLibRevision();
     20    psMetadataAddStr(header, PS_LIST_TAIL, "PSLIB_V", PS_META_REPLACE, NULL, revision);
    2121   
    2222    psStringPrepend(&version, "psLib version: ");
    … …  
    2828    psFree(version);
    2929    psFree(source);
    30 
     30    psFree(revision);
    3131    return true;
    3232}
Note: See TracChangeset for help on using the changeset viewer.