How leviborodenko/primify works
Main Components
• CLI Interface – Represented by the src/primify/cli.py module. This is the entry point for users invoking the command-line tool.
• Core Library – Built around the PrimeImage class in src/primify/base.py. This class encapsulates the image transformation procedures.
• Prime Search Module – Found in src/primify/prime_finder.py, this module handles prime testing and adjustment of the number until a prime is obtained.
Processing Pipeline
• Followed by “Image Enhancement” (edge enhancement, smoothing).
• Then, “Grey-scale Conversion” leading into “Quantisation” (reducing the range to 5 to 10 levels).
• Next, a “Mapping to Digits” stage where each quantised level translates into a digit.
• Finally, incorporate the “Prime Searching and Tweaking” module (using the Baillie–PSW test and other prime-finding logic). The output is the prime number that retains the image’s structure.
Relationships and Data Flow
• Dependencies between modules. For example, the CLI receives parameters (image path, max-digits, etc.) and passes them to the PrimeImage class, which then orchestrates the image processing pipeline and calls the prime_finder module.
• How the output (a prime number that “looks like” the source image) is generated and either returned to the CLI for display or saved to a file.
Architectural Patterns and Design Principles
• Separation of concerns: splitting the CLI input handling from the actual processing logic.
• Modular design: each processing stage (resizing, enhancement, mapping, prime testing) is distinct and can potentially be unit-tested (as seen in the tests folder).
• That the design is essentially a pipeline, with sequential processing steps feeding into the next stage.