import numpy as np
from PIL import Image

def main():
    img = Image.open("output2g.png").convert("L")
    P = (np.array(img) < 128).astype(np.uint8)
    print(f"Matrix P shape: {P.shape}")
    
    # We want to check the rank of P.
    # Since P is 16384x2048, we check if columns are linearly independent.
    # But it's easier to check rows. rank(P) = rank(P^T)
    # We can use a small portion or the whole thing if we are careful.
    
    # Let's take the first 2048 rows and check rank.
    sub = P[:2048, :]
    rank = np.linalg.matrix_rank(sub.astype(float)) # Not GF2 but good proxy for upper bound
    print(f"Approximate rank of first 2048 rows: {rank}")
    
    # Since it's QC, we can check rank over the ring of polynomials.
    # But let's just stick to the BCH bound.
    
if __name__ == "__main__":
    main()
