IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 14, 2005, 3:23:24 AM (21 years ago)
Author:
eugene
Message:

mask/noise are working

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/psUtils.c

    r4188 r4251  
    11# include "psphot.h"
    2 
    3 // set actual region based on image parameters
    4 // XXX EAM : this needs to be changes to use psRegion rather than psRegion*
    5 psRegion *psRegionForImage (psRegion *out, psImage *image, psRegion *in) {
    6    
    7     if (out == NULL) {
    8         out = psRegionAlloc(in->x0, in->x1, in->y0, in->y1);
    9     } else {
    10         *out = *in;
    11     }
    12     if (out->x1 <= 0) {
    13         out->x1 = image->numCols + out->x1;
    14     }
    15     if (out->y1 <= 0) {
    16         out->y1 = image->numRows + out->y1;
    17     }
    18     return (out);
    19 }
    202
    213static psHash *timers = NULL;
     
    336318  return (false);
    337319}           
     320
     321// define a square region centered on the given coordinate
     322psRegion *psRegionSquare (psF32 x, psF32 y, psF32 radius) {
     323    psRegion *region;
     324    region = psRegionAlloc (x - radius, x + radius + 1,   
     325                            y - radius, y + radius + 1);
     326    return (region);
     327}
     328
     329// set actual region based on image parameters:
     330// compensate for negative upper limits
     331// XXX this is inconsistent: the coordindates should always be in the parent
     332//     frame, which means the negative values should subtract from Nx,Ny of
     333//     the parent, not the child.  but, we don't carry the dimensions of the
     334//     parent in the psImage container.  for now, us the child Nx,Ny
     335// force range to be on this subimage
     336// XXX EAM : this needs to be changes to use psRegion rather than psRegion*
     337psRegion *psRegionForImage (psRegion *out, psImage *image, psRegion *in) {
     338   
     339    // x0,y0, x1,y1 are in *parent* units
     340
     341    if (out == NULL) {
     342        out = psRegionAlloc(in->x0, in->x1, in->y0, in->y1);
     343    } else {
     344        *out = *in;
     345    }
     346    // XXX these are probably wrong (see above)
     347    if (out->x1 <= 0) {
     348        out->x1 = image->col0 + image->numCols + out->x1;
     349    }
     350    if (out->y1 <= 0) {
     351        out->y1 = image->row0 + image->numRows + out->y1;
     352    }
     353
     354    // force the lower-limits to be on the child
     355    out->x0 = PS_MAX(image->col0, out->x0);
     356    out->y0 = PS_MAX(image->row0, out->y0);
     357
     358    // force the upper-limits to be on the child
     359    out->x1 = PS_MIN(image->col0 + image->numCols, out->x1);
     360    out->y1 = PS_MIN(image->row0 + image->numRows, out->y1);
     361    return (out);
     362}
     363
     364// mask the area contained by the region
     365// the region is defined wrt the parent image
     366void psImageMaskRegion (psImage *image, psRegion *region, bool logical_and, int maskValue) {
     367
     368    for (int iy = 0; iy < image->numRows; iy++) {
     369        for (int ix = 0; ix < image->numCols; ix++) {
     370            if (ix + image->col0 <  region->x0) continue;
     371            if (ix + image->col0 >= region->x1) continue;
     372            if (iy + image->row0 <  region->y0) continue;
     373            if (iy + image->row0 >= region->y1) continue;
     374            if (logical_and) {
     375                image->data.U8[iy][ix] &= maskValue;
     376            } else {
     377                image->data.U8[iy][ix] |= maskValue;
     378            }
     379        }
     380    }
     381}
     382
     383// mask the area not contained by the region
     384// the region is defined wrt the parent image
     385void psImageKeepRegion (psImage *image, psRegion *region, bool logical_and, int maskValue) {
     386
     387    for (int iy = 0; iy < image->numRows; iy++) {
     388        for (int ix = 0; ix < image->numCols; ix++) {
     389            if (ix + image->col0 <  region->x0) goto maskit;
     390            if (ix + image->col0 >= region->x1) goto maskit;
     391            if (iy + image->row0 <  region->y0) goto maskit;
     392            if (iy + image->row0 >= region->y1) goto maskit;
     393            continue;
     394        maskit:
     395            if (logical_and) {
     396                image->data.U8[iy][ix] &= maskValue;
     397            } else {
     398                image->data.U8[iy][ix] |= maskValue;
     399            }
     400        }
     401    }
     402}
     403
     404// mask the area contained by the region
     405// the region is defined wrt the parent image
     406void psImageMaskCircle (psImage *image, double x, double y, double radius, bool logical_and, int maskValue) {
     407
     408    double dx, dy, r2, R2;
     409
     410    R2 = PS_SQR(radius);
     411
     412    for (int iy = 0; iy < image->numRows; iy++) {
     413        for (int ix = 0; ix < image->numCols; ix++) {
     414            dx = ix + image->col0 - x;
     415            dy = iy + image->row0 - y;
     416            r2 = PS_SQR(dx) + PS_SQR(dy);
     417            if (r2 > R2) continue;
     418            if (logical_and) {
     419                image->data.U8[iy][ix] &= maskValue;
     420            } else {
     421                image->data.U8[iy][ix] |= maskValue;
     422            }
     423        }
     424    }
     425}
     426
     427// mask the area contained by the region
     428// the region is defined wrt the parent image
     429void psImageKeepCircle (psImage *image, double x, double y, double radius, bool logical_and, int maskValue) {
     430
     431    double dx, dy, r2, R2;
     432
     433    R2 = PS_SQR(radius);
     434
     435    for (int iy = 0; iy < image->numRows; iy++) {
     436        for (int ix = 0; ix < image->numCols; ix++) {
     437            dx = ix + image->col0 - x;
     438            dy = iy + image->row0 - y;
     439            r2 = PS_SQR(dx) + PS_SQR(dy);
     440            if (r2 < R2) continue;
     441            if (logical_and) {
     442                image->data.U8[iy][ix] &= maskValue;
     443            } else {
     444                image->data.U8[iy][ix] |= maskValue;
     445            }
     446        }
     447    }
     448}
     449
Note: See TracChangeset for help on using the changeset viewer.