图像处理一些基本算子的逻辑

1、CHW2HWC、CHW2HWC、NCHW2NHWC、NCHW2NHWC

  NCHW2NHWC、NCHW2NHWC逻辑就是增加外层的N

  template
  void matData_HWC2CHW(T* input, T* output, int height, int width, int channel)
  {
    //output的内存空间需要在外部开辟好,for循环的层级顺序无所谓(是从channel还是height、width开始遍历不影响结果)
    for (int c = 0; c < channel; ++c) 
    {
      for (int h = 0; h < height; ++h) 
      {
        for (int w = 0; w < width; ++w) 
        {
          //HWC2CHW 那么input的最后一个就是c,对应HWC的最后一位,倒数第二位则是w*channel,对应HWC的最后两位,其他含义类似
          output[ c*width*height + h*width + w ] = input[ width*channel*h + w*channel + c ];
        }
      }
    }
  }

  template
  void matData_CHW2HWC(T* input, T* output, int height, int width, int channel)
  {
    //output的内存空间需要在外部开辟好,for循环的层级顺序无所谓(是从channel还是height、width开始遍历不影响结果)
    for (int c = 0; c < channel; ++c) 
    {
      for (int h = 0; h < height; ++h) 
      {
        for (int w = 0; w < width; ++w) 
        {
          //CHW2HWC 那么input的最后一个就是w,对应CHW的最后一位,倒数第二位则是h*width,对应CHW的最后两位,其他含义类似
          output[ width*channel*h + w*channel + c ] = input[ c*width*height + h*width + w ];
        }
      }
    }
  }

你可能感兴趣的:(java,前端,javascript)