Acceptable format

What is an acceptable format to represent the image? A slice of bytes is useful for reading and displaying the image, but it's not particularly useful for doing any machine learning. Rather, we should want to represent the image as a slice of floating points. So, here's a function to convert a byte into a float64:

func pixelWeight(px byte) float64 {
retVal := float64(px)/pixelRange*0.9 + 0.1
if retVal == 1.0 {
return 0.999
}
return retVal
}

This is essentially a scaling function that scales from 0-255 to between 0.0 and 1.0. There is an additional check; if the value is 1.0, we return 0.999 instead of 1. This is mainly due to the fact that when values are 1.0, numerical instability tends to happen, as mathematical functions tend to act weirdly. So instead, replace 1.0 with values that are very close to 1.

So now, we can make a RawImage into a []float64. And because we have N images in the form of []RawImage, we can make it into a [][]float64, or a matrix.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.148.104.124