IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 12, 2005, 3:49:21 PM (21 years ago)
Author:
eugene
Message:

rework with masks and noise array

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/psphot-utils.c

    r4215 r4216  
    129129}
    130130
     131bool DumpImage (psImage *image, char *filename) {
     132
     133    unlink (filename);
     134    psFits *fits = psFitsAlloc (filename);
     135    psFitsWriteImage (fits, NULL, image, 0, NULL);
     136    psFree (fits);
     137    return;
     138}
     139
    131140void pmSourceMaskSaturated (psSource *source, float saturate) {
    132141
     
    142151}
    143152
    144 void pmSourceMaskRegion (psSource *source, psRegion *region) {
    145 
    146     psImage *image = source->pixels;
    147     psImage *mask  = source->mask;
     153// mask the area contained by the region
     154// the region is defined wrt the parent image
     155void psImageMaskRegion (psImage *image, psRegion *region, bool logical_and, int maskValue) {
     156
     157    for (int iy = 0; iy < image->numRows; iy++) {
     158        for (int ix = 0; ix < image->numCols; ix++) {
     159            if (ix + image->col0 <  region->x0) continue;
     160            if (ix + image->col0 >= region->x1) continue;
     161            if (iy + image->row0 <  region->y0) continue;
     162            if (iy + image->row0 >= region->y1) continue;
     163            if (logical_and) {
     164                image->data.U8[iy][ix] &= maskValue;
     165            } else {
     166                image->data.U8[iy][ix] |= maskValue;
     167            }
     168        }
     169    }
     170}
     171
     172// mask the area not contained by the region
     173// the region is defined wrt the parent image
     174void psImageKeepRegion (psImage *image, psRegion *region, bool logical_and, int maskValue) {
    148175
    149176    for (int iy = 0; iy < image->numRows; iy++) {
     
    155182            continue;
    156183        maskit:
    157             mask->data.U8[iy][ix] |= 0x02;
     184            if (logical_and) {
     185                image->data.U8[iy][ix] &= maskValue;
     186            } else {
     187                image->data.U8[iy][ix] |= maskValue;
     188            }
    158189        }
    159190    }
     
    161192
    162193// mask the area contained by the region
    163 void psImageMaskRegion (psImage *image, psRegion *region, int maskValue) {
    164 
    165     for (int iy = 0; iy < image->numRows; iy++) {
    166         for (int ix = 0; ix < image->numCols; ix++) {
    167             if (ix + image->col0 <  region->x0) continue;
    168             if (ix + image->col0 >= region->x1) continue;
    169             if (iy + image->row0 <  region->y0) continue;
    170             if (iy + image->row0 >= region->y1) continue;
    171             image->data.U8[iy][ix] |= maskValue;
    172         }
    173     }
    174 }
    175 
    176 // mask the area not contained by the region
    177 void psImageKeepRegion (psImage *image, psRegion *region, int maskValue) {
    178 
    179     for (int iy = 0; iy < image->numRows; iy++) {
    180         for (int ix = 0; ix < image->numCols; ix++) {
    181             if (ix + image->col0 <  region->x0) goto maskit;
    182             if (ix + image->col0 >= region->x1) goto maskit;
    183             if (iy + image->row0 <  region->y0) goto maskit;
    184             if (iy + image->row0 >= region->y1) goto maskit;
    185             continue;
    186         maskit:
    187             image->data.U8[iy][ix] |= maskValue;
     194// the region is defined wrt the parent image
     195void psImageMaskCircle (psImage *image, double x, double y, double radius, bool logical_and, int maskValue) {
     196
     197    double R2 = PS_SQR(radius);
     198
     199    for (int iy = 0; iy < image->numRows; iy++) {
     200        for (int ix = 0; ix < image->numCols; ix++) {
     201            dx = ix + image->col0 - x;
     202            dy = iy + image->row0 - y;
     203            r2 = PS_SQR(dx) + PS_SQR(dy);
     204            if (r2 > R2) continue;
     205            if (logical_and) {
     206                image->data.U8[iy][ix] &= maskValue;
     207            } else {
     208                image->data.U8[iy][ix] |= maskValue;
     209            }
     210        }
     211    }
     212}
     213
     214// mask the area contained by the region
     215// the region is defined wrt the parent image
     216void psImageKeepCircle (psImage *image, double x, double y, double radius, bool logical_and, int maskValue) {
     217
     218    double R2 = PS_SQR(radius);
     219
     220    for (int iy = 0; iy < image->numRows; iy++) {
     221        for (int ix = 0; ix < image->numCols; ix++) {
     222            dx = ix + image->col0 - x;
     223            dy = iy + image->row0 - y;
     224            r2 = PS_SQR(dx) + PS_SQR(dy);
     225            if (r2 < R2) continue;
     226            if (logical_and) {
     227                image->data.U8[iy][ix] &= maskValue;
     228            } else {
     229                image->data.U8[iy][ix] |= maskValue;
     230            }
    188231        }
    189232    }
Note: See TracChangeset for help on using the changeset viewer.