## 3 Materials and Methods
### Data Preprocessing and Augmentation  
To ensure optimal model performance and robustness, a standardized data preprocessing and augmentation pipeline was implemented. The primary objective of preprocessing was to enhance image quality, normalize input dimensions, and increase dataset variability to improve the generalization capability of the deep learning model.  
Each image in the dataset underwent several preprocessing steps, beginning with background removal to isolate the tablet from its surroundings. To standardize input dimensions, all images were resized to 512 \(\times\) 512 pixels, ensuring consistency while maintaining the morphological integrity of each pharmaceutical tablet. Additionally, grayscale conversion was applied where necessary to reduce computational complexity, particularly in models that prioritize shape-based feature extraction.  
To further enhance the visibility of pill imprints and surface details, contrast normalization techniques such as histogram equalization were employed. This adjustment ensured that subtle features, such as engraved text or embossed symbols, remained distinguishable under varying lighting conditions. Moreover, to mitigate potential biases from illumination differences, adaptive brightness and contrast adjustments were applied.  
To improve model robustness against real-world image variations, data augmentation techniques were incorporated during training. The augmentation process introduced controlled modifications to the dataset, ensuring the model could generalize well to different orientations, distortions, and imaging conditions. The following augmentation strategies were applied:  
* Random rotation (\(\pm\)20\({}^{\circ}\)): Introduced minor rotational variations to account for non-perfectly aligned pill images.
* Horizontal and vertical flipping: Applied selectively to balance asymmetric pill distributions in the dataset.
* Gaussian noise addition: Simulated real-world noise conditions, improving the model's ability to classify pills under suboptimal imaging scenarios.
* Shearing and scaling: Applied to introduce perspective variations, ensuring robustness to variations in camera angles.  
A critical aspect of data preprocessing involved ensuring class balance within the dataset. To prevent the model from overfitting to dominant classes, synthetic image generation techniques, such as oversampling underrepresented classes, were employed. This ensured that all pharmaceutical categories were adequately represented in the training dataset, minimizing class imbalance issues that could skew model predictions.  
Once preprocessing and augmentation were completed, the dataset was normalized using mean subtraction and scaling, aligning all pixel values within a range of [0, 1]. This standardization improved convergence speed during model training by ensuring that all images were processed on a consistent scale.  
By implementing this comprehensive preprocessing and augmentation strategy, the dataset was transformed into a robust, well-balanced input source, ensuring high classification accuracy and real-world applicability of the deep learning model in pharmaceutical image recognition.