- Timestamp:
- Mar 24, 2010, 4:56:11 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20100225/psphot/src/psphotSourceSize.c
r27270 r27440 23 23 bool psphotMaskCosmicRay (pmReadout *readout, pmSource *source, psImageMaskType maskVal); 24 24 bool psphotMaskCosmicRayFootprintCheck (psArray *sources); 25 int psphotMaskCosmicRayConnected (int xPeak, int yPeak, psImage *mymask, psImage *myvar, psImage *edges, int binning, float sigma_thresh); 25 26 26 27 // we need to call this function after sources have been fitted to the PSF model and … … 252 253 253 254 # define SIZE_SN_LIM 10 254 255 255 bool psphotSourceClassRegion (psRegion *region, pmPSFClump *psfClump, psArray *sources, psMetadata *recipe, pmPSF *psf, psphotSourceSizeOptions *options) { 256 256 … … 484 484 485 485 // XXX test : save the mask image 486 if ( 1) {486 if (0) { 487 487 psphotSaveImage (NULL, readout->mask, "mask.fits"); 488 488 } … … 491 491 } 492 492 493 # define DUMPPICS 0 493 494 # define LIMIT_XRANGE(X, IMAGE) { X = PS_MIN(PS_MAX(0, X), IMAGE->numCols); } 494 495 # define LIMIT_YRANGE(Y, IMAGE) { Y = PS_MIN(PS_MAX(0, Y), IMAGE->numRows); } … … 524 525 int binning = 2; 525 526 float sigma_thresh = 3.0; 526 int max_iter = 5; 527 float noise_factor = 5.0 / 4.0; // Intrinsic to the Laplacian making noise spikes spikier. 527 int max_iter = 1; // XXX with isophot masking, we only want to do a single pass 528 528 529 529 // Temporary images. … … 591 591 } 592 592 593 // Modify my mask if we're above the significance threshold 594 for (int y = 0; y < dy; y++) { 595 for (int x = 0; x < dx; x++) { 596 if (!(mymask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & 0x01)) continue; 597 598 float noise = binning * sqrt(noise_factor * myvar->data.F32[y][x]); 599 float value = edges->data.F32[y][x] / noise; 600 601 if (value > sigma_thresh ) { 602 mymask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] |= 0x40; 603 nCRpix ++; 604 } 605 } 606 } 607 608 # if 1 593 // coordinate of peak in subimage pixels: 594 int xPeak = peak->x - xs; 595 int yPeak = peak->y - ys; 596 597 // Modify my mask if we're above the significance threshold, but only for connected pixels 598 nCRpix = psphotMaskCosmicRayConnected (xPeak, yPeak, mymask, myvar, edges, binning, sigma_thresh); 599 600 # if DUMPPICS 609 601 psphotSaveImage (NULL, mypix, "crmask.pix.fits"); 610 602 # endif 611 603 604 // XXX do not repair the pixels in isophot version 605 # if 0 612 606 // "Repair" Masked pixels for the next round. 613 607 for (int y = 1; y < dy - 1; y++) { … … 629 623 } 630 624 } 631 632 # if 1 625 # endif 626 627 # if DUMPPICS 633 628 fprintf (stderr, "CRMASK %d %d %d %d %d\n", xs, ys, dx, dy, iteration); 634 629 psphotSaveImage (NULL, mypix, "crmask.fix.fits"); … … 642 637 } 643 638 639 # if 0 644 640 // A solitary masked pixel is likely a lie. Remove those 645 641 // XXX can't we use nCRpix == 1 to test for these? … … 662 658 } 663 659 } 660 # endif 664 661 665 662 // transfer temporary mask to real mask & count masked pixels … … 677 674 if (nCRpix > 1) { 678 675 source->mode |= PM_SOURCE_MODE_CR_LIMIT; 679 } 676 source->tmpFlags |= PM_SOURCE_TMPF_SIZE_MEASURED; 677 } 678 // fprintf (stderr, "CRMASK %d %d %d %d %d\n", peak->x, peak->y, dx, dy, nCRpix); 680 679 681 680 psFree(mypix); … … 753 752 } 754 753 754 # define VERBOSE 0 755 int psphotMaskCosmicRayConnected (int xPeak, int yPeak, psImage *mymask, psImage *myvar, psImage *edges, int binning, float sigma_thresh) { 756 757 int xLo, xRo; 758 int nCRpix = 0; 759 760 float noise_factor = 5.0 / 4.0; // Intrinsic to the Laplacian making noise spikes spikier. 761 762 // mark the pixels in this row to the left, then the right. stay within footprint 763 int xL = xPeak; // find the range of valid pixels in this row 764 int xR = xPeak; 765 for (int ix = xPeak; (ix >= 0) && (mymask->data.PS_TYPE_IMAGE_MASK_DATA[yPeak][ix] & 0x01); ix--) { 766 float noise = binning * sqrt(noise_factor * myvar->data.F32[yPeak][ix]); 767 float value = edges->data.F32[yPeak][ix] / noise; 768 if (value < sigma_thresh ) break; 769 mymask->data.PS_TYPE_IMAGE_MASK_DATA[yPeak][ix] |= 0x40; 770 xL = ix; 771 nCRpix ++; 772 if (VERBOSE) fprintf (stderr, "mark %d,%d (%d) : %d - %d\n", ix, yPeak, nCRpix, xL, xR); 773 } 774 for (int ix = xPeak; (ix < mymask->numCols) && (mymask->data.PS_TYPE_IMAGE_MASK_DATA[yPeak][ix] & 0x01); ix++) { 775 float noise = binning * sqrt(noise_factor * myvar->data.F32[yPeak][ix]); 776 float value = edges->data.F32[yPeak][ix] / noise; 777 if (value < sigma_thresh ) break; 778 mymask->data.PS_TYPE_IMAGE_MASK_DATA[yPeak][ix] |= 0x40; 779 xR = ix; 780 nCRpix ++; 781 if (VERBOSE) fprintf (stderr, "mark %d,%d (%d) : %d - %d\n", ix, yPeak, nCRpix, xL, xR); 782 } 783 // xL and xR mark the first and last valid pixel in the row 784 785 // for each of the neighboring rows, mark the high pixels if they touch the range xL to xR 786 xLo = PS_MAX(xL - 1, 0); 787 xRo = PS_MIN(xR + 1, mymask->numCols); 788 789 // first go down: 790 for (int iy = yPeak - 1; iy >= 0; iy--) { 791 792 int xLn = -1; 793 int xRn = -1; 794 int newPix = 0; 795 796 // mark the pixels in the good range 797 for (int ix = xLo; ix < xRo; ix++) { 798 if (!(mymask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & 0x01)) continue; // only use pixels in the footprint 799 float noise = binning * sqrt(noise_factor * myvar->data.F32[iy][ix]); 800 float value = edges->data.F32[iy][ix] / noise; 801 if (value < sigma_thresh ) continue; 802 mymask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= 0x40; 803 if (xLn == -1) xLn = ix; // first valid pixel in this row 804 xRn = ix; // last valid pixel in this row 805 nCRpix ++; 806 newPix ++; 807 if (VERBOSE) fprintf (stderr, "mark C %d,%d (%d) : %d - %d | %d - %d | %d - %d \n", ix, iy, nCRpix, xL, xR, xLo, xRo, xLn, xRn); 808 } 809 810 // mark the pixels to the left of the good range 811 for (int ix = xLo; (ix >= 0) && (mymask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & 0x01); ix--) { 812 float noise = binning * sqrt(noise_factor * myvar->data.F32[iy][ix]); 813 float value = edges->data.F32[iy][ix] / noise; 814 if (value < sigma_thresh ) break; 815 mymask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= 0x40; 816 if (xRn == -1) xRn = ix; // last valid pixel in this row 817 xLn = ix; 818 nCRpix ++; 819 newPix ++; 820 if (VERBOSE) fprintf (stderr, "mark L %d,%d (%d) : %d - %d | %d - %d | %d - %d \n", ix, iy, nCRpix, xL, xR, xLo, xRo, xLn, xRn); 821 } 822 823 // mark the pixels to the right of the good range 824 for (int ix = xRo; (ix < mymask->numCols) && (mymask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & 0x01); ix++) { 825 float noise = binning * sqrt(noise_factor * myvar->data.F32[iy][ix]); 826 float value = edges->data.F32[iy][ix] / noise; 827 if (value < sigma_thresh ) break; 828 mymask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= 0x40; 829 if (xLn == -1) xLn = ix; // first valid pixel in this row 830 xRn = ix; 831 nCRpix ++; 832 newPix ++; 833 if (VERBOSE) fprintf (stderr, "mark R %d,%d (%d) : %d - %d | %d - %d | %d - %d \n", ix, iy, nCRpix, xL, xR, xLo, xRo, xLn, xRn); 834 } 835 if (newPix == 0) break; 836 xLo = PS_MAX(xLn - 1, 0); 837 xRo = PS_MIN(xRn + 1, mymask->numCols); 838 } 839 840 xLo = PS_MAX(xL - 1, 0); 841 xRo = PS_MIN(xR + 1, mymask->numCols); 842 843 // next go up: 844 for (int iy = yPeak + 1; iy < mymask->numRows; iy++) { 845 846 int xLn = -1; 847 int xRn = -1; 848 int newPix = 0; 849 850 // mark the pixels in the good range 851 for (int ix = xLo; ix < xRo; ix++) { 852 if (!(mymask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & 0x01)) continue; // only use pixels in the footprint 853 float noise = binning * sqrt(noise_factor * myvar->data.F32[iy][ix]); 854 float value = edges->data.F32[iy][ix] / noise; 855 if (value < sigma_thresh ) continue; 856 mymask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= 0x40; 857 if (xLn == -1) xLn = ix; // first valid pixel in this row 858 xRn = ix; // last valid pixel in this row 859 nCRpix ++; 860 newPix ++; 861 if (VERBOSE) fprintf (stderr, "mark C %d,%d (%d) : %d - %d | %d - %d | %d - %d \n", ix, iy, nCRpix, xL, xR, xLo, xRo, xLn, xRn); 862 } 863 864 // mark the pixels to the left of the good range 865 for (int ix = xLo; (ix >= 0) && (mymask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & 0x01); ix--) { 866 float noise = binning * sqrt(noise_factor * myvar->data.F32[iy][ix]); 867 float value = edges->data.F32[iy][ix] / noise; 868 if (value < sigma_thresh ) break; 869 mymask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= 0x40; 870 if (xRn == -1) xRn = ix; // last valid pixel in this row 871 xLn = ix; 872 nCRpix ++; 873 newPix ++; 874 if (VERBOSE) fprintf (stderr, "mark L %d,%d (%d) : %d - %d | %d - %d | %d - %d \n", ix, iy, nCRpix, xL, xR, xLo, xRo, xLn, xRn); 875 } 876 877 // mark the pixels to the right of the good range 878 for (int ix = xRo; (ix < mymask->numCols) && (mymask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & 0x01); ix++) { 879 float noise = binning * sqrt(noise_factor * myvar->data.F32[iy][ix]); 880 float value = edges->data.F32[iy][ix] / noise; 881 if (value < sigma_thresh ) break; 882 mymask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= 0x40; 883 if (xLn == -1) xLn = ix; // first valid pixel in this row 884 xRn = ix; 885 nCRpix ++; 886 newPix ++; 887 if (VERBOSE) fprintf (stderr, "mark R %d,%d (%d) : %d - %d | %d - %d | %d - %d \n", ix, iy, nCRpix, xL, xR, xLo, xRo, xLn, xRn); 888 } 889 if (newPix == 0) break; 890 xLo = PS_MAX(xLn - 1, 0); 891 xRo = PS_MIN(xRn + 1, mymask->numCols); 892 } 893 894 return nCRpix; 895 } 896 755 897 bool psphotMaskCosmicRayIsophot (pmSource *source, psImageMaskType maskVal, psImageMaskType crMask) { 756 898
Note:
See TracChangeset
for help on using the changeset viewer.
