Changeset 41341 for trunk/Ohana/src/opihi/cmd.data/extract.c
- Timestamp:
- Apr 16, 2020, 2:04:27 PM (6 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/cmd.data/extract.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.data/extract.c
r41340 r41341 1 1 # include "data.h" 2 3 /* <from> : source image, must exist 4 <to> : target image -- if it does not exist, it is created of size (Nx,Ny) 5 sx, sy : source starting coordinate -- need not be on a valid image pixel 6 nx, ny : number of source pixels -- currently must not go out of bounds -> allow out-of-bounds 7 Sx, Sy : target starting coordinate -- need not be on a valid image pixel 8 Nx, Ny : redundant information UNLESS <to> does exist (in which case it is required information) -> make Nx,Ny optional if <to> exists? 9 */ 2 10 3 11 int extract (int argc, char **argv) { 4 12 5 int i, j; 6 float *Vin, *Vout; 7 int sx, sy, nx, ny, NX, NY; 8 int Sx, Sy, Nx, Ny; 13 int N; 9 14 Buffer *in, *out; 15 16 float initValue = 0.0; 17 int initOutput = FALSE; 18 if ((N = get_argument (argc, argv, "-init"))) { 19 remove_argument (N, &argc, argv); 20 initValue = atof (argv[N]); 21 remove_argument (N, &argc, argv); 22 initOutput = TRUE; 23 } 10 24 11 25 if (argc != 11) { … … 15 29 16 30 if ((in = SelectBuffer (argv[1], OLDBUFFER, TRUE)) == NULL) return (FALSE); 17 NX = in[0].matrix.Naxis[0];18 NY = in[0].matrix.Naxis[1];31 int NX = in[0].matrix.Naxis[0]; 32 int NY = in[0].matrix.Naxis[1]; 19 33 20 sx = atof (argv[3]);21 sy = atof (argv[4]);22 nx = atof (argv[5]);23 ny = atof (argv[6]);34 int sx = atof (argv[3]); 35 int sy = atof (argv[4]); 36 int nx = atof (argv[5]); 37 int ny = atof (argv[6]); 24 38 25 Sx = atof (argv[7]);26 Sy = atof (argv[8]);27 Nx = atof (argv[9]);28 Ny = atof (argv[10]);39 int Sx = atof (argv[7]); 40 int Sy = atof (argv[8]); 41 int Nx = atof (argv[9]); 42 int Ny = atof (argv[10]); 29 43 30 44 if ((Sy + ny > Ny) || (Sx + nx > Nx)) { 31 gprint (GP_ERR, " mismatch between source and dest regions\n");45 gprint (GP_ERR, "source pixels extend beyond target pixels\n"); 32 46 gprint (GP_ERR, "%d + %d > %d or %d + %d > %d\n", Sy, ny, Ny, Sx, nx, Nx); 33 return (FALSE);47 // return (FALSE); 34 48 } 49 50 // XXX : allow source region to fall outside source image 35 51 36 52 /* region is not on first image */ … … 39 55 (sy > in[0].matrix.Naxis[1])) { 40 56 gprint (GP_ERR, "region outside of source image\n"); 41 return (FALSE);57 // return (FALSE); 42 58 } 43 59 44 if ((Sx + nx > Nx) || (Sy + ny > Ny)) {45 gprint (GP_ERR, "source region larger than dest region\n");46 return (FALSE);47 }48 60 if ((Sx < 0) || (Sy < 0)) { 49 61 gprint (GP_ERR, "dest region out of range\n"); 50 return (FALSE);62 // return (FALSE); 51 63 } 52 64 … … 76 88 } 77 89 78 for (j = 0; j < ny; j++) { 79 if (j + sy < 0) continue; 80 if (j + sy >= NY) continue; 81 Vin = (float *)(in[0].matrix.buffer) + (j + sy)*in[0].matrix.Naxis[0] + sx; 82 Vout = (float *)(out[0].matrix.buffer) + (j + Sy)*out[0].matrix.Naxis[0] + Sx; 83 for (i = 0; i < nx; i++, Vin++, Vout++) { 90 // (NX,NY) : source image dimensions 91 // (Nx,Ny) : target image dimensions 92 93 // allow (sx, sy), (Sx, Sy) to be off image 94 // allow (sx+nx, sy+ny) to be off image 95 96 // if (sx < 0) { 97 // nx += sx; 98 // sx = 0; 99 // } 100 // if (sx > NX) sx = NX; 101 // 102 // if (Sx < 0) { 103 // Nx += sx; 104 // sx = 0; 105 // } 106 // if (sx > NX) sx = NX; 107 108 float *Vin = (float *)(in[0].matrix.buffer); 109 float *Vout = (float *)(out[0].matrix.buffer); 110 111 if (initOutput) { 112 for (int j = 0; j < Ny; j++) { 113 for (int i = 0; i < Nx; i++) { 114 Vout[i + Nx*j] = initValue; 115 } 116 } 117 } 118 119 int Nps = NX*NY; 120 int Npt = Nx*Ny; 121 122 for (int j = 0; j < ny; j++) { 123 if (j + sy < 0) continue; // not yet on source image 124 if (j + Sy < 0) continue; // not yet on target image 125 if (j + sy >= NY) continue; // past edge of source image 126 if (j + Sy >= Ny) continue; // past edge of target image 127 128 // Vin = (float *)(in[0].matrix.buffer) + (j + sy)*in[0].matrix.Naxis[0] + sx; 129 // Vout = (float *)(out[0].matrix.buffer) + (j + Sy)*out[0].matrix.Naxis[0] + Sx; 130 131 for (int i = 0; i < nx; i++) { 84 132 if (i + sx < 0) continue; 85 133 if (i + sx >= NX) continue; 86 *Vout = *Vin; 134 if (i + Sx < 0) continue; 135 if (i + Sx >= Nx) continue; 136 137 int ps = i + sx + (j + sy)*NX; 138 int pt = i + Sx + (j + Sy)*Nx; 139 140 myAssert (pt >= 0, "oops 1"); 141 myAssert (pt < Npt, "oops 2"); 142 143 myAssert (ps >= 0, "oops 3"); 144 myAssert (ps < Nps, "oops 4"); 145 146 Vout[pt] = Vin[ps]; 87 147 } 88 148 } … … 91 151 92 152 } 93
Note:
See TracChangeset
for help on using the changeset viewer.
