Changeset 2783 for trunk/stac/src/stacTransform.c
- Timestamp:
- Dec 21, 2004, 4:07:04 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/stac/src/stacTransform.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/stac/src/stacTransform.c
r2751 r2783 105 105 106 106 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 107 bool 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 113 115 ) 114 116 { … … 121 123 psError("stac.transform", "Number of maps (%d) does not match number of images (%d).\n", 122 124 maps->n, images->n); 123 return NULL;125 return false; 124 126 } 125 127 if (errors && (images->n != errors->n)) { 126 128 psError("stac.transform", "Number of error images (%d) does not match number of images (%d).\n", 127 129 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 131 147 if (errors && (*outErrors == NULL)) { 132 // Allocate the output error images, if required133 148 *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 } 134 153 } else if (errors->n != (*outErrors)->n) { 135 154 psError("stac.transform", "Number of error output images (%d) does not match number of input" 136 155 "images (%d).\n", (*outErrors)->n, errors->n); 137 return NULL; 138 } 139 156 return false; 157 } 158 159 // Check the masks, if specified 140 160 if (masks != NULL) { 141 161 if (masks->n != nImages) { 142 162 psError("stac.transform", "Number of masks (%d) does not match number of input images (%d).\n", 143 163 masks->n, nImages); 144 return NULL;164 return false; 145 165 } 146 166 for (int i = 0; i < nImages; i++) { … … 151 171 "Size of input mask (%dx%d) does not match that of input image (%dx%d).\n", 152 172 mask->numCols, mask->numRows, image->numCols, image->numRows); 153 return NULL;173 return false; 154 174 } 155 175 } 156 176 } 157 177 158 // Arrays of images for return159 psArray *outImages = psArrayAlloc(nImages); // Output images160 178 161 179 // Stuff for the transformations 162 180 psPlane *detector = psAlloc(sizeof(psPlane)); // Coordinates on the detector 163 181 psPlane *sky = psAlloc(sizeof(psPlane)); // Coordinates on the sky 182 164 183 165 184 // Iterate over the images … … 171 190 psPlaneTransform *map = maps->data[n]; // The map 172 191 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 178 194 179 195 #if 0 … … 193 209 } 194 210 195 #if 0196 // Calculate scales; could be adapted for higher order than linear by moving this into the197 // pixel-dependent section and calculating derivatives198 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 #endif202 203 211 // Iterate over the output image pixels 204 212 for (int y = 0; y < ny; y++) { 205 213 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 220 233 } 221 234 } // Iterating over output pixels … … 233 246 #endif 234 247 235 // Plug the new images into arrays236 outImages->data[n] = outImage;237 (*outErrors)->data[n] = outError;238 239 248 } // Iterating over images 240 249 … … 243 252 psFree(sky); 244 253 245 return outImages;254 return true; 246 255 } 247 256
Note:
See TracChangeset
for help on using the changeset viewer.
