语言

Menu
Sites
Language
Merging 2 image pixel by pixel

Hi,

I need to merge 2 raw images (say rgb images) pixel by pixel.

But,i could not find a direct way of doing it.

Anybody has any idea how to acheive this?

Regards,

编辑者为: Brock Boland 17 3月, 2014 原因: Paragraph tags added automatically from tizen_format_fix module.

响应

3 回复
Pushpa G
Hi, Can you let me know which pixel format do you use and what kind of merge operation you want. Give an example for better understanding
Siddharth Singh
I can work with any pixel format like RGB 565 or RGB 888. In essence i want to add the corresponding pixels of 2 different images with same resolution. I want to have a third image which is the result of merge of 2 images. Let us suppose the resolution is 700 * 1000. So,i want to achieve this: for(i=1;i<=700;i++) { for(j=1;j<=1000;j++) { pic_3[j] = ( pic_1[j] + pic_2[j] ) / 2 ; } } Hope,it makes sense!
Pushpa G
Try this code: ------------------------------ // // source buffer for blending #1 // Pixel16* pic_1 = ... // (imageWidth * imageHeight * 2) bytes allocated. RGB565; // source buffer for blending #2 // Pixel16* pic_2 = ... // (imageWidth * imageHeight * 2) bytes allocated. RGB565; // destination (blending result stored) // Pixel16* pic_3 = ... // (imageWidth * imageHeight * 2) bytes allocated. RGB565; // // Image size for testing: 350 x 500 // typedef unsigned short Pixel16; typedef unsigned long Pixel32; int imageWidth = 350; int imageHeight = 500; int imagePpl = imageWidth; for (int y = 0; y < imageHeight; y++) { for (int x = 0; x < imageWidth; x++) { int offset = y * imagePpl + x; // extract color components of source#1 (RGB565) Pixel32 r1 = Pixel32(pic_1[offset] & 0xF800); Pixel32 g1 = Pixel32(pic_1[offset] & 0x07E0); Pixel32 b1 = Pixel32(pic_1[offset] & 0x001F); // extract color components of source#2 (RGB565) Pixel32 r2 = Pixel32(pic_2[offset] & 0xF800); Pixel32 g2 = Pixel32(pic_2[offset] & 0x07E0); Pixel32 b2 = Pixel32(pic_2[offset] & 0x001F); // blend two sources (50% blending) Pixel32 r3 = (r1 + r2) >> 1; Pixel32 g3 = (g1 + g2) >> 1; Pixel32 b3 = (b1 + b2) >> 1; // composite each component to make RGB565 pic_3[offset] = (r3 & 0xF800) | (g3 & 0x07E0) | (b3 & 0x001F); } }