I'm working on a program that combines two images together in the best possible way. Let's say I have two 2D arrays containing "pixel" structures that make up these two images.
I have already written the algorithm that determines where to join the images together relative to the larger of the two images in terms of "x" and "y", where x is the column and y is the row of the larger image's 2D array. The point in which they should be joined is encapsulated in a "match" structure, which looks like this:
typedef struct {
int overlap; // used in algorithm to determine where to combine
int x; // column of larger image
int y; // row of larger image
int overlapWidth; // width of the overlap between the two images
int overlapHeight; // height of the overlap between the two images
} match;
Note that the matching point could be negative (x, y, or both) relative to the larger image.
The pixels contained in the overlap are averaged and any pixels outside of the two images (but still within the new dimensions) are white.
Example
+---+---+ image1
| | |
+---+---+---+ image2
| | X | |
+---+---+---+
| | |
+---+---+
X represents the match point for these two images, so its state looks like this:
x = 1
y = 1
overlapWidth = 1
overlapHeight = 1
The new image for this case would be 3x3.
Assuming, then, that I have the "match" in which to join the two images together, the calculated new width and height of the resulting image, and an allocated 2D array for the resulting image based on these new dimensions, I'm wondering how I could put the appropriate pixels into the new image. Below is some pseudocode that represents what I'm trying to do.
Pseudocode
FOREACH row in new_height
FOREACH col in new_width
IF larger_image AND smaller_image do not contain (row,col)
add white pixel
ELSE IF overlap contains (row,col)
add average of pixels
ELSE IF only larger_image contains (row,col)
add larger_image pixel
ELSE
add smaller_image pixel
I'm having a hard time coming up with a way to do this. I'm not necessarily looking for code, I'm just looking for ideas on how I could do what I'm talking about. Any thoughts would be appreciated.