How runwenhu/cnn-prediction-based-reversible-data-hiding works
Project Overview and Identifying the Main Components
• The project is a specialized image processing application that implements a reversible data hiding method using a CNN-based predictor (as introduced in the referenced paper). Its core purpose is to calculate the PSNR (Peak Signal-to-Noise Ratio) for watermarked images by utilizing two embedding techniques: histogram shifting and expansion embedding.
• Key components include:
• The Main Application (main.py) which orchestrates the execution according to command-line parameters.
• The CNN-based predictor implemented in the “model” directory, comprising files like cnnp.py and predict_model.py.
• Model parameters stored in the “model_parameter” folder.
• The test images (in “standard_test_images”) used as sample inputs.
• Supporting utility scripts (utils.py) and several MATLAB scripts (calculate_complexity.m, calculate_tp_tn.m, cnn_expansion.m, cnn_histogram_shifting.m, num2bitlist.m) that might support or validate certain operations.
Analyzing the File Structure for Architectural Insights
• Top-Level Files/Directories:
• README.md: Provides project description, usage instructions, and parameter details.
• Python source code files (main.py, utils.py) that serve as the entry point and helper functions.
• “model” folder: Contains CNN predictor implementations. This indicates a modular separation where core processing logic (the CNN predictor) is decoupled from the main orchestration.
• “model_parameter” folder: Stores pretrained model weights. Its separation shows an adherence to the separation of concerns.
• The directory names and file names provide clues; for example, “cnn_expansion.m” and “cnn_histogram_shifting.m” suggest distinct modules for each embedding type. This implies a branching or conditional flow in the data embedding pipeline within the application.
Extracting Insights from the README
• The README clearly states how to use the software with different modes (histogram shifting vs. expansion embedding), as well as the required environment details (Windows 10, Python 3.7, PyTorch 1.6.0, MATLAB 2019a).
• The application depends on a pretrained model (from “model_parameter”) loaded within the CNN predictor logic.
a. Main Components to Include:
• Input Component: “Standard Test Images” folder (e.g., Barbara.bmp, Lena.bmp, etc.).
• User Interface/CLI: The command-line interface handled by main.py that receives parameters such as image size, model file path, folder, mode, and data length.
• Processing Core:
• Data Handling Module: Responsible for loading images and preprocessing.
• CNN-Predictor Module: Located in the “model” folder (using cnnp.py and predict_model.py), which implements the CNN-based predictor.
• Embedding Logic: Divided into two branches/components for:
• Histogram Shifting embedding (supported by cnn_histogram_shifting.m).
• Expansion Embedding (supported by cnn_expansion.m).
• Utility Module: Supporting functions in utils.py.
• Model Parameter Loader: A component that loads the model weights from “model_parameter/model_state.pth”.
• Evaluation Module: Calculation and reporting of PSNR values.
• Auxiliary Scripts: MATLAB scripts (calculate_complexity.m, calculate_tp_tn.m, num2bitlist.m) that might be used for additional processing or evaluation.
b. Relationships and Data Flow:
• The controller chooses between histogram shifting and expansion embedding based on command-line mode, directing the flow to the respective embedding logic.
• Calls are made to the CNN predictor module that uses model parameters for predictions.
• The processed images are then evaluated for PSNR.
• Optionally, MATLAB scripts might be invoked separately (or serve as reference implementations) for auxiliary computations.
• Data flows are directional: from image input -> processing (CNN prediction and embedding) -> evaluation -> output (PSNR value).
c. Architectural Patterns & Design Principles:
• Modular Design: Separating the CNN predictor from the main orchestration code.
• Parameterization: External model parameters are decoupled and loaded at runtime.
• Multi-environment Integration: Blend of Python (main processing) and MATLAB (auxiliary functions).
• Conditional Branching: Different embedding techniques encapsulated in separate modules.
d. Relevant Technologies:
• Python 3.7 (Core scripting and application logic)
• PyTorch 1.6.0 (For CNN implementation in the “model” folder)
• MATLAB 2019a (For supporting .m functions)
• Image processing libraries (implied by image loading and processing, though not explicitly shown in the file tree, likely in utils.py or imported in main.py)