test image stats of all image modes

This commit is contained in:
Yay295 2024-09-18 15:00:30 -05:00
parent 1ee3bd1d9e
commit bf14cc66d4

View File

@ -31,17 +31,241 @@ def test_sanity() -> None:
ImageStat.Stat(1) # type: ignore[arg-type] ImageStat.Stat(1) # type: ignore[arg-type]
def test_hopper() -> None: hopper_image_stats = {
im = hopper() "1": {
"extrema": [(0, 255)],
"count": [16384],
"sum": [1374450.0],
"sum2": [350484750.0],
"mean": [83.8897705078125],
"median": [0],
"rms": [146.25967140497818],
"var": [14354.39788363874],
"stddev": [119.80984051253361],
},
"L": {
"extrema": [(1, 255)],
"count": [16384],
"sum": [1387784.0],
"sum2": [189769246.0],
"mean": [84.70361328125],
"median": [87],
"rms": [107.62246782644732],
"var": [4407.893478155136],
"stddev": [66.39196847627834],
},
"LA": {
"extrema": [(1, 255), (1, 255)],
"count": [16384, 16384],
"sum": [1387784.0, 1387784.0],
"sum2": [189769246.0, 189769246.0],
"mean": [84.70361328125, 84.70361328125],
"median": [87, 87],
"rms": [107.62246782644732, 107.62246782644732],
"var": [4407.893478155136, 4407.893478155136],
"stddev": [66.39196847627834, 66.39196847627834],
},
"La": {
"extrema": [(1, 255), (1, 255)],
"count": [16384, 16384],
"sum": [1387784.0, 1387784.0],
"sum2": [189769246.0, 189769246.0],
"mean": [84.70361328125, 84.70361328125],
"median": [87, 87],
"rms": [107.62246782644732, 107.62246782644732],
"var": [4407.893478155136, 4407.893478155136],
"stddev": [66.39196847627834, 66.39196847627834],
},
"P": {
"extrema": [(0, 225)],
"count": [16384],
"sum": [1434006.0],
"sum2": [191921024.0],
"mean": [87.5247802734375],
"median": [61],
"rms": [108.2309091133397],
"var": [4053.342525586486],
"stddev": [63.665866251756015],
},
"PA": {
"extrema": [(0, 225), (0, 225)],
"count": [16384, 16384],
"sum": [1434006.0, 1434006.0],
"sum2": [191921024.0, 191921024.0],
"mean": [87.5247802734375, 87.5247802734375],
"median": [61, 61],
"rms": [108.2309091133397, 108.2309091133397],
"var": [4053.342525586486, 4053.342525586486],
"stddev": [63.665866251756015, 63.665866251756015],
},
"F": {
"extrema": [(0, 255)],
"count": [16384],
"sum": [1371401.0],
"sum2": [187010571.0],
"mean": [83.70367431640625],
"median": [86],
"rms": [106.8373503105853],
"var": [4407.914327319711],
"stddev": [66.39212549180597],
},
"I": {
"extrema": [(0, 255)],
"count": [16384],
"sum": [1371401.0],
"sum2": [187010571.0],
"mean": [83.70367431640625],
"median": [86],
"rms": [106.8373503105853],
"var": [4407.914327319711],
"stddev": [66.39212549180597],
},
"I;16": {
"extrema": [(0, 254)],
"count": [16384],
"sum": [588959.0],
"sum2": [83694771.0],
"mean": [35.94720458984375],
"median": [2],
"rms": [71.47253616105257],
"var": [3816.121907468885],
"stddev": [61.77476756305025],
},
"I;16B": {
"extrema": [(0, 254)],
"count": [16384],
"sum": [588959.0],
"sum2": [83694771.0],
"mean": [35.94720458984375],
"median": [2],
"rms": [71.47253616105257],
"var": [3816.121907468885],
"stddev": [61.77476756305025],
},
"I;16L": {
"extrema": [(0, 254)],
"count": [16384],
"sum": [588959.0],
"sum2": [83694771.0],
"mean": [35.94720458984375],
"median": [2],
"rms": [71.47253616105257],
"var": [3816.121907468885],
"stddev": [61.77476756305025],
},
"I;16N": {
"extrema": [(0, 254)],
"count": [16384],
"sum": [588959.0],
"sum2": [83694771.0],
"mean": [35.94720458984375],
"median": [2],
"rms": [71.47253616105257],
"var": [3816.121907468885],
"stddev": [61.77476756305025],
},
"RGB": {
"extrema": [(0, 255), (0, 255), (0, 255)],
"count": [16384, 16384, 16384],
"sum": [1470218.0, 1311896.0, 1563008.0],
"sum2": [227989760.0, 176170192.0, 240873092.0],
"mean": [89.7349853515625, 80.07177734375, 95.3984375],
"median": [72, 73, 71],
"rms": [117.96351395664678, 103.69462471754503, 121.25067755126412],
"var": [5863.023028954864, 4341.085668325424, 5600.864929199219],
"stddev": [76.57037957954017, 65.88691575969712, 74.83892656364881],
},
"RGBA": {
"extrema": [(0, 255), (0, 255), (0, 255), (255, 255)],
"count": [16384, 16384, 16384, 16384],
"sum": [1470218.0, 1311896.0, 1563008.0, 4177920.0],
"sum2": [227989760.0, 176170192.0, 240873092.0, 1065369600.0],
"mean": [89.7349853515625, 80.07177734375, 95.3984375, 255.0],
"median": [72, 73, 71, 255],
"rms": [117.96351395664678, 103.69462471754503, 121.25067755126412, 255.0],
"var": [5863.023028954864, 4341.085668325424, 5600.864929199219, 0.0],
"stddev": [76.57037957954017, 65.88691575969712, 74.83892656364881, 0.0],
},
"RGBa": {
"extrema": [(0, 255), (0, 255), (0, 255), (255, 255)],
"count": [16384, 16384, 16384, 16384],
"sum": [1470218.0, 1311896.0, 1563008.0, 4177920.0],
"sum2": [227989760.0, 176170192.0, 240873092.0, 1065369600.0],
"mean": [89.7349853515625, 80.07177734375, 95.3984375, 255.0],
"median": [72, 73, 71, 255],
"rms": [117.96351395664678, 103.69462471754503, 121.25067755126412, 255.0],
"var": [5863.023028954864, 4341.085668325424, 5600.864929199219, 0.0],
"stddev": [76.57037957954017, 65.88691575969712, 74.83892656364881, 0.0],
},
"RGBX": {
"extrema": [(0, 255), (0, 255), (0, 255), (255, 255)],
"count": [16384, 16384, 16384, 16384],
"sum": [1470218.0, 1311896.0, 1563008.0, 4177920.0],
"sum2": [227989760.0, 176170192.0, 240873092.0, 1065369600.0],
"mean": [89.7349853515625, 80.07177734375, 95.3984375, 255.0],
"median": [72, 73, 71, 255],
"rms": [117.96351395664678, 103.69462471754503, 121.25067755126412, 255.0],
"var": [5863.023028954864, 4341.085668325424, 5600.864929199219, 0.0],
"stddev": [76.57037957954017, 65.88691575969712, 74.83892656364881, 0.0],
},
"CMYK": {
"extrema": [(0, 255), (0, 255), (0, 255), (0, 0)],
"count": [16384, 16384, 16384, 16384],
"sum": [2707702.0, 2866024.0, 2614912.0, 0.0],
"sum2": [543548180.0, 572472832.0, 509108612.0, 0.0],
"mean": [165.2650146484375, 174.92822265625, 159.6015625, 0.0],
"median": [183, 182, 184, 0],
"rms": [182.1415605942343, 186.9250351076602, 176.2768381882334, 0.0],
"var": [5863.023028954864, 4341.085668325424, 5600.864929199219, 0.0],
"stddev": [76.57037957954017, 65.88691575969712, 74.83892656364881, 0.0],
},
"HSV": {
"extrema": [(0, 254), (0, 255), (1, 255)],
"count": [16384, 16384, 16384],
"sum": [2129583.0, 1958662.0, 1966497.0],
"sum2": [372384587.0, 283361102.0, 347501397.0],
"mean": [129.97943115234375, 119.5472412109375, 120.02545166015625],
"median": [155, 121, 132],
"rms": [150.7599132814712, 131.51041455239272, 145.6358543181873],
"var": [5833.89892994985, 3003.446254596114, 6803.6930167637765],
"stddev": [76.37996419186022, 54.80370657716606, 82.48450167615597],
},
"LAB": {
"extrema": [(1, 255), (112, 202), (67, 199)],
"count": [16384, 16384, 16384],
"sum": [1450343.0, 2241211.0, 1994635.0],
"sum2": [211197929.0, 308840591.0, 252898203.0],
"mean": [88.52191162109375, 136.79266357421875, 121.74285888671875],
"median": [98, 132, 125],
"rms": [113.53633161323914, 137.29578918534736, 124.24041747937432],
"var": [5054.3697591386735, 137.9009202979505, 614.3576455377042],
"stddev": [71.09409088763056, 11.743122255088316, 24.786239035757408],
},
"YCbCr": {
"extrema": [(0, 255), (46, 189), (85, 230)],
"count": [16384, 16384, 16384],
"sum": [1379771.0, 2189635.0, 2148579.0],
"sum2": [188439995.0, 301607477.0, 289799029.0],
"mean": [84.21453857421875, 133.64471435546875, 131.13885498046875],
"median": [87, 130, 128],
"rms": [107.2448811765588, 135.67851519258045, 132.99597368384232],
"var": [4409.376031305641, 547.7498097084463, 490.5297305248678],
"stddev": [66.40313269195694, 23.404055411582974, 22.14790578192141],
},
}
def test_hopper_modes() -> None:
"""Check that we're testing image stats for all of the image modes."""
assert sorted(Image.MODES) == sorted(hopper_image_stats.keys())
@pytest.mark.parametrize("mode", hopper_image_stats.keys())
@pytest.mark.parametrize("stat", hopper_image_stats["RGB"].keys())
def test_hopper(mode: str, stat: str) -> None:
im = hopper(mode)
st = ImageStat.Stat(im) st = ImageStat.Stat(im)
assert getattr(st, stat) == hopper_image_stats[mode][stat]
# verify a few values
assert st.extrema[0] == (0, 255)
assert st.median[0] == 72
assert st.sum[0] == 1470218
assert st.sum[1] == 1311896
assert st.sum[2] == 1563008
def test_constant() -> None: def test_constant() -> None: