Reputation: 1462
I am following the Deep Learning course on Udacity. I am slightly confused about pixel depth
and how it is being used in below code:
image_size = 28 # Pixel width and height.
pixel_depth = 255.0 # Number of levels per pixel.
image_data = (ndimage.imread(image_file).astype(float) -
pixel_depth / 2) / pixel_depth
Can someone explain me why we are doing pixel_depth / 2) / pixel_depth
while reading the image into N-d array?
Upvotes: 0
Views: 264
Reputation: 2790
Pixel depth is the number of values that a pixel can take. For 8-bits images, this is 256 (but they use 255 here).
The code here is used to normalize and center the pixel values into the interval [-0.5,0.5].
Upvotes: 1
Reputation:
Depth in CV just refers to the data type. Depth of 255.0 implies 8-bits for each pixel and so on.
pixel_depth / 2) / pixel_depth
This bit of code seems a little weird at first but it's purpose is to normalize the image to a range of -0.5 to 0.5, which is a common tactic to simplify image processing.
Upvotes: 1