Dealing with NaN pixels
Here's an approach to dealing with the occasional NaN pixel that can for example crop up when outputting through the ScanlineRender node.
So what does it look like and why is it bad? On the left, the pixel sampler has selected a single NaN pixel being output through the ScanlineRender node and you can see that the information being displayed for that pixel is "nan" in each channel. And on the right is with VectorBlur added:


As you can see any kind of filtering will turn up as nasty blocky artefacts (in this case blocky motion blur) and suddenly the effect of the NaN pixel is much more apparent. Luckily Nuke has some handy expressions for dealing with them in an elegant way:
1 |
isnan(r) |
The Expression node shown on the right is using the expression isnan(r), adjusted accordingly for rgba channels, to show us the NaN pixels:


Now that the pixel is isolated, we need to do that in the context of the original image. By using a conditional statement we can say that if there is a NaN pixel then make it black, otherwise keep the existing pixel value for that channel:
1 |
isnan(r)?0:r |
The conditional takes the form of if?then:else so in this case we are saying "if the pixel is a NaN then make it black, or else just leave it at its current value".


So now we get our image back and the problematic NaN is neutralised to a black value which is not going to blow out when filtered. But ideally we want to procedurally clone the colour from an adjacent pixel. We can use an expression to tell a pixel to grab its colour from a given xy coordinate offset like this:
1 |
r(x+1, y) |
This will pull the pixel in the red channel from the current xy position but with an offset of +1 in x. Once that's wrapped into our existing conditional it looks like this:
1 |
isnan(r)?r(x+1,y):r |


To abstract the expressions a bit for the sake of usability we can create x and y offset knobs (xo and yo) as shown in the image on the left and then modify the expressions to take advantage of that (as shown in the image on the right):
1 |
isnan(r)?r(x+xo,y+yo):r |

