the division by iM is what causes the -nan. I bumped into this by accident when processing a blank image which was not supposed to be blank. Is this a bug? Area image is below.
Not really a bug. NaN often comes with undefined behaviors in C/C++, particularly when aggressive optimizations (like -O3) are used when compiling (which is the case for G’MIC).
I can’t tell exactly what is going on here, but if you use label_fg (native function) in a 10x10 image of -nan, you get indeed consecutive pixels with the same value, at the location of the small segment you see on the right:
$ gmic 10,10,1,1,-nan label_fg 0,0
This is hard to see in a first glance, but this command does not generate an image going continuously from 0 to 99.
See, top-left pixel is 1, which is the min value, and bottom-right pixel is 99, which is the max value. Pixels located at (8,4) and (9,4) have the same value 49.
labe_fg implements a forward/backward scanline pass over the image and do some tricky computations to mix the two passes. not sure what is going on, but as long as NaN is involved in a math operation, you cannot expect something very precise