Index: trunk/psphot/src/psphotSignificanceImage.c
===================================================================
--- trunk/psphot/src/psphotSignificanceImage.c	(revision 29548)
+++ trunk/psphot/src/psphotSignificanceImage.c	(revision 31154)
@@ -4,5 +4,5 @@
 // (S/N)^2.  If FWMH_X,Y have been recorded, use them, otherwise use PEAKS_SMOOTH_SIGMA for the
 // smoothing kernel.
-psImage *psphotSignificanceImage (pmReadout *readout, psMetadata *recipe, psImageMaskType maskVal) {
+pmReadout *psphotSignificanceImage (pmReadout *readout, psMetadata *recipe, psImageMaskType maskVal) {
 
     float SIGMA_SMTH, NSIGMA_SMTH;
@@ -21,4 +21,6 @@
         minGauss = 0.5;
     }
+
+    // NOTE: for a faint extended-source detection pass, we over-smooth by SOMETHING
 
     // if we have already determined the PSF model, then we have a better idea how to smooth this image
@@ -92,13 +94,18 @@
     psMetadataAddF32(readout->analysis, PS_LIST_TAIL, "SIGNIFICANCE_SCALE_FACTOR", PS_META_REPLACE, "Signicance scale factor", factor);
 
-    // XXX multithread this if needed
+    // we are going to return both the image and the weight here: the image contains the signal
+    // while the 'weight' will contain the significance (NOTE the deviation from the usual
+    // definition)
+
+    // save the smoothed significance image in the weight array
     for (int j = 0; j < smooth_im->numRows; j++) {
         for (int i = 0; i < smooth_im->numCols; i++) {
             float value = smooth_im->data.F32[j][i];
             if (value < 0 || smooth_wt->data.F32[j][i] <= 0 || (mask->data.PS_TYPE_IMAGE_MASK_DATA[j][i] & maskVal)) {
-                smooth_im->data.F32[j][i] = 0.0;
+                smooth_wt->data.F32[j][i] = 0.0;
             } else {
-		float v2 = value + PS_SQR(value/1000.0);
-                smooth_im->data.F32[j][i] = factor * PS_SQR(v2) / smooth_wt->data.F32[j][i];
+		// XXX the value of 100 here (or 1000 before) must depend on the FWHM of the smoothing kernel, right??
+		float v2 = value + PS_SQR(value/100.0);
+                smooth_wt->data.F32[j][i] = factor * PS_SQR(v2) / smooth_wt->data.F32[j][i];
             }
         }
@@ -112,13 +119,14 @@
 	static int pass = 0;
         sprintf (name, "snsmooth.v%d.fits", pass);
-        psphotSaveImage (NULL, smooth_im, name);
+        psphotSaveImage (NULL, smooth_wt, name);
 	pass ++;
     }
-
-    psFree(smooth_wt);
-
     psImageConvolveSetThreads(oldThreads);
 
-    return smooth_im;
+    pmReadout *significanceRO = pmReadoutAlloc(NULL);
+    significanceRO->variance = smooth_wt;    
+    significanceRO->image = smooth_im;    
+
+    return significanceRO;
 }
 
