In this project focusing on color channel alignment, I initially cropped the image to remove a $15\%$ edge, which helps prevent black or white edges from interfering with the model's processing. Subsequently, I employed a combination of the Sobel Edge Detection algorithm and a Pyramid structure. This approach not only ensures precise color channel alignment but also enhances the speed of the algorithm when processing large images. Additionally, to address issues of color distortion, a color adjustment strategy was implemented to improve the quality of the aligned images.
All large images were successfully aligned, each within 25 seconds, while smaller images were completed in about 5 seconds. In order to validate the generalizability and effectiveness of the algorithm, three additional images were selected for testing. This step is critical to ensuring that the color alignment technique performs consistently across diverse image types and real-world applications.
The Sobel Edge Detection algorithm, introduced by Irwin Sobel in 1968, represents a pivotal advancement in image processing technologies. This method is now regarded as one of the most fundamental and widely-used techniques for edge detection in digital image processing. The Sobel operator distinguishes itself by its simplicity and efficiency, making it particularly effective for real-time applications.
If we denote the source image by \( I \), the results of the convolution of \( I \) with the Sobel kernels are two derivative images: \( G_x \) and \( G_y \). Here, \( G_x \) contains the approximations of the horizontal gradients, and \( G_y \) contains the vertical gradients. These gradients at any point in the image are calculated as follows:
\[ G_x = \begin{bmatrix} -1 & 0 & 1 \\ -2 & 0 & 2 \\ -1 & 0 & 1 \end{bmatrix} \cdot I, \quad G_y = \begin{bmatrix} -1 & -2 & -1 \\ 0 & 0 & 0 \\ 1 & 2 & 1 \end{bmatrix} \cdot I \]
The magnitude of the gradient at each point gives the edge response at that point and can be calculated using the following function:
\[ G = \sqrt{G_x^2 + G_y^2} \]
High magnitude of gradient represents the edge of items, after normalizing the result, I visualized one of the edge detection result as below:
Without import any other libraries just 'Numpy', it would be too slow to use 'for' loops to scan a large image. To accelerate this process, I create a 6 layers matrix to help increase the speed - by moving around the calculated matrix and stack them together then use 'numpy.sum' can easily calculate the derivative result.
If the orange block is the pixel that need calculate the derivative, by moving around the matrix, stacking them and adding them together (For easier understanding, I didn't show out all of the moving matrix)
I adjust the average pixel value in each channel and calculate the augmentation coefficients and apply them to each channel. The coefficient's function is listed as follows:
\[ \text{coef} = \frac{\text{average}(I)}{\text{average}(C)} \]
The adjustment method is listed as follows:
\[ \text{adjust C} = C \times \text{coef} \]