I am trying to find colors in an image with frequency of more than one time to create a very simple color palette from an input image. To do so, I went this far …
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
public class ColorAnalyzer : MonoBehaviour
{
public Texture2D RawImage;
public Color Color1;
public Color Color2;
public Color Color3;
public Color Color4;
public Color Color5;
void Start()
{
// getting all the pixels with the mipmap level of 5
Color[] arrayOfColors = RawImage.GetPixels(5);
// identifying unique colors
Color[] distinctColors = arrayOfColors.Distinct().ToArray();
// subtracting unique colors from the main array
Color[] colorsWithFrequencyOfMoreThanOne = arrayOfColors.Except(distinctColors).ToArray();
Debug.Log("ArrayColors lengh: " + arrayOfColors.Length); // console says 512
Debug.Log("DistinctColors lengh: " + distinctColors.Length); // console says 496
Debug.Log("colorsWithFrequencyOfMoreThanOne lengh: " + colorsWithFrequencyOfMoreThanOne.Length); // console says 0
}
}
Does anybody know why my “Except” function does not work and says “null” instead of “16”?