IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 10553


Ignore:
Timestamp:
Dec 8, 2006, 1:54:05 AM (20 years ago)
Author:
eugene
Message:

added FITTED_MEAN_V2
changed psVectorStats return to bool
added code to handle failures in psVectorStats:

  • set the superpixel to NAN in the main loop
  • attempt to patch NAN superpixels by averaging neighbors
  • patch remaining NAN pixels with global median
File:
1 edited

Legend:

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

    r10437 r10553  
    4040    }
    4141    psStatsOptions statsOption = psStatsOptionFromString (statsName);
    42     if (!(statsOption & (PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_MEDIAN | PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_QUARTILE | PS_STAT_CLIPPED_MEAN | PS_STAT_FITTED_MEAN))) {
     42    if (!(statsOption & (PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_MEDIAN | PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_QUARTILE | PS_STAT_CLIPPED_MEAN | PS_STAT_FITTED_MEAN | PS_STAT_FITTED_MEAN_V2))) {
    4343        statsOption = PS_STAT_FITTED_MEAN;
    4444    }
     
    141141                stats->options |= PS_STAT_ROBUST_MEDIAN;
    142142                if (!psImageBackground(stats, subset, submask, 0xff, rng)) {
    143                     psAbort(PS_FILE_LINE, "Failed to estimate background using ROBUST_MEDIAN for "
    144                             "(%dx%d, (row0,col0) = (%d,%d)",
    145                             subset->numRows, subset->numCols, subset->row0, subset->col0);
     143                    psLogMsg ("psphot", PS_LOG_WARN, "Failed to estimate background using ROBUST_MEDIAN for "
     144                               "(%dx%d, (row0,col0) = (%d,%d)",
     145                               subset->numRows, subset->numCols, subset->row0, subset->col0);
     146                    modelData[iy][ix] = NAN;
     147                } else {
     148                    modelData[iy][ix] = psStatsGetValue (stats, PS_STAT_ROBUST_MEDIAN);
    146149                }
    147                 modelData[iy][ix] = psStatsGetValue (stats, PS_STAT_ROBUST_MEDIAN);
     150                psErrorClear(); // drop errors caused by this condition
    148151                stats->options = currentOptions;
    149152            }
     
    158161            // backMdl->data.F32[iy][ix] = stats->clippedMean;
    159162        }
     163    }
     164
     165    // patch over bad regions (use average of 8 possible neighbor pixels)
     166    float Count = 0;
     167    float Value = 0;
     168    for (int iy = 0; iy < ny; iy++) {
     169        for (int ix = 0; ix < nx; ix++) {
     170            if (!isnan(modelData[iy][ix])) {
     171                Value += modelData[iy][ix];
     172                Count += 1;
     173                continue;
     174            }
     175            float value = 0;
     176            float count = 0;
     177            for (int jy = iy - 1; jy <= iy + 1; jy++) {
     178                if (jy <   0) continue;
     179                if (jy >= ny) continue;
     180                for (int jx = ix - 1; jx <= ix + 1; jx++) {
     181                    if (!jx && !jy) continue;
     182                    if (jx   <   0) continue;
     183                    if (jx   >= nx) continue;
     184                    value += modelData[jy][jx];
     185                    count += 1.0;
     186                }
     187            }
     188            if (count > 0) modelData[iy][ix] = value / count;
     189           
     190        }
     191    }
     192    Value = Value / Count;
     193
     194    // patch over remaining bad regions (use global average)
     195    for (int iy = 0; iy < ny; iy++) {
     196        for (int ix = 0; ix < nx; ix++) {
     197            if (!isnan(modelData[iy][ix])) continue;
     198            modelData[iy][ix] = Value;
     199        }
    160200    }
    161201    psLogMsg ("psphot", 3, "build median image: %f sec\n", psTimerMark ("psphot"));
Note: See TracChangeset for help on using the changeset viewer.