• 0 Posts
  • 7 Comments
Joined 9 months ago
cake
Cake day: March 8th, 2025

help-circle






  • I see a flag. I like flags. Especially the Japanese flags. I don’t specifically care for Japan, but the flag is one of my favourites. I prefer flags with low entropy: so I wrote a script once that ranks the nations flags by entropy so I could quantify my preference. Thanks for letting me infodump a bit.

    Edit: Due to people aski g for it: here is the top ten of my ranking:

    Nations' flag entropy ranking (n=208). 
    Image source: Wikimedia.
    
    0	white_field			-1.439759075204976e-10
    1	Indonesia			3.3274441922278752
    2	Germany			3.391689777286108
    3	South_Ossetia			3.8174437373506778
    4	Monaco			3.9718936201427066
    5	Poland			3.9719290780440133
    6	Austria			4.372592975412404
    7	Ukraine			4.405280849871184
    8	Hungary			4.4465472496385985
    9	Albania			4.6134257669087395
    10	Mauritius			4.707109405551959
    11	Luxembourg			4.721346585737304
    

    Here’s how I defined the entropy value for each flag:

    def color_weighted_spectral_entropy(image):
        b_channel, g_channel, r_channel = cv2.split(image)
        
        # Calculate spectral entropy for each channel
        def channel_spectral_entropy(channel):
            f_transform = np.fft.fft2(channel)
            f_shifted = np.fft.fftshift(f_transform)
            magnitude_spectrum = np.abs(f_shifted)
            if np.sum(magnitude_spectrum) > 0:
                normalized = magnitude_spectrum / np.sum(magnitude_spectrum)
            else:
                normalized = magnitude_spectrum
            # Entropy calculation with color channel weighting
            epsilon = 1e-10
            entropy = -np.sum(normalized * np.log2(normalized + epsilon))
            
            return entropy
        
        weighted_entropy = (
            0.333 * channel_spectral_entropy(b_channel) +
            0.333 * channel_spectral_entropy(g_channel) +
            0.333 * channel_spectral_entropy(r_channel)
        )
        
        return float(weighted_entropy)
    

    “White_field” is just an array that holds zeroes. I use this as a sanity check. Code is on github. I can send DM to whomever is interested. I guess it can also be searched for.