cv2.normalize()

array = cv2.normalize(array,None,0,255,cv2.NORM_MINMAX)

代码示例


import cv2 
test_set = torchvision.datasets.CIFAR10(root='../datasets', train=False, download=False, transform=None)
x = train_set.data[0]
x = x / 255.
x
array([[[0.23137255, 0.24313725, 0.24705882],
    [0.16862745, 0.18039216, 0.17647059],
    [0.19607843, 0.18823529, 0.16862745],
    ...,
    [0.61960784, 0.51764706, 0.42352941],
    [0.59607843, 0.49019608, 0.4       ],
    [0.58039216, 0.48627451, 0.40392157]],
   [[0.0627451 , 0.07843137, 0.07843137],
    [0.        , 0.        , 0.        ],
    [0.07058824, 0.03137255, 0.        ],
    ...,
    [0.48235294, 0.34509804, 0.21568627],
    [0.46666667, 0.3254902 , 0.19607843],
    [0.47843137, 0.34117647, 0.22352941]],
   [[0.09803922, 0.09411765, 0.08235294],
    [0.0627451 , 0.02745098, 0.        ],
    [0.19215686, 0.10588235, 0.03137255],
    ...,
    [0.4627451 , 0.32941176, 0.19607843],
    [0.47058824, 0.32941176, 0.19607843],
    [0.42745098, 0.28627451, 0.16470588]],
   ...,
   [[0.81568627, 0.66666667, 0.37647059],
    [0.78823529, 0.6       , 0.13333333],
    [0.77647059, 0.63137255, 0.10196078],
    ...,
    [0.62745098, 0.52156863, 0.2745098 ],
    [0.21960784, 0.12156863, 0.02745098],
    [0.20784314, 0.13333333, 0.07843137]],
   [[0.70588235, 0.54509804, 0.37647059],
    [0.67843137, 0.48235294, 0.16470588],
    [0.72941176, 0.56470588, 0.11764706],
    ...,
    [0.72156863, 0.58039216, 0.36862745],
    [0.38039216, 0.24313725, 0.13333333],
    [0.3254902 , 0.20784314, 0.13333333]],
   [[0.69411765, 0.56470588, 0.45490196],
    [0.65882353, 0.50588235, 0.36862745],
    [0.70196078, 0.55686275, 0.34117647],
    ...,
    [0.84705882, 0.72156863, 0.54901961],
    [0.59215686, 0.4627451 , 0.32941176],
    [0.48235294, 0.36078431, 0.28235294]]])
plt.imshow(x)

Opencv学习之:将图片的值进行范围调整 cv2.normalize()

x_ = cv2.normalize(x,None,0,255,cv2.NORM_MINMAX)
x_
array([[[ 59,  62,  63],
    [ 43,  46,  45],
    [ 50,  48,  43],
    ...,
    [158, 132, 108],
    [152, 125, 102],
    [148, 124, 103]],
   [[ 16,  20,  20],
    [  0,   0,   0],
    [ 18,   8,   0],
    ...,
    [123,  88,  55],
    [119,  83,  50],
    [122,  87,  57]],
   [[ 25,  24,  21],
    [ 16,   7,   0],
    [ 49,  27,   8],
    ...,
    [118,  84,  50],
    [120,  84,  50],
    [109,  73,  42]],
   ...,
   [[208, 170,  96],
    [201, 153,  34],
    [198, 161,  26],
    ...,
    [160, 133,  70],
    [ 56,  31,   7],
    [ 53,  34,  20]],
   [[180, 139,  96],
    [173, 123,  42],
    [186, 144,  30],
    ...,
    [184, 148,  94],
    [ 97,  62,  34],
    [ 83,  53,  34]],
   [[177, 144, 116],
    [168, 129,  94],
    [179, 142,  87],
    ...,
    [216, 184, 140],
    [151, 118,  84],
    [123,  92,  72]]], dtype=uint8)
plt.imshow(x_)

Opencv学习之:将图片的值进行范围调整 cv2.normalize()