IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 2, 2009, 12:04:51 PM (16 years ago)
Author:
Paul Price
Message:

Merging Gene's work on adding a window function to the stamps. I'd been thinking about something like this for a while, so glad someone's done it. It's got visualisation turned on though.

Location:
branches/pap/psModules/src/imcombine
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/pap/psModules/src/imcombine

  • branches/pap/psModules/src/imcombine/pmSubtractionStamps.c

    r26046 r26321  
    4646    psFree(list->y);
    4747    psFree(list->flux);
     48    psFree(list->window);
    4849}
    4950
     
    220221    list->y = NULL;
    221222    list->flux = NULL;
     223    list->window = NULL;
    222224    list->footprint = footprint;
    223225    list->sysErr = sysErr;
     
    239241    out->y = NULL;
    240242    out->flux = NULL;
     243    out->window = psMemIncrRefCounter(in->window);
    241244    out->footprint = in->footprint;
    242245
     
    606609}
    607610
     611
     612bool pmSubtractionStampsGetWindow(pmSubtractionStampList *stamps, int kernelSize)
     613{
     614    PM_ASSERT_SUBTRACTION_STAMP_LIST_NON_NULL(stamps, false);
     615    PS_ASSERT_INT_NONNEGATIVE(kernelSize, false);
     616
     617    int size = kernelSize + stamps->footprint; // Size of postage stamps
     618
     619    psFree (stamps->window);
     620    stamps->window = psKernelAlloc(-size, size, -size, size);
     621    psImageInit(stamps->window->image, 0.0);
     622
     623    // generate normalizations for each stamp
     624    psVector *norm1 = psVectorAlloc(stamps->num, PS_TYPE_F32);
     625    psVector *norm2 = psVectorAlloc(stamps->num, PS_TYPE_F32);
     626    for (int i = 0; i < stamps->num; i++) {
     627        pmSubtractionStamp *stamp = stamps->stamps->data[i]; // Stamp of interest
     628        if (!stamp) continue;
     629        if (!stamp->image1) continue;
     630        if (!stamp->image2) continue;
     631
     632        float sum1 = 0.0;
     633        float sum2 = 0.0;
     634        for (int y = -size; y <= size; y++) {
     635            for (int x = -size; x <= size; x++) {
     636                sum1 += stamp->image1->kernel[y][x];
     637                sum2 += stamp->image2->kernel[y][x];
     638            }
     639        }
     640        norm1->data.F32[i] = sum1;
     641        norm2->data.F32[i] = sum2;
     642    }
     643
     644    // storage vector for flux data
     645    psStats *stats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);
     646    psVector *flux = psVectorAllocEmpty(2*stamps->num, PS_TYPE_F32);
     647
     648    // generate the window pixels
     649    for (int y = -size; y <= size; y++) {
     650        for (int x = -size; x <= size; x++) {
     651
     652            flux->n = 0;
     653            for (int i = 0; i < stamps->num; i++) {
     654                pmSubtractionStamp *stamp = stamps->stamps->data[i]; // Stamp of interest
     655                if (!stamp) continue;
     656                if (!stamp->image1) continue;
     657                if (!stamp->image2) continue;
     658               
     659                psVectorAppend (flux, stamp->image1->kernel[y][x] / norm1->data.F32[i]);
     660                psVectorAppend (flux, stamp->image2->kernel[y][x] / norm2->data.F32[i]);
     661            }
     662
     663            psStatsInit (stats);
     664            if (!psVectorStats (stats, flux, NULL, NULL, 0)) {
     665                psAbort ("failed to generate stats");
     666            }
     667            stamps->window->kernel[y][x] = stats->robustMedian;
     668        }
     669    }
     670
     671    // XXX TESTING:
     672    {
     673        psFits *fits = psFitsOpen ("window.fits", "w");
     674        psFitsWriteImage (fits, NULL, stamps->window->image, 0, NULL);
     675        psFitsClose (fits);
     676    }
     677
     678    psFree (stats);
     679    psFree (flux);
     680    psFree (norm1);
     681    psFree (norm2);
     682    return true;
     683}
    608684
    609685bool pmSubtractionStampsExtract(pmSubtractionStampList *stamps, psImage *image1, psImage *image2,
Note: See TracChangeset for help on using the changeset viewer.