How to normalize pixel value

as written in question we have to normalize pixel value between 0-1 plz explain

Hey @Jan19LPN0013, let me explain you :

Every image is made up of pixel values ranging between 0 to 255, right ?..So to normalize means bringing all the pixel values of an image in the range of (0-1). Now you can do this by using the formula given below :

X = (X - Xmin)/(Xmax - Xmin)  

Now here in case of pixels values , your Xmin=0 and your Xmax=255. So putting these values in above equation you would get :

X = X/255

Hope this helps.
Happy Learning :slight_smile:

why sir used image_data = np.array(image_data,dtype=‘float32’)/255.0

why sir used float32 in { image_data = np.array(image_data,dtype=‘float32’)/255.0 }

Sir used this to specify that the data type of all the pixel values will be float32. If you make it int32 then the decimal part goes away automatically. But we want to preserve the exact value of the pixel in decimal points.

but in one video used ‘uint8’ instead of ‘float32’ why plz explain ?

It depends on the application whether to use uint8 or to use float32. Which video are u talking about ?

i am talking about video of K-Means dominant color extraction in this video sir used uint8 why sir not used float32?

Ohh okay. Please create a new doubt regarding your query under the section of this video. I hope I have answered your major query which was, how to normalize pixel values.

Happy Learning :slight_smile:

but i only want to ask what is the use of float32 and uint8 as both of them are used to store image in array

Both the formats can be used to represent an image. If the datatype is uint8, the pixel values will range from 0-255 and if the datatype is float32 , then the pixel values range between 0-1.
This is the reason we use float32 datatype, when we normalize an image.

If you still have any doubt, then you can create a new doubt on the portal.

Happy to help.
All the best :slight_smile:

why can’t we normalize in uint8?

Because normalizing means values between 0 and 1. If you will make it uint8 then pixel values will be only 0 or 1 as values between 0 and 1 will be float and will approximate to 0 or 1 in case of uint8.