Thanks a lot for your response; I’d appreciate it.

I can get the idea of why we choose 0 and 48. We add 47 to each x and y, and since tf.random.uniform accepts the distribution in the range [minval, maxval), the maxval should be 48, and then we can get the max 47.

Regarding the decision by 75, I still don’t get it totally. As far as I understand, each pixel’s value stays in range (0, 254), so we divide it by 255 to normalize the value, and we apply this division to all pixels despite an image’s width and height.

Here, [x|y][min|max] is simply a coordinate of one random point on the XY coordinate system:

The reason we normalize them is that it will be easier to feed NN later.

And the range of the new canvas’ X-axis and Y-axis is (0,74), we will divide them by 75. If there is another image with a different size like (16, 32), we will divide x by 32 and y by 16.

Am I correct?

In addition, I would like to ask why we need to subtract an image by 1 (line 11), after the normalization step. Is it a compulsory or optional step?

On the minus 1 operation, it follows the standard transformation that consists of scaling + centering: first we scale the image by dividing against 127.5, then center the image by minusing 1. The resulting range would be different from say, just dividing by 255, which is more often.