Compression & Serialization
Image Compression
ParametricDFT.CompressedImage — Type
CompressedImageSparse representation of an image in the frequency domain.
Fields
indices::Vector{Int}: Linear indices of non-zero coefficientsvalues_real::Vector{Float64}: Real parts of coefficient valuesvalues_imag::Vector{Float64}: Imaginary parts of coefficient valuesoriginal_size::Tuple{Int,Int}: Original image dimensions (height, width)basis_hash::String: Hash of the basis used for compression (for verification)
Note
The compressed representation stores only the non-zero coefficients after truncation, achieving compression by discarding small coefficients.
ParametricDFT.CompressedImageJSON — Type
CompressedImageJSONInternal struct for JSON serialization of CompressedImage.
ParametricDFT._reconstruct_frequency_domain — Method
_reconstruct_frequency_domain(compressed::CompressedImage, size::Tuple{Int,Int})Reconstruct full frequency domain matrix from sparse representation.
ParametricDFT._select_top_coefficients — Method
_select_top_coefficients(freq_domain::AbstractMatrix, k::Int)Select top k coefficients by magnitude. Matches the magnitude-only topk_truncate used during training — no frequency weighting.
ParametricDFT.compress — Method
compress(basis::AbstractSparseBasis, image::AbstractMatrix; ratio::Float64=0.9)Compress an image using the given sparse basis.
Arguments
basis::AbstractSparseBasis: The trained basis to use for compressionimage::AbstractMatrix: Input image (must match basis dimensions)ratio::Float64 = 0.9: Compression ratio (0.9 means keep only 10% of coefficients)
Returns
CompressedImage: Sparse representation of the image
Example
basis = load_basis("trained_basis.json")
image = load_grayscale_image("photo.png")
compressed = compress(basis, image; ratio=0.95) # Keep top 5%
save_compressed("photo.cimg", compressed)ParametricDFT.compress_with_k — Method
compress_with_k(basis::AbstractSparseBasis, image::AbstractMatrix; k::Int)Compress an image keeping exactly k coefficients.
Arguments
basis::AbstractSparseBasis: The trained basis to useimage::AbstractMatrix: Input imagek::Int: Exact number of coefficients to keep
Returns
CompressedImage: Sparse representation
ParametricDFT.compression_stats — Method
compression_stats(compressed::CompressedImage) -> NamedTupleGet statistics about the compression.
Returns
A named tuple with:
original_size: Original image dimensionstotal_coefficients: Total number of coefficientskept_coefficients: Number of non-zero coefficients keptcompression_ratio: Ratio of discarded coefficientsstorage_reduction: Approximate storage reduction factor
ParametricDFT.load_compressed — Method
load_compressed(path::String) -> CompressedImageLoad a compressed image from a JSON file.
Arguments
path::String: Path to the compressed image file
Returns
CompressedImage: The loaded compressed image
ParametricDFT.recover — Method
recover(basis::AbstractSparseBasis, compressed::CompressedImage; verify_hash::Bool=true)Recover an image from its compressed representation.
Arguments
basis::AbstractSparseBasis: The basis used for compressioncompressed::CompressedImage: The compressed image dataverify_hash::Bool = true: Whether to verify basis hash matches
Returns
Matrix{Float64}: Reconstructed image (real-valued)
Example
basis = load_basis("trained_basis.json")
compressed = load_compressed("photo.cimg")
recovered = recover(basis, compressed)ParametricDFT.save_compressed — Method
save_compressed(path::String, compressed::CompressedImage)Save a compressed image to a JSON file.
Arguments
path::String: File path to save tocompressed::CompressedImage: The compressed image to save
Returns
String: The path where the file was saved
Serialization
ParametricDFT.BasisJSON — Type
BasisJSONInternal struct for JSON serialization of QFTBasis.
ParametricDFT.EntangledBasisJSON — Type
EntangledBasisJSONInternal struct for JSON serialization of EntangledQFTBasis.
ParametricDFT.MERABasisJSON — Type
MERABasisJSONInternal struct for JSON serialization of MERABasis.
ParametricDFT.TEBDBasisJSON — Type
TEBDBasisJSONInternal struct for JSON serialization of TEBDBasis.
ParametricDFT._basis_to_json — Method
_basis_to_json(basis::EntangledQFTBasis)Convert an EntangledQFTBasis to JSON-serializable format.
ParametricDFT._basis_to_json — Method
_basis_to_json(basis::MERABasis)Convert a MERABasis to JSON-serializable format.
ParametricDFT._basis_to_json — Method
_basis_to_json(basis::QFTBasis)Convert a QFTBasis to JSON-serializable format.
ParametricDFT._basis_to_json — Method
_basis_to_json(basis::TEBDBasis)Convert a TEBDBasis to JSON-serializable format.
ParametricDFT._json_to_basis — Method
_json_to_basis(json_data::BasisJSON)Convert JSON data back to a QFTBasis object.
ParametricDFT._json_to_entangled_basis — Method
_json_to_entangled_basis(json_data::EntangledBasisJSON)Convert JSON data back to an EntangledQFTBasis object.
ParametricDFT._json_to_mera_basis — Method
_json_to_mera_basis(json_data::MERABasisJSON)Convert JSON data back to a MERABasis object.
ParametricDFT._json_to_tebd_basis — Method
_json_to_tebd_basis(json_data::TEBDBasisJSON)Convert JSON data back to a TEBDBasis object.
ParametricDFT.basis_to_dict — Method
basis_to_dict(basis::EntangledQFTBasis) -> DictConvert an EntangledQFTBasis to a dictionary for custom serialization.
Returns
Dict: Dictionary representation of the basis
ParametricDFT.basis_to_dict — Method
basis_to_dict(basis::MERABasis) -> DictConvert a MERABasis to a dictionary for custom serialization.
Returns
Dict: Dictionary representation of the basis
ParametricDFT.basis_to_dict — Method
basis_to_dict(basis::AbstractSparseBasis) -> DictConvert a basis to a dictionary for custom serialization.
Returns
Dict: Dictionary representation of the basis
ParametricDFT.basis_to_dict — Method
basis_to_dict(basis::TEBDBasis) -> DictConvert a TEBDBasis to a dictionary for custom serialization.
Returns
Dict: Dictionary representation of the basis
ParametricDFT.dict_to_basis — Method
dict_to_basis(d::Dict) -> AbstractSparseBasisConvert a dictionary back to a basis.
Arguments
d::Dict: Dictionary with basis data
Returns
AbstractSparseBasis: The reconstructed basis
ParametricDFT.load_basis — Method
load_basis(path::String) -> AbstractSparseBasisLoad a sparse basis from a JSON file.
Arguments
path::String: Path to the JSON file
Returns
AbstractSparseBasis: The loaded basis (concrete type depends on file contents)
Example
basis = load_basis("trained_basis.json")
freq = forward_transform(basis, image)ParametricDFT.save_basis — Method
save_basis(path::String, basis::AbstractSparseBasis)Save a sparse basis to a JSON file.
Arguments
path::String: File path to save to (should end in .json)basis::AbstractSparseBasis: The basis to save
Example
basis = train_basis(QFTBasis, images; m=6, n=6)
save_basis("trained_basis.json", basis)