public static Texture2D GetEntropyImage(Texture2D texture, int sampleArea, out float[,] returnEntropyTable) { Texture2D entropyTexture = new Texture2D(texture.width, texture.height); Color[] oldColors = texture.GetPixels(); Color[] newColors = new Color[oldColors.Length]; float[,] entropyTable = new float[texture.width, texture.height]; LookupTable <float, float> lookupTable = new LookupTable <float, float>(); Histogram histogram = new Histogram(); for (int i = 0; i < oldColors.Length; i++) { int thisY = Mathf.FloorToInt(i / texture.width); int thisX = i - thisY * texture.width; //For each pixel check sample area around it to set this pixel entropy for (int x = Mathf.Max(thisX - sampleArea, 0); x <= thisX + sampleArea && x < texture.width; x++) { for (int y = Mathf.Max(thisY - sampleArea, 0); y <= thisY + sampleArea && y < texture.height; y++) { histogram.AddPixel(oldColors[x + y * texture.width]); } } float entropy = histogram.EntropyOfHistogram(lookupTable); histogram.Clear(); newColors[i] = new Color(entropy / 5f, entropy / 5f, entropy / 5f); entropyTable[thisX, thisY] = entropy; } entropyTexture.filterMode = FilterMode.Point; entropyTexture.SetPixels(newColors); entropyTexture.Apply(); returnEntropyTable = entropyTable; return(entropyTexture); }