Speed up Matrix Addition in C#

前端 未结 15 1182
北荒
北荒 2021-02-05 22:48

I\'d like to optimize this piece of code :

public void PopulatePixelValueMatrices(GenericImage image,int Width, int Height)
{            
        for (int x = 0;         


        
15条回答
  •  梦谈多话
    2021-02-05 22:57

    I'm not sure if it's faster but you may write something like;

    public void PopulatePixelValueMatrices(GenericImage image,int Width, int Height)
    {            
            Byte pixelValue;
            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    pixelValue = image.GetPixel(x, y).B;
                    this.sumOfPixelValues[x, y] += pixelValue;
                    this.sumOfPixelValuesSquared[x, y] += pixelValue * pixelValue;
                }
            }
    }
    

提交回复
热议问题