[Deep Learning] Channel arrangement problem of color pictures

When we reason with the image-related model, we need to consider the channel of the image, especially when deploying, otherwise we will encounter the problem that the data cannot correspond

  • opencv's Mat 
    • By default, when imread reads, the memory arrangement order is HWC, which can be accessed by using the data pointer of Mat (when accessing, the data pointer must be char*, if you are a float matrix, you need to force it)
    • The problem of the color channel, that is, the order of C, opencv is BGR by default, but generally we are RGB, you can use the convertTo() API to convert it.
  • PIL read
    • The memory layout of the read image is HWC
    • Color channels are RGB
  • Tensor( torch : transform.ToTensor())
    • Is the input data shape W, H, C ——> C, H, W
    • Divide all numbers by 255 and normalize the data to [0, 1]

    • This does not involve the color channel, which channel is the channel when the original image is read

Guess you like

Origin blog.csdn.net/qq_31638535/article/details/128663501