Index: /trunk/stac/src/stacRejection.c
===================================================================
--- /trunk/stac/src/stacRejection.c	(revision 7542)
+++ /trunk/stac/src/stacRejection.c	(revision 7543)
@@ -144,6 +144,10 @@
                                     // Calculate the gradient
                                     grads->data.F32[j] = stacGradient(inputs->data[j], xPix, yPix);
-                                    gradsMask->data.U8[j] = 0;
-                                    numGrads++;
+                                    if (finite(grads->data.F32[j])) {
+                                        gradsMask->data.U8[j] = 0;
+                                        numGrads++;
+                                    } else {
+                                        gradsMask->data.U8[j] = 1;
+                                    }
                                 } else {
                                     gradsMask->data.U8[j] = 1; // Mask this one
