Index: /trunk/ppbgrestore/src/ppbgrestoreLoop.c
===================================================================
--- /trunk/ppbgrestore/src/ppbgrestoreLoop.c	(revision 25973)
+++ /trunk/ppbgrestore/src/ppbgrestoreLoop.c	(revision 25974)
@@ -113,11 +113,11 @@
         for (int y = 0; y < numRows; y++) {
             for (int x = 0; x < numCols; x++) {
-                float value = backData[y][x];
-                if (!isfinite(value)) {
+                float imageval =  image->data.F32[y][x] ;
+                float bgvalue = backData[y][x];
+                if (!isfinite(bgvalue)) {
                     // if background is NAN leave the image unchanged
                     // According to ppImageSubtractBackground pixels where the background is not finite should be NAN
                     // experimentally
                     // for breakpoint
-                    float imageval =  image->data.F32[y][x] ;
                     nancount++;
                     if (isfinite(imageval)) {
@@ -128,7 +128,7 @@
                     //      NANS are appearing in the model for some reason.
                     //      image->data.F32[y][x] = NAN;
-                } else {
+                } else if (isfinite(imageval)) {
                     // XXX: TODO:following ppImage we should not modify pixels that are masked.
-                    image->data.F32[y][x] += value;
+                    image->data.F32[y][x] += bgvalue;
                 }
             }
