IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 21, 2004, 4:07:04 PM (22 years ago)
Author:
Paul Price
Message:

Running fast now. Only optimisation tweaks to be made now.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/stac/src/stacTransform.c

    r2751 r2783  
    105105
    106106
    107 psArray *stacTransform(const psArray *images, // Array of images to be transformed
    108                        const psArray *maps, // Array of polynomials that do the transformation
    109                        const psArray *errors, // Array of error images to be transformed
    110                        psArray **outErrors, // Transformed error images for output
    111                        const psArray *masks, // Masks of input images
    112                        const stacConfig *config // Configuration
     107bool stacTransform(psArray **outputs,   // Transformed images for output
     108                   psArray **outErrors, // Transformed error images for output
     109                   const psArray *images, // Array of images to be transformed
     110                   const psArray *maps, // Array of polynomials that do the transformation
     111                   const psArray *errors, // Array of error images to be transformed
     112                   const psArray *masks, // Masks of input images
     113                   const psImage *region, // Region of interest for transformation
     114                   const stacConfig *config // Configuration
    113115    )
    114116{
     
    121123        psError("stac.transform", "Number of maps (%d) does not match number of images (%d).\n",
    122124                maps->n, images->n);
    123         return NULL;
     125        return false;
    124126    }
    125127    if (errors && (images->n != errors->n)) {
    126128        psError("stac.transform", "Number of error images (%d) does not match number of images (%d).\n",
    127129                errors->n, images->n);
    128         return NULL;
    129     }
    130 
     130        return false;
     131    }
     132
     133    // Allocate the output images if required, otherwise check the number
     134    if (*outputs == NULL) {
     135        *outputs = psArrayAlloc(nImages);
     136        psTrace("stac.transform", 5, "Allocating space for transformed images, %dx%d\n", nx, ny);
     137        for (int i = 0; i < nImages; i++) {
     138            (*outputs)->data[i] = psImageAlloc(nx, ny, PS_TYPE_F32);
     139        }
     140    } else if ((*outputs)->n != nImages) {
     141        psError("stac.transform", "Number of output images (%d) does not match number of input images "
     142                "(%d).\n", (*outputs)->n, nImages);
     143        return false;
     144    }
     145
     146    // Allocate the output error images, if required, otherwise check the number
    131147    if (errors && (*outErrors == NULL)) {
    132         // Allocate the output error images, if required
    133148        *outErrors = psArrayAlloc(errors->n);
     149        psTrace("stac.transform", 5, "Allocating space for transformed error images, %dx%d\n", nx, ny);
     150        for (int i = 0; i < nImages; i++) {
     151            (*outErrors)->data[i] = psImageAlloc(nx, ny, PS_TYPE_F32);
     152        }
    134153    } else if (errors->n != (*outErrors)->n) {
    135154        psError("stac.transform", "Number of error output images (%d) does not match number of input"
    136155                "images (%d).\n", (*outErrors)->n, errors->n);
    137         return NULL;
    138     }
    139 
     156        return false;
     157    }
     158
     159    // Check the masks, if specified
    140160    if (masks != NULL) {
    141161        if (masks->n != nImages) {
    142162            psError("stac.transform", "Number of masks (%d) does not match number of input images (%d).\n",
    143163                    masks->n, nImages);
    144             return NULL;
     164            return false;
    145165        }
    146166        for (int i = 0; i < nImages; i++) {
     
    151171                         "Size of input mask (%dx%d) does not match that of input image (%dx%d).\n",
    152172                         mask->numCols, mask->numRows, image->numCols, image->numRows);
    153                 return NULL;
     173                return false;
    154174            }
    155175        }
    156176    }
    157177
    158     // Arrays of images for return
    159     psArray *outImages = psArrayAlloc(nImages); // Output images
    160178
    161179    // Stuff for the transformations
    162180    psPlane *detector = psAlloc(sizeof(psPlane)); // Coordinates on the detector
    163181    psPlane *sky = psAlloc(sizeof(psPlane)); // Coordinates on the sky
     182
    164183
    165184    // Iterate over the images
     
    171190        psPlaneTransform *map = maps->data[n]; // The map
    172191        psImage *error = errors->data[n]; // The error image
    173 
    174         // Initialise the output images
    175         psImage *outImage = psImageAlloc(nx, ny, PS_TYPE_F32);
    176         psImage *outError = psImageAlloc(nx, ny, PS_TYPE_F32);
    177         psTrace("stac.transform", 5, "Allocating space for transformed image, %dx%d\n", nx, ny);
     192        psImage *outImage = (*outputs)->data[n]; // The output image
     193        psImage *outError = (*outErrors)->data[n]; // The output error image
    178194
    179195#if 0
     
    193209        }
    194210
    195 #if 0
    196         // Calculate scales; could be adapted for higher order than linear by moving this into the
    197         // pixel-dependent section and calculating derivatives
    198         double xscale = 0.5*sqrt(SQUARE(map->x->coeff[0][1]) + SQUARE(map->x->coeff[1][0]));
    199         double yscale = 0.5*sqrt(SQUARE(map->y->coeff[0][1]) + SQUARE(map->y->coeff[1][0]));
    200         double areascale = 0.25 / xscale / yscale;
    201 #endif
    202 
    203211        // Iterate over the output image pixels
    204212        for (int y = 0; y < ny; y++) {
    205213            for (int x = 0; x < nx; x++) {
    206                 // Transform!
    207                 sky->x = (double)x + 0.5;
    208                 sky->y = (double)y + 0.5;
    209                 (void)psPlaneTransformApply(detector, map, sky);
    210 
    211                 // Change PS_INTERPOLATE_BILINEAR to best available technique.
    212                 outImage->data.F32[y][x] = (psF32)psImagePixelInterpolate(image, detector->x + 0.5,
    213                                                                           detector->y + 0.5, mask, 1, 0.0,
    214                                                                           PS_INTERPOLATE_BILINEAR);
    215                 outError->data.F32[y][x] = (psF32)p_psImageErrorInterpolateBILINEAR_F32(error,
    216                                                                                         detector->x + 0.5,
    217                                                                                         detector->y + 0.5,
    218                                                                                         mask, 1, 0.0);
    219                 outError->data.F32[y][x] = sqrtf(outError->data.F32[y][x]);
     214
     215                // Only transform those pixels requested
     216                if (!region || (region && region->data.U8[y][x])) {
     217                    // Transform!
     218                    sky->x = (double)x + 0.5;
     219                    sky->y = (double)y + 0.5;
     220                    (void)psPlaneTransformApply(detector, map, sky);
     221                   
     222                    // Change PS_INTERPOLATE_BILINEAR to best available technique.
     223                    outImage->data.F32[y][x] = (psF32)psImagePixelInterpolate(image, detector->x + 0.5,
     224                                                                              detector->y + 0.5, mask, 1, 0.0,
     225                                                                              PS_INTERPOLATE_BILINEAR);
     226                    // Error is actually the variance
     227                    outError->data.F32[y][x] = (psF32)p_psImageErrorInterpolateBILINEAR_F32(error,
     228                                                                                            detector->x + 0.5,
     229                                                                                            detector->y + 0.5,
     230                                                                                            mask, 1, 0.0);
     231                } // Pixels of interest
     232
    220233            }
    221234        } // Iterating over output pixels
     
    233246#endif
    234247
    235         // Plug the new images into arrays
    236         outImages->data[n] = outImage;
    237         (*outErrors)->data[n] = outError;
    238 
    239248    } // Iterating over images
    240249
     
    243252    psFree(sky);
    244253
    245     return outImages;
     254    return true;
    246255}
    247256
Note: See TracChangeset for help on using the changeset viewer.