Just I verified picnic application with converting from RGB to Gray scale, it works fine, so coding logic should be correct.
Are you getting any error in the result of this function?
That's true. We will fix it. Probably, there were assertions before with "assert(NChannels==3 || NChannels==4)". When substituting with "if", the expression must be turned inside out completely "NChannels!=3 && NChannels!=4"