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/pmSubtractionVisual.c

    r23487 r26321  
    1616
    1717#include "pmKapaPlots.h"
     18#include "pmSubtraction.h"
    1819#include "pmSubtractionStamps.h"
     20#include "pmSubtractionEquation.h"
    1921
    2022#include "pmVisual.h"
     
    3234static bool plotLeastSquares     = true;
    3335static bool plotImage            = true;
     36
    3437// variables to store plotting window indices
    35 static int kapa  = -1;
     38static int kapa1 = -1;
    3639static int kapa2 = -1;
     40static int kapa3 = -1;
    3741
    3842/** function prototypes*/
     
    4650bool pmSubtractionVisualClose(void)
    4751{
    48     if(kapa != -1)
    49         KiiClose(kapa);
    50     if(kapa2 != -1)
    51         KiiClose(kapa2);
     52    if(kapa1 != -1) KiiClose(kapa1);
     53    if(kapa2 != -1) KiiClose(kapa2);
    5254    return true;
    5355}
     
    6062bool pmSubtractionVisualPlotConvKernels(psImage *convKernels) {
    6163    if (!pmVisualIsVisual() || !plotConvKernels) return true;
    62     if (!pmVisualInitWindow(&kapa, "ppSub:Images")) {
    63         return false;
    64     }
    65     pmVisualScaleImage(kapa, convKernels, "Convolution_Kernels", 0, true);
     64    if (!pmVisualInitWindow(&kapa1, "ppSub:Images")) {
     65        return false;
     66    }
     67    pmVisualScaleImage(kapa1, convKernels, "Convolution_Kernels", 0, true);
    6668    pmVisualAskUser(&plotConvKernels);
    6769    return true;
     
    7476bool pmSubtractionVisualPlotStamps(pmSubtractionStampList *stamps, pmReadout *ro) {
    7577    if (!pmVisualIsVisual() || !plotStamps) return true;
    76     if (!pmVisualInitWindow (&kapa, "ppSub:Images")) {
     78    if (!pmVisualInitWindow (&kapa1, "ppSub:Images")) {
    7779        return false;
    7880    }
     
    134136        stampNum++;
    135137    }
    136     pmVisualScaleImage(kapa, canvas, "Subtraction_Stamps", 0, true);
     138    pmVisualScaleImage(kapa1, canvas, "Subtraction_Stamps", 0, true);
    137139
    138140    pmVisualAskUser(&plotStamps);
     
    144146
    145147    if (!pmVisualIsVisual() || !plotLeastSquares) return true;
    146     if (!pmVisualInitWindow (&kapa, "PPSub:Images")) {
     148    if (!pmVisualInitWindow (&kapa1, "PPSub:Images")) {
    147149        return false;
    148150    }
     
    197199
    198200    psImage *canvas32 = pmVisualImageToFloat(canvas);
    199     pmVisualScaleImage(kapa, canvas32, "Least_Squares", 0, true);
     201    pmVisualScaleImage(kapa1, canvas32, "Least_Squares", 0, true);
    200202
    201203    pmVisualAskUser(&plotLeastSquares);
     
    207209bool pmSubtractionVisualShowSubtraction(psImage *image, psImage *ref, psImage *sub) {
    208210    if (!pmVisualIsVisual() || !plotImage) return true;
    209     if (!pmVisualInitWindow (&kapa, "PPSub:Images")) {
    210         return false;
    211     }
    212 
    213     pmVisualScaleImage(kapa, image, "Image", 0, true);
    214     pmVisualScaleImage(kapa, ref, "Reference", 1, true);
    215     pmVisualScaleImage(kapa, sub, "Subtraction", 2, true);
     211    if (!pmVisualInitWindow (&kapa1, "PPSub:Images")) {
     212        return false;
     213    }
     214
     215    pmVisualScaleImage(kapa1, image, "Image", 0, true);
     216    pmVisualScaleImage(kapa1, ref, "Reference", 1, true);
     217    pmVisualScaleImage(kapa1, sub, "Subtraction", 2, true);
    216218    pmVisualAskUser(&plotImage);
    217219    return true;
     
    255257}
    256258
     259static int footprint = 0;
     260static int NX = 0;
     261static int NY = 0;
     262static psImage *sourceImage      = NULL;
     263static psImage *targetImage      = NULL;
     264static psImage *residualImage    = NULL;
     265static psImage *differenceImage  = NULL;
     266static psImage *convolutionImage = NULL;
     267
     268bool pmSubtractionVisualShowFitInit(pmSubtractionStampList *stamps) {
     269
     270    // if (!pmVisualIsVisual()) return true;
     271
     272    // generate 4 storage images large enough to hold the N stamps:
     273
     274    footprint = stamps->footprint;
     275
     276    float NXf = sqrt(stamps->num);
     277    NX = (int) NXf == NXf ? NXf : NXf + 1.0;
     278   
     279    float NYf = stamps->num / NX;
     280    NY = (int) NYf == NY ? NYf : NYf + 1.0;
     281
     282    int NXpix = (2*footprint + 1) * NX;
     283    NXpix += (NX > 1) ? 3 * NX : 0;
     284
     285    int NYpix = (2*footprint + 1) * NY;
     286    NYpix += (NY > 1) ? 3 * NY : 0;
     287
     288    sourceImage      = psImageAlloc (NXpix, NYpix, PS_TYPE_F32);
     289    targetImage      = psImageAlloc (NXpix, NYpix, PS_TYPE_F32);
     290    residualImage    = psImageAlloc (NXpix, NYpix, PS_TYPE_F32);
     291    differenceImage  = psImageAlloc (NXpix, NYpix, PS_TYPE_F32);
     292    convolutionImage = psImageAlloc (NXpix, NYpix, PS_TYPE_F32);
     293   
     294    psImageInit (sourceImage,      0.0);
     295    psImageInit (targetImage,      0.0);
     296    psImageInit (residualImage,    0.0);
     297    psImageInit (differenceImage,  0.0);
     298    psImageInit (convolutionImage, 0.0);
     299
     300    return true;
     301}
     302
     303bool pmSubtractionVisualShowFitAddStamp(psKernel *target, psKernel *source, psKernel *convolution, double background, double norm, int index) {
     304
     305    // if (!pmVisualIsVisual()) return true;
     306
     307    int NXoff = index % NX;
     308    int NYoff = index / NX;
     309
     310    int NXpix = NXoff * (2*footprint + 1 + 3) + footprint;
     311    int NYpix = NYoff * (2*footprint + 1 + 3) + footprint;
     312
     313    // insert the (target) kernel into the (target) image:
     314    for (int y = -footprint; y <= footprint; y++) {
     315        for (int x = -footprint; x <= footprint; x++) {
     316            targetImage->data.F32[y + NYpix][x + NXpix] = target->kernel[y][x];
     317        }
     318    }
     319
     320    // insert the (source) kernel into the (source) image:
     321    for (int y = -footprint; y <= footprint; y++) {
     322        for (int x = -footprint; x <= footprint; x++) {
     323            sourceImage->data.F32[y + NYpix][x + NXpix] = source->kernel[y][x];
     324        }
     325    }
     326   
     327    // insert the (convolution) kernel into the (convolution) image:
     328    for (int y = -footprint; y <= footprint; y++) {
     329        for (int x = -footprint; x <= footprint; x++) {
     330            convolutionImage->data.F32[y + NYpix][x + NXpix] = -convolution->kernel[y][x];
     331        }
     332    }
     333   
     334    // insert the (difference) kernel into the (difference) image:
     335    for (int y = -footprint; y <= footprint; y++) {
     336        for (int x = -footprint; x <= footprint; x++) {
     337            differenceImage->data.F32[y + NYpix][x + NXpix] = target->kernel[y][x] - background - source->kernel[y][x] * norm;
     338        }
     339    }
     340
     341    // insert the (residual) kernel into the (residual) image:
     342    for (int y = -footprint; y <= footprint; y++) {
     343        for (int x = -footprint; x <= footprint; x++) {
     344            residualImage->data.F32[y + NYpix][x + NXpix] = target->kernel[y][x] - background - source->kernel[y][x] * norm + convolution->kernel[y][x];
     345        }
     346    }
     347    return true;
     348}
     349
     350bool pmSubtractionVisualShowFit() {
     351
     352    // if (!pmVisualIsVisual()) return true;
     353    if (!pmVisualInitWindow(&kapa1, "ppSub:Images")) return false;
     354    if (!pmVisualInitWindow(&kapa2, "ppSub:Misc")) return false;
     355
     356    pmVisualScaleImage(kapa1, targetImage, "Target Stamps", 0, true);
     357    pmVisualScaleImage(kapa1, sourceImage, "Source Stamps", 1, true);
     358    pmVisualScaleImage(kapa1, convolutionImage, "Convolution Stamps", 2, true);
     359
     360    pmVisualScaleImage(kapa2, differenceImage, "Difference Stamps", 0, true);
     361    pmVisualScaleImage(kapa2, residualImage, "Residual Stamps", 1, true);
     362    pmVisualAskUser(NULL);
     363
     364    psFree(targetImage);
     365    psFree(sourceImage);
     366    psFree(convolutionImage);
     367    psFree(differenceImage);
     368    psFree(residualImage);
     369
     370    targetImage = NULL;
     371    sourceImage = NULL;
     372    convolutionImage = NULL;
     373    differenceImage = NULL;
     374    residualImage = NULL;
     375
     376    return true;
     377}
     378
     379bool pmSubtractionVisualPlotFit(const pmSubtractionKernels *kernels) {
     380
     381    Graphdata graphdata;
     382
     383    // if (!pmVisualIsVisual()) return true;
     384    if (!pmVisualInitWindow(&kapa3, "ppSub:plots")) return false;
     385
     386    KapaClearSections (kapa3);
     387    KapaInitGraph (&graphdata);
     388
     389    psVector *x = psVectorAllocEmpty (kernels->num, PS_TYPE_F32);
     390    psVector *y = psVectorAllocEmpty (kernels->num, PS_TYPE_F32);
     391
     392    graphdata.xmin = -1.0;
     393    graphdata.xmax = kernels->num + 1.0;
     394    graphdata.ymin = +32.0;
     395    graphdata.ymax = -32.0;
     396
     397    psImage *polyValues = p_pmSubtractionPolynomial(NULL, kernels->spatialOrder, 0.0, 0.0);
     398
     399    // construct the plot vectors
     400    for (int i = 0; i < kernels->num; i++) {
     401        x->data.F32[i] = i;
     402        y->data.F32[i] = p_pmSubtractionSolutionCoeff(kernels, polyValues, i, false);
     403        graphdata.ymin = PS_MIN(graphdata.ymin, y->data.F32[i]);
     404        graphdata.ymax = PS_MAX(graphdata.ymax, y->data.F32[i]);
     405    }
     406    x->n = y->n = kernels->num;
     407
     408    float range;
     409    range = graphdata.xmax - graphdata.xmin;
     410    graphdata.xmax += 0.05*range;
     411    graphdata.xmin -= 0.05*range;
     412    range = graphdata.ymax - graphdata.ymin;
     413    graphdata.ymax += 0.05*range;
     414    graphdata.ymin -= 0.05*range;
     415
     416    KapaSetLimits (kapa3, &graphdata);
     417
     418    KapaSetFont (kapa3, "helvetica", 14);
     419    KapaBox (kapa3, &graphdata);
     420    KapaSendLabel (kapa3, "kernel number", KAPA_LABEL_XM);
     421    KapaSendLabel (kapa3, "coeff", KAPA_LABEL_YM);
     422
     423    graphdata.color = KapaColorByName ("black");
     424    graphdata.ptype = 2;
     425    graphdata.size = 0.5;
     426    graphdata.style = 2;
     427
     428    KapaPrepPlot   (kapa3, x->n, &graphdata);
     429    KapaPlotVector (kapa3, x->n, x->data.F32, "x");
     430    KapaPlotVector (kapa3, x->n, y->data.F32, "y");
     431
     432    psFree (x);
     433    psFree (y);
     434
     435    pmVisualAskUser(NULL);
     436    return true;
     437}
     438
    257439#else
    258440bool pmSubtractionVisualClose(void) {return true;}
     
    261443bool pmSubtractionVisualPlotLeastSquares(pmSubtractionStampList *stamps) {return true;}
    262444bool pmSubtractionVisualShowSubtraction(psImage *image, psImage *ref, psImage *sub) {return true;}
     445bool pmSubtractionVisualShowFitInit(pmSubtractionStampList *stamps) {return true;}
     446bool pmSubtractionVisualShowFitAddStamp(psKernel *target, psKernel *source, psKernel *convolution, double background, double norm, int index) {return true;}
     447bool pmSubtractionVisualShowFit() {return true;}
     448bool pmSubtractionVisualPlotFit(const pmSubtractionKernels *kernels);
    263449#endif
Note: See TracChangeset for help on using the changeset viewer.