Changeset 3666
- Timestamp:
- Apr 5, 2005, 11:51:26 AM (21 years ago)
- Location:
- trunk/stac/src
- Files:
-
- 1 added
- 11 edited
-
stac.c (modified) (6 diffs)
-
stac.h (modified) (10 diffs)
-
stacCombine.c (modified) (4 diffs)
-
stacConfig.c (modified) (7 diffs)
-
stacConfig.h (added)
-
stacErrorImages.c (modified) (2 diffs)
-
stacInvertMaps.c (modified) (2 diffs)
-
stacRead.c (modified) (2 diffs)
-
stacRejection.c (modified) (6 diffs)
-
stacScales.c (modified) (7 diffs)
-
stacSize.c (modified) (3 diffs)
-
stacTransform.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/stac/src/stac.c
r3660 r3666 2 2 #include "pslib.h" 3 3 #include "stac.h" 4 #include "stacConfig.h" 4 5 #include <sys/time.h> 5 6 … … 47 48 48 49 // Read input files 49 psArray *inputs = stacReadImages(config );50 psArray *inputs = stacReadImages(config->inputs); 50 51 51 52 // Read maps 52 psArray *maps = stacReadMaps(config );53 psArray *maps = stacReadMaps(config->inputs); 53 54 54 55 psTrace("stac.time", 1, "I/O completed at %f seconds\n", getTime() - startTime); … … 56 57 // Get size, if not input 57 58 if (config->outnx == 0 || config->outny == 0) { 58 stacSize( config, inputs, maps);59 stacSize(&config->outnx, &config->outny, &config->xMapDiff, &config->yMapDiff, inputs, maps); 59 60 } 60 61 61 62 // Invert maps 62 psArray *inverseMaps = stacInvertMaps(maps, config );63 psArray *inverseMaps = stacInvertMaps(maps, config->outnx, config->outny); 63 64 64 65 // Generate errors 65 psArray *errors = stacErrorImages(inputs, config); 66 psArray *errors = stacErrorImages(inputs, config->gain, config->readnoise); 67 #ifdef TESTING 68 // Write error images out to check 69 for (int i = 0; i < inputs->n; i++) { 70 char errName[MAXCHAR]; // Filename of error image 71 sprintf(errName,"%s.err",config->inputs->data[i]); 72 psFits *errorFile = psFitsAlloc(errName); 73 if (!psFitsWriteImage(errorFile, NULL, error, 0, NULL)) { 74 psErrorStackPrint(stderr, "Unable to write image: %s\n", errName); 75 } 76 psTrace("stac", 1, "Error image written to %s\n", errName); 77 psFree(errorFile); 78 } 79 #endif 66 80 67 81 // Transform inputs and errors … … 69 83 psArray *transformedErrors = NULL; 70 84 (void)stacTransform(&transformed, &transformedErrors, inputs, inverseMaps, errors, NULL, NULL, NULL, NULL, 71 config); 72 85 config->outnx, config->outny); 73 86 psTrace("stac.time",1,"Transformation completed at %f seconds\n", getTime() - startTime); 87 88 #ifdef TESTING 89 // Write transformed images out to check 90 for (int i = 0; i < inputs->n; i++) { 91 char shiftName[MAXCHAR]; // Filename of shift image 92 char errName[MAXCHAR]; // Filename of error image 93 sprintf(shiftName,"%s.shift1",config->inputs->data[n],numTransforms); 94 sprintf(errName,"%s.shifterr1",config->inputs->data[n],numTransforms); 95 psTrace("stac.transform.test", 6, 96 "Output files have size: %dx%d\n",outImage->numCols,outImage->numRows); 97 psFits *shiftFile = psFitsAlloc(shiftName); 98 psFits *errFile = psFitsAlloc(errName); 99 if (!psFitsWriteImage(shiftFile, NULL, outImage, 0, NULL)) { 100 psErrorStackPrint(stderr, "Unable to write image: %s\n", shiftName); 101 } 102 psTrace("stac", 1, "Shifted image written to %s\n", shiftName); 103 if (!psFitsWriteImage(errFile, NULL, outError, 0, NULL)) { 104 psErrorStackPrint(stderr, "Unable to write image: %s\n", errName); 105 } 106 psTrace("stac", 1, "Shifted error image written to %s\n", errName); 107 psFree(shiftFile); 108 psFree(errFile); 109 } 110 #endif 111 112 74 113 75 114 psVector *scales = NULL; // Relative scales between images 76 115 psVector *offsets = NULL; // Offsets between images 77 (void)stacScales(&scales, &offsets, transformed, config); 116 (void)stacScales(&scales, &offsets, transformed, config->starFile, config->starMapFile, config->xMapDiff, 117 config->yMapDiff, config->aper); 78 118 // Rescale the images 79 119 (void)stacRescale(transformed, transformedErrors, NULL, scales, offsets); 120 // Set the saturation and bad values 121 psVector *saturated = psVectorAlloc(transformed->n, PS_TYPE_F32); // Saturation limits 122 psVector *bad = psVectorAlloc(transformed->n, PS_TYPE_F32); // Bad limits 123 for (int i = 0; i < transformed->n; i++) { 124 saturated->data.F32[i] = (config->saturated - offsets->data.F32[i]) / scales->data.F32[i]; 125 bad->data.F32[i] = (config->bad - offsets->data.F32[i]) / scales->data.F32[i]; 126 } 80 127 81 128 // Combine with rejection 82 129 psArray *rejected = NULL; 83 130 psImage *combined = NULL; 84 (void)stacCombine(&combined, &rejected, transformed, transformedErrors, config->nReject, NULL, config); 131 (void)stacCombine(&combined, &rejected, transformed, transformedErrors, config->nReject, NULL, saturated, 132 bad, config->reject); 85 133 86 134 psTrace("stac.time",1,"First combination completed at %f seconds\n", getTime() - startTime); 87 135 88 #ifdef TESTING 136 137 #ifdef TESTING 138 // Write rejection images out to check 139 for (int i = 0; i < nImages; i++) { 140 char rejName[MAXCHAR]; // Filename of rejection image 141 sprintf(rejName,"%s.shiftrej",config->inputs->data[i]); 142 143 psFits *rejFile = psFitsAlloc(rejName); 144 if (!psFitsWriteImage(rejFile, NULL, (*rejected)->data[i], 0, NULL)) { 145 psErrorStackPrint(stderr, "Unable to write image: %s\n", rejName); 146 } 147 psTrace("stac", 1, "Rejection image written to %s\n", rejName); 148 psFree(rejFile); 149 } 150 151 // Write out pre-combined image 89 152 char preName[MAXCHAR]; // Filename of precombined image 90 153 sprintf(preName,"%s.pre",config->output); … … 116 179 117 180 // Transform rejected pixels to source frame 118 psArray *rejectedSource = stacRejection(inputs, rejected, regions, maps, inverseMaps, config); 181 psArray *rejectedSource = stacRejection(inputs, rejected, regions, maps, inverseMaps, config->frac, 182 config->grad, config->inputs); 119 183 120 184 // Get regions of interest in the output frame … … 134 198 // Redo transformation with the masks and scales/offsets 135 199 (void)stacTransform(&transformed, &transformedErrors, inputs, inverseMaps, errors, rejectedSource, 136 combineRegion, scales, offsets, config );200 combineRegion, scales, offsets, config->outnx, config->outny); 137 201 138 202 // Combine the newly-transformed CR-free images, no rejection 139 203 psFree(rejected); 140 204 rejected = NULL; 141 (void)stacCombine(&combined, &rejected, transformed, transformedErrors, 0, combineRegion, config); 205 (void)stacCombine(&combined, &rejected, transformed, transformedErrors, 0, combineRegion, saturated, 206 bad, config->reject); 142 207 143 208 // Write output image -
trunk/stac/src/stac.h
r3660 r3666 13 13 /************************************************************************************************************/ 14 14 15 // stacConfig.c16 17 // Configuration options18 typedef struct {19 int verbose; // Verbosity level20 float gain, readnoise; // Gain and readnoise for detectors21 psArray *inputs; // Input file names22 const char *output; // Output file name23 bool saveShifts; // Save shifted images?24 const char *starFile; // File with star coordinates25 const char *starMapFile; // File with map for stars26 int outnx, outny; // Size of output image27 float xOffset, yOffset; // Offset to get lower-left corner at 0,028 psVector *saturated; // Saturation level for each image29 psVector *bad; // Bad level for each image30 float reject; // Rejection level31 float frac; // Fraction of input pixel that must be masked before the pixel is32 // considered bad33 float grad; // Multiplier of the gradient34 int nReject; // Number of rejection iterations35 float xMapDiff, yMapDiff; // Difference between pure map and output image coordinates36 float aper; // Aperture size (pixels)37 } stacConfig;38 39 // Allocator40 stacConfig *stacConfigAlloc(void);41 // Deallocator42 void stacConfigFree(stacConfig *config);43 44 // Help message45 void help(const char *name);46 47 // Parse the command line and return config48 stacConfig *stacParseConfig(int argc, // Number of command-line arguments49 char **argv // Command-line arguments50 );51 52 53 /************************************************************************************************************/54 55 15 // stacRead.c 56 16 57 17 // Read the input files and return an array of images 58 psArray *stacReadImages(stacConfig *config); 18 psArray *stacReadImages(psArray *filenames // The file names of the images 19 ); 59 20 60 21 // Read a file of coordinates (x,y) … … 65 26 66 27 // Read the map files and return an array of transformations 67 psArray *stacReadMaps(stacConfig *config); 28 psArray *stacReadMaps(psArray *filenames // The file names of the images whose maps are to be read 29 ); 68 30 69 31 /************************************************************************************************************/ … … 73 35 // Calculate the error images 74 36 psArray *stacErrorImages(psArray *inputs, // Array of input images 75 stacConfig *config // Configuration details 37 float gain, // Gain, in e/ADU 38 float rn // Read noise, in e 76 39 ); 77 40 … … 90 53 const psVector *scales, // Relative scales 91 54 const psVector *offsets, // Relative offsets 92 const stacConfig *config // Configuration55 int outnx, int outny // Size of output images 93 56 ); 94 57 … … 133 96 int nReject, // Number of rejection iterations 134 97 psImage *region, // Region to combine 135 stacConfig *config // Configuration 98 psVector *saturated, // Saturation limits for each image 99 psVector *bad, // Bad pixel limits for each image 100 float reject // Rejection (k-sigma) 136 101 ); 137 102 … … 142 107 // Invert an array of maps 143 108 psArray *stacInvertMaps(const psArray *maps, // Array of maps to invert 144 const stacConfig *config // Configuration 145 ); 146 109 int outnx, int outny // Size of output image 110 ); 147 111 148 112 /************************************************************************************************************/ … … 161 125 psArray *maps, // Maps from input to transformed image 162 126 psArray *inverseMaps, // Maps from transformed to input image 163 stacConfig *config // Configuration 127 float frac, // Fraction of pixel rejected before looking more carefully 128 float grad, // Gradient limit for rejection 129 psArray *names // Names of original images (only for writing out when TESTING) 164 130 ); 165 131 … … 186 152 187 153 // Calculate the size of the output image 188 bool stacSize(stacConfig *config, // Configuration, containing the output size 154 bool stacSize(int *outnx, int *outny, // Size of output image (returned) 155 float *xMapDiff, float *yMapDiff, // Difference applied to maps 189 156 const psArray *images, // Input images 190 157 psArray *maps // Transformation maps 191 158 ); 192 193 159 194 160 /************************************************************************************************************/ … … 206 172 psVector **offsetsPtr, // Offsets to return 207 173 const psArray *images, // Images on which to measure the scales and offsets 208 const stacConfig *config // Configuration 174 const char *starFile, // File containing coordinates to photometer 175 const char *starMapFile, // Map for coodinates to the common output frame 176 float xMapDiff, float yMapDiff, // Difference from the map to apply (due to size difference) 177 float aper // Aperture to use for photometry (radius) 209 178 ); 210 179 … … 224 193 225 194 // Write maps out 226 bool stacWriteMap s(const psArray *maps, // Maps to write227 const stacConfig *config // Configuration195 bool stacWriteMap(const char *mapName, // Filename to write to 196 psPlaneTransform *map // Map to write 228 197 ); 229 198 -
trunk/stac/src/stacCombine.c
r3610 r3666 62 62 int nReject, // Number of rejection iterations 63 63 psImage *region, // Region to combine 64 stacConfig *config // Configuration 64 psVector *saturated, // Saturation limits for each image 65 psVector *bad, // Bad pixel limits for each image 66 float reject // Rejection (k-sigma) 65 67 ) 66 68 { … … 68 70 int numRows = ((psImage*)images->data[0])->numRows; // Image size 69 71 int numCols = ((psImage*)images->data[0])->numCols; // Image size 70 psVector *saturated = config->saturated;// Saturation limits71 psVector *bad = config->bad; // Bad pixel limits72 float reject = config->reject; // Rejection (k-sigma)73 72 74 73 // Check dimensions for consistency … … 188 187 189 188 #ifdef TESTING 190 // Write rejection images out to check191 if (nReject > 0) {192 for (int i = 0; i < nImages; i++) {193 char rejName[MAXCHAR]; // Filename of rejection image194 sprintf(rejName,"%s.shiftrej",config->inputs->data[i]);195 196 psFits *rejFile = psFitsAlloc(rejName);197 if (!psFitsWriteImage(rejFile, NULL, (*rejected)->data[i], 0, NULL)) {198 psErrorStackPrint(stderr, "Unable to write image: %s\n", rejName);199 }200 psTrace("stac", 1, "Rejection image written to %s\n", rejName);201 psFree(rejFile);202 }203 }204 189 // Write chi^2 image 205 190 iteration++; … … 210 195 psErrorStackPrint(stderr, "Unable to write image: %s\n", chiName); 211 196 } 212 psTrace("stac ", 1, "Chi^2 image written to %s\n", chiName);197 psTrace("stac.combine", 1, "Chi^2 image written to %s\n", chiName); 213 198 psFree(chiFile); 214 199 psFree(chi2); 215 200 #endif 216 217 201 218 202 // Clean up -
trunk/stac/src/stacConfig.c
r3660 r3666 6 6 #include "pslib.h" 7 7 #include "stac.h" 8 #include "stacConfig.h" 8 9 9 10 stacConfig *stacConfigAlloc(void) … … 21 22 config->starMapFile = NULL; 22 23 config->aper = 3.0; 23 config->outnx = 512;24 config->outny = 512;25 config->saturated = NULL; // Saturations; will fill this in later, when we know how many images26 config->bad = NULL; // Bad levels; will fill this in later, when we know how many images24 config->outnx = 0; 25 config->outny = 0; 26 config->saturated = 65535.0; // Saturation level 27 config->bad = 0.0; // Bad level 27 28 config->reject = 3.0; 28 29 config->frac = 0.5; … … 40 41 psFree(config->inputs); 41 42 } 42 if (config->saturated) {43 psFree(config->saturated);44 }45 if (config->bad) {46 psFree(config->bad);47 }48 43 // Free everything 49 44 psFree(config); … … 57 52 stacConfig *config = stacConfigAlloc(); // Configuration values 58 53 const char *programName = argv[0]; // Program name 59 60 float saturated = 65535.0; // Saturation level61 float bad = 0.0; // Bad level62 54 63 55 /* Variables for getopt */ … … 96 88 break; 97 89 case 's': 98 if (sscanf(optarg, "%f", & saturated) != 1) {90 if (sscanf(optarg, "%f", &config->saturated) != 1) { 99 91 help(programName); 100 92 exit(EXIT_FAILURE); … … 102 94 break; 103 95 case 'b': 104 if (sscanf(optarg, "%f", & bad) != 1) {96 if (sscanf(optarg, "%f", &config->bad) != 1) { 105 97 help(programName); 106 98 exit(EXIT_FAILURE); … … 170 162 } 171 163 172 // Create the saturation and bad vectors173 config->saturated = psVectorAlloc(argc-1, PS_TYPE_F32);174 config->bad = psVectorAlloc(argc-1, PS_TYPE_F32);175 for (int i = 0; i < argc - 1; i++) {176 ((psVector*)config->saturated)->data.F32[i] = saturated;177 ((psVector*)config->bad)->data.F32[i] = bad;178 }179 180 164 // Debugging output 181 165 psTrace("stac.config", 8, "Parsed command line for configuration\n"); -
trunk/stac/src/stacErrorImages.c
r3375 r3666 4 4 5 5 psArray *stacErrorImages(psArray *inputs, // Array of input images 6 stacConfig *config // Configuration details 6 float gain, // Gain, in e/ADU 7 float rn // Read noise, in e 7 8 ) 8 9 { 9 float invGain = 1.0/ config->gain;// Inverse square root of gain10 float rn = config->readnoise/config->gain;// Read noise in ADU10 float invGain = 1.0/gain; // Inverse square root of gain 11 rn /= gain; // Read noise in ADU 11 12 psArray *errors = psArrayAlloc(inputs->n); 12 13 … … 32 33 // Put image onto the array 33 34 errors->data[i] = error; 34 35 #ifdef TESTING36 // Write error image out to check37 char errName[MAXCHAR]; // Filename of error image38 sprintf(errName,"%s.err",config->inputs->data[i]);39 psFits *errorFile = psFitsAlloc(errName);40 if (!psFitsWriteImage(errorFile, NULL, error, 0, NULL)) {41 psErrorStackPrint(stderr, "Unable to write image: %s\n", errName);42 }43 psTrace("stac", 1, "Error image written to %s\n", errName);44 psFree(errorFile);45 #endif46 47 35 } 48 36 -
trunk/stac/src/stacInvertMaps.c
r3375 r3666 9 9 10 10 psArray *stacInvertMaps(const psArray *maps, // Array of maps to invert 11 const stacConfig *config // Configuration11 int outnx, int outny // Size of output image 12 12 ) 13 13 { … … 48 48 // Create grid of points 49 49 for (int yint = 0; yint < NUM_GRID; yint++) { 50 inCoord->y = (float)(yint * config->outny) / (float)(NUM_GRID - 1);50 inCoord->y = (float)(yint * outny) / (float)(NUM_GRID - 1); 51 51 for (int xint = 0; xint < NUM_GRID; xint++) { 52 inCoord->x = (float)(xint * config->outnx) / (float)(NUM_GRID - 1);52 inCoord->x = (float)(xint * outnx) / (float)(NUM_GRID - 1); 53 53 54 54 (void)psPlaneTransformApply(outCoord, oldMap, inCoord); -
trunk/stac/src/stacRead.c
r3610 r3666 6 6 #define BUFFER 100 // Size of buffer for incrementally reading coordinates 7 7 8 psArray *stacReadImages(stacConfig *config) 8 psArray *stacReadImages(psArray *filenames // The file names of the images 9 ) 9 10 { 10 psArray *filenames = config->inputs;// The file names11 11 int nFiles = filenames->n; // The number of input files 12 12 psArray *images = psArrayAlloc(nFiles); // The input files, to be returned … … 162 162 163 163 164 psArray *stacReadMaps(stacConfig *config) 164 psArray *stacReadMaps(psArray *filenames // The file names of the images whose maps are to be read 165 ) 165 166 { 166 psArray *filenames = config->inputs;// The file names167 167 int nFiles = filenames->n; // The number of input files 168 168 psArray *maps = psArrayAlloc(nFiles); // The maps, to be returned -
trunk/stac/src/stacRejection.c
r3387 r3666 48 48 psArray *maps, // Maps from input to transformed image 49 49 psArray *inverseMaps, // Maps from transformed to input image 50 stacConfig *config // Configuration 50 float frac, // Fraction of pixel rejected before looking more carefully 51 float grad, // Gradient limit for rejection 52 psArray *names // Names of original images (only for writing out when TESTING) 51 53 ) 52 54 { … … 58 60 assert(inputs->n == maps->n); 59 61 assert(inputs->n == inverseMaps->n); 62 assert(!names || names->n == inputs->n); 60 63 61 64 for (int i = 0; i < nImages; i++) { … … 93 96 FILE *crs = NULL; // File for outputting details of rejected pixels 94 97 char crfile[MAXCHAR]; // Filename 95 sprintf(crfile,"%s.cr", config->inputs->data[i]);98 sprintf(crfile,"%s.cr",names->data[i]); 96 99 if ((crs = fopen(crfile, "w")) == NULL) { 97 100 fprintf(stderr, "Unable to open file for detailed output, %s\n"); … … 119 122 #endif 120 123 121 if (maskVal > config->frac) {124 if (maskVal > frac) { 122 125 // Calculate mean gradient on other images 123 126 float meanGrads = 0.0; … … 147 150 #endif 148 151 149 if (stacGradient(inputs->data[i], x, y) < config->grad * meanGrads) {152 if (stacGradient(inputs->data[i], x, y) < grad * meanGrads) { 150 153 mask->data.U8[y][x] = 1; 151 154 nBad++; … … 182 185 char rejmapName[MAXCHAR]; // Filename of rejection image 183 186 char gradName[MAXCHAR]; // Filename of gradient image 184 sprintf(maskName, "%s.mask",config->inputs->data[i]);185 sprintf(rejmapName, "%s.rejmap",config->inputs->data[i]);186 sprintf(gradName, "%s.grad",config->inputs->data[i]);187 sprintf(maskName, "%s.mask", names->data[i]); 188 sprintf(rejmapName, "%s.rejmap", names->data[i]); 189 sprintf(gradName, "%s.grad", names->data[i]); 187 190 188 191 psFits *maskFile = psFitsAlloc(maskName); -
trunk/stac/src/stacScales.c
r3613 r3666 54 54 psVector **offsetsPtr, // Offsets to return 55 55 const psArray *images, // Images on which to measure the scales and offsets 56 const stacConfig *config // Configuration 56 const char *starFile, // File containing coordinates to photometer 57 const char *starMapFile, // Map for coodinates to the common output frame 58 float xMapDiff, float yMapDiff, // Difference from the map to apply (due to size difference) 59 float aper // Aperture to use for photometry (radius) 57 60 ) 58 61 { … … 60 63 assert(offsetsPtr); 61 64 assert(images); 62 assert(config);63 65 for (int i = 0; i < images->n; i++) { 64 66 psImage *image = images->data[i]; … … 99 101 100 102 // Now the scales 101 if ( config->starFile == NULL || config->starMapFile == NULL) {103 if (starFile == NULL || starMapFile == NULL) { 102 104 psLogMsg("stac.scales", PS_LOG_INFO, 103 105 "No coordinates available to set scales --- assuming all are identical.\n"); … … 108 110 } else { 109 111 // Read star coordinates and map 110 psArray *starCoords = stacReadCoords( config->starFile); // Array of star coordinates111 psPlaneTransform *starMap = stacReadMap( config->starMapFile); // Transformation for star coordinates112 psArray *starCoords = stacReadCoords(starFile); // Array of star coordinates 113 psPlaneTransform *starMap = stacReadMap(starMapFile); // Transformation for star coordinates 112 114 113 115 // Transform the stellar positions to match the transformed reference frame 114 116 psArray *starCoordsTransformed = psArrayAlloc(starCoords->n); // Transformed positions 115 117 // Fix up difference between map and output frame 116 starMap->x->coeff[0][0] -= config->xMapDiff;117 starMap->y->coeff[0][0] -= config->yMapDiff;118 starMap->x->coeff[0][0] -= xMapDiff; 119 starMap->y->coeff[0][0] -= yMapDiff; 118 120 for (int i = 0; i < starCoords->n; i++) { 119 121 starCoordsTransformed->data[i] = psPlaneTransformApply(NULL, starMap, starCoords->data[i]); … … 139 141 psPlane *coords = starCoordsTransformed->data[j]; // The coordinates of the star 140 142 141 if (coords->x < config->aper || coords->y < config->aper ||142 coords->x + config->aper > image->numCols - 1 ||143 coords->y + config->aper > image->numRows) {143 if (coords->x < aper || coords->y < aper || 144 coords->x + aper > image->numCols - 1 || 145 coords->y + aper > image->numRows) { 144 146 mask->data.U8[j] = 1; 145 147 } else { … … 147 149 float sum = 0.0; 148 150 int numPix = 0; 149 float aper2 = SQUARE( config->aper);150 for (int y = (int)floorf(coords->y - config->aper);151 y <= (int)ceilf(coords->y + config->aper); y++) {152 for (int x = (int)floorf(coords->x - config->aper);153 x <= (int)ceilf(coords->x + config->aper); x++) {151 float aper2 = SQUARE(aper); 152 for (int y = (int)floorf(coords->y - aper); 153 y <= (int)ceilf(coords->y + aper); y++) { 154 for (int x = (int)floorf(coords->x - aper); 155 x <= (int)ceilf(coords->x + aper); x++) { 154 156 if (SQUARE((float)x + 0.5 - coords->x) + SQUARE((float)y + 0.5 - coords->y) <= 155 157 aper2) { … … 198 200 } 199 201 200 // Change the saturation and bad values201 psVector *saturated = config->saturated; // Saturation limits202 psVector *bad = config->bad; // Bad limits203 for (int i = 0; i < saturated->n; i++) {204 saturated->data.F32[i] = (saturated->data.F32[i] - offsets->data.F32[i]) / scales->data.F32[i];205 bad->data.F32[i] = (bad->data.F32[i] - offsets->data.F32[i]) / scales->data.F32[i];206 }207 208 202 return true; 209 203 } -
trunk/stac/src/stacSize.c
r3610 r3666 4 4 #include "stac.h" 5 5 6 bool stacSize(stacConfig *config, // Configuration, containing the output size 6 bool stacSize(int *outnx, int *outny, // Size of output image (returned) 7 float *xMapDiff, float *yMapDiff, // Difference applied to maps 7 8 const psArray *images, // Input images 8 9 psArray *maps // Transformation maps … … 91 92 92 93 // Tweak the maps to account for the offset 93 config->xMapDiff = floor(xMin);94 config->yMapDiff = floor(yMin);94 *xMapDiff = floor(xMin); 95 *yMapDiff = floor(yMin); 95 96 for (int i = 0; i < nImages; i++) { 96 97 psPlaneTransform *map = maps->data[i]; // The map of interest … … 99 100 } 100 101 101 config->outnx = (int)(xMax + 0.5) - (int)xMin;102 config->outny = (int)(yMax + 0.5) - (int)yMin;102 *outnx = (int)(xMax + 0.5) - (int)xMin; 103 *outny = (int)(yMax + 0.5) - (int)yMin; 103 104 104 psTrace("stac.size", 1, "Output size is to be %dx%d\n", config->outnx, config->outny);105 psTrace("stac.size", 1, "Output size is to be %dx%d\n", *outnx, *outny); 105 106 106 107 psFree(inCoord); -
trunk/stac/src/stacTransform.c
r3610 r3666 7 7 #define MIN(x,y) (((x) > (y)) ? (y) : (x)) 8 8 #define MAX(x,y) (((x) > (y)) ? (x) : (y)) 9 10 #define MAXCHAR 8011 12 static int numTransforms = 0; // Number of transformations performed13 14 9 15 10 // Hacked the original ps_ImagePixelInterpolateBILINEAR_F32 to add variances … … 115 110 const psVector *scales, // Relative scales 116 111 const psVector *offsets, // Relative offsets 117 const stacConfig *config // Configuration112 int outnx, int outny // Size of output images 118 113 ) 119 114 { 120 115 int nImages = images->n; // Number of images 121 int nx = config->outnx, ny = config->outny; // Size of output images122 numTransforms++;123 116 124 117 // Check input sizes … … 134 127 if (*outputs == NULL) { 135 128 *outputs = psArrayAlloc(nImages); 136 psTrace("stac.transform", 5, "Allocating space for transformed images, %dx%d\n", nx,ny);129 psTrace("stac.transform", 5, "Allocating space for transformed images, %dx%d\n", outnx, outny); 137 130 for (int i = 0; i < nImages; i++) { 138 (*outputs)->data[i] = psImageAlloc( nx,ny, PS_TYPE_F32);131 (*outputs)->data[i] = psImageAlloc(outnx, outny, PS_TYPE_F32); 139 132 } 140 133 } … … 144 137 if (errors && (*outErrors == NULL)) { 145 138 *outErrors = psArrayAlloc(errors->n); 146 psTrace("stac.transform", 5, "Allocating space for transformed error images, %dx%d\n", nx,ny);139 psTrace("stac.transform", 5, "Allocating space for transformed error images, %dx%d\n", outnx, outny); 147 140 for (int i = 0; i < nImages; i++) { 148 (*outErrors)->data[i] = psImageAlloc( nx,ny, PS_TYPE_F32);141 (*outErrors)->data[i] = psImageAlloc(outnx, outny, PS_TYPE_F32); 149 142 } 150 143 } … … 187 180 #if 0 188 181 // No need for initialisation, since we iterate over the entire output image. 189 for (int y = 0; y < ny; y++) {190 for (int x = 0; x < nx; x++) {182 for (int y = 0; y < outny; y++) { 183 for (int x = 0; x < outnx; x++) { 191 184 outImage->data.F32[y][x] = 0.0; 192 185 outError->data.F32[y][x] = 0.0; … … 202 195 203 196 // Iterate over the output image pixels 204 for (int y = 0; y < ny; y++) {205 for (int x = 0; x < nx; x++) {197 for (int y = 0; y < outny; y++) { 198 for (int x = 0; x < outnx; x++) { 206 199 // Only transform those pixels requested 207 200 if (!region || (region && region->data.U8[y][x])) { … … 229 222 } // Iterating over output pixels 230 223 231 #ifdef TESTING232 // Write error image out to check233 char shiftName[MAXCHAR]; // Filename of shift image234 char errName[MAXCHAR]; // Filename of error image235 sprintf(shiftName,"%s.shift.%d",config->inputs->data[n],numTransforms);236 sprintf(errName,"%s.shifterr.%d",config->inputs->data[n],numTransforms);237 psTrace("stac.transform.test", 6,238 "Output files have size: %dx%d\n",outImage->numCols,outImage->numRows);239 240 psFits *shiftFile = psFitsAlloc(shiftName);241 psFits *errFile = psFitsAlloc(errName);242 if (!psFitsWriteImage(shiftFile, NULL, outImage, 0, NULL)) {243 psErrorStackPrint(stderr, "Unable to write image: %s\n", shiftName);244 }245 psTrace("stac", 1, "Shifted image written to %s\n", shiftName);246 if (!psFitsWriteImage(errFile, NULL, outError, 0, NULL)) {247 psErrorStackPrint(stderr, "Unable to write image: %s\n", errName);248 }249 psTrace("stac", 1, "Shifted error image written to %s\n", errName);250 psFree(shiftFile);251 psFree(errFile);252 #endif253 254 224 } // Iterating over images 255 225
Note:
See TracChangeset
for help on using the changeset viewer.
