Overview
Feather blending performs a direct alpha blend of images based on their masks. The transition between images is smooth but may show visible seams when blending images with significantly different colors or textures at the boundary.Complete Example
This example is based on thetest_feather() function from examples/stitch.c:66.
#include "blending.h"
#include "utils.h"
void test_feather() {
Image img_buf1 = create_image("../files/apple.jpeg");
Image img_buf2 = create_image("../files/orange.jpeg");
Image mask1 = create_image_mask(img_buf1.width, img_buf1.height, 0.1f, 0, 1);
Image mask2 = create_image_mask(img_buf2.width, img_buf2.height, 0.1f, 1, 0);
mask1 with 0, 1: Creates a gradient from 0 (left) to 1 (right)mask2 with 1, 0: Creates a gradient from 1 (left) to 0 (right)0.1f: Transition zone is 10% of image width int out = (img_buf1.width * 0.1f);
int out_width = (img_buf1.width * 2) - (out * 2);
StitchRect out_size = {0, 0, out_width, img_buf1.height};
FEATHER instead of MULTIBAND-1 for the number of bands (not used in feather blending) StitchPoint pt1 = {0, 0};
feed(b, &img_buf1, &mask1, pt1);
StitchPoint pt2 = {img_buf2.width - out * 2 - 100, 0};
feed(b, &img_buf2, &mask2, pt2);
result = (img1 * mask1 + img2 * mask2) / (mask1 + mask2)b->result if (b->result.data != NULL) {
if (save_image(&b->result, "merge_feather.jpg")) {
printf("Merged image saved\n");
}
}
destroy_blender(b);
destroy_image(&img_buf1);
destroy_image(&img_buf2);
destroy_image(&mask1);
destroy_image(&mask2);
}
Expected Output
The output filemerge_feather.jpg will contain a blended image with a smooth gradient transition in the overlap region.
Feather vs Multiband Comparison
| Aspect | Feather Blending | Multiband Blending |
|---|---|---|
| Speed | Very fast (2-5x faster) | Slower due to pyramid operations |
| Quality | Good for gradual transitions | Excellent, nearly invisible seams |
| Memory | Low memory usage | Higher (stores multiple pyramid levels) |
| Use case | Quick previews, similar images | Production quality, different textures |
| Algorithm | Direct weighted average | Frequency domain blending |
| Parameters | Just output size | Configurable band count |
Code Differences Summary
create_blender() call. The rest of the workflow is identical.
When to Use Feather Blending
- Real-time preview: When you need fast feedback during development
- Similar images: When blending images with minimal color/brightness differences
- Low-power devices: When computational resources are limited
- Large images: When processing very high-resolution images where speed matters
- Batch processing: When processing hundreds of images and speed is critical
Performance Characteristics
- Typical processing time for 1920×1080 images: 0.05-0.10 seconds
- Memory usage: O(output_size) - just the output buffer
- Parallelization: Benefits from multi-core processors
- Linear complexity: Processing time scales linearly with image size