简体   繁体   中英

Confusion in Rescaling/normalization of uint16 image?

I have 15000 uint images and i have vectorized them to give it as an input to my Convolutional Neural network. [15000x8192] My question is regarding scaling as if i scale like below i get the good result

scaler= MinMaxScaler()
x_train= scaler.transform(x_train)

but if i do the following, i don't

x_train= xtrain./65535

The maximum and minimum pixel value for my images are 31,238 & 16841. Is the first approach correct while dealing with images?

I found the third approach which is below, it looks more reasonable

X_set_uint8 = cv2.normalize(X_set_16, None, 0, 255, cv2.NORM_MINMAX, dtype=cv2.CV_8U)
# Normalize pixel values to be between 0 and 1
X_set_scaled= X_train_uint8/255

All approaches should give the same performance and they are not. That's what is confusing for me.

Okay, so you've revealed you are using data from a spectrograph? Remember how I said the most important thing is to think about your data?

We know you need to normalize your data, since the network will converge faster. Ideally we want them normally distributed.

One huge problem with a spectrogram is that standard normalization techniques are of no use since the data is very heavy tailed.

You'll probably want to take an adjusted logarithm of your values: take log(x + c) where you adjust c until you see something Gaussian. A more advanced technique would be to use the Box-Cox transformation.

Now for normalizing by the min and max, you'll probably want to use the minimum and maximum values for a spectrogram instead of what your data shows.


This answer to this depends on the nature of your input data. Note the answer below applies to both classification tasks and regression tasks.

  1. Go from 16-bit to 8-bit color unless you really believe there's information worth capturing in the 16-bit color. (I doubt it.)
  2. Do you want to normalize for color brightness/saturation across your images? Use min/max scaler. This will protect against saturation having an effect on classification.
  3. Do you think saturation/brightness is a feature and your data should span the entire color space? Then stick to [0, 255] or [0, 635535].
  4. Just an addendum: For certain classifiers, it's also worth looking into Transformed = (I - I.mean) / I.std since they expect Gaussian data.

Remember, the goal of normalization is to scale your domain down to [0, 1]. You should always think about how the transformation will effect in sample and possible out of sample images. What will you teach the model? Do out of sample images fall in that same image space? What possible transformations might best map the training and out-of-sample images to a similar domain?

The MinMaxScaler will (by default) transform every feature (in this case pixels) to the range [0,1] .

Whereas in your second approach you just transform all the values to the range [0.257,0.477] independently to which feature they belong.

Since you're dealing with images, it can make sense to do a simple min-max-scaling regardless of features since you like to maintain the differences of intensities among pixels:

x_train = (x_train - x_train.min())/(x_train.max() - x_train.min())

This formula is equivalent to your second approach, if max = 65535 and min = 0 of your image data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM