English 中文(简体)
How to joint some objects in digital image?
原标题:

I m looking for some algorithm to joint objects, for example, combine an apple into a tree in digital image and some demo in Matlab. Please show me some materials of that. Thanks for reading and helping me!!!

问题回答

I not sure if I undertand your question, but if you are looking to do some image overlaping, as does photoshop layers, you can use some image characteristics to, through that characteristc, determine the degree of transparency.

For example, consider using two RGB images. Image A will be overlapped by image B. To do it, we ll use image B brightness to determine transparency degree (255 = 100%). Intensity = pixel / 255;

NewPixel = (PixelA * (1 - Intensity)) + (PixelB * Intensity);

As intensity is a percentage and each pixel is multiplied by the complement of this percentage, the resulting sum will never overflow over 255 (max graylevel)

int WidthA = imageA.Width * channels;
int WidthB = imageB.Width * channels;

int width = Min(ImageA.Width, ImageB.Width) * channels;
int height = Min(ImageA.Height, ImageB.Height);

byte *ptrA = imageA.Buffer;
byte *ptrB = imageB.Buffer;

for (int y = 0; y < height; y++)
{
    for (int x = 0; x < width; x += channels, ptrA += channels, ptrB += channels)
    {

  //Take the intensity of the pixel. If RGB (channels = 3), intensity = (R+B+G) / 3. If grayscale, the pixel value is intensity itself
  int avg = 0;
        for (int j = 0; j < channels; ++j)
        {
            avg += ptrB[j];
        }

        //Obtain the intensity as a value between 0..100%
  double intensity = (double)(avg / channels) / 255;

        for (int j = 0; j < channels; ++j)
        {
   //Write in image A the resulting pixel which is obtained by multiplying Image B pixel 
   //by 100% - intensity plus Image A pixel multiplied by the intensity
            ptrA[j] = (byte) ((ptrB[j] * (1.0 - intensity)) + ((intensity) * ptrA[j]));
        }
    }

    ptrA = imageA.Buffer + (y * WidthA));
    ptrB = imageB.Buffer + (y * WidthB));
}

You can also change this algorithm in order to overlap Image A over B, in a different place. I m assuming here the image B coordinate (0, 0) will overlap image A coordinate (0, 0).

But once again, I m not sure if this is what you are looking for.





相关问题
How to add/merge several Big O s into one

If I have an algorithm which is comprised of (let s say) three sub-algorithms, all with different O() characteristics, e.g.: algorithm A: O(n) algorithm B: O(log(n)) algorithm C: O(n log(n)) How do ...

Grokking Timsort

There s a (relatively) new sort on the block called Timsort. It s been used as Python s list.sort, and is now going to be the new Array.sort in Java 7. There s some documentation and a tiny Wikipedia ...

Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Enumerating All Minimal Directed Cycles Of A Directed Graph

I have a directed graph and my problem is to enumerate all the minimal (cycles that cannot be constructed as the union of other cycles) directed cycles of this graph. This is different from what the ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签