Procedurality.Channel.convolution C# (CSharp) Method

convolution() public method

public convolution ( float filter, float divisor, float offset ) : Channel
filter float
divisor float
offset float
return Channel
		public Channel convolution(float[][] filter, float divisor, float offset) {
			int radius = (filter.GetLength(0) - 1)/2;
			Channel channel = new Channel(width, height);
			for (int y = 0; y < height; y++) {
				for (int x = 0; x < width; x++) {
					float value = 0;
					for (int i = -radius; i <= radius; i++) {
						for (int j = -radius; j <= radius; j++) {
							value += filter[i + radius][j + radius] * getPixelWrap(x + i, y + j);
						}
					}
					value = value/divisor + offset;
					channel.putPixel(x, y, value);
				}
			}
			pixels = channel.getPixels();
			return this;
		}