I would like to understand why the author uses the below line of code (and these exact values) in the file C1_W4_Lab_1_image_generator_no_validation.ipynb. Under #Tile the images in this matrix
x*=64
x+=128
I tried tuning this value with different values, but the proposed value suits so perfectly that I claim it was supposed to be a result of a large trial and error.
But what should be the good tipping point when I solve a similar use case?
Mentors, Could I get some clarifications on this topic, please?
Assuming that the feature values are normally distributed, 95% of feature values should lie within 2 standard deviations of the mean. When we perform \frac{x - \mu}{\sigma}, 95% of values are expected to lie in range [-2, 2].
Multiplying this range by 64 makes the range of values fall in [-128, 128].
Adding 128 now changes the range to [0, 256].
Clipping to 0, 255 limits all values to [0, 255] which is the range of values allowed for imshow
.
Here’s the doc for the array input of `imshow:
Parameters
----------
X : array-like or PIL image
The image data. Supported array shapes are:
- (M, N): an image with scalar data. The values are mapped to
colors using normalization and a colormap. See parameters *norm*,
*cmap*, *vmin*, *vmax*.
- (M, N, 3): an image with RGB values (0-1 float or 0-255 int).
- (M, N, 4): an image with RGBA values (0-1 float or 0-255 int),
i.e. including transparency.