如何拼接数字图像中的一些物体?

发布于 2024-08-12 08:13:10 字数 75 浏览 4 评论 0原文

我正在寻找一些算法来连接对象,例如,将苹果组合成数字图像中的树以及Matlab中的一些演示。请给我看一些相关材料。感谢您的阅读和帮助我!

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!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傾旎 2024-08-19 08:13:10

我不确定我是否理解你的问题,但如果你想要做一些图像重叠,就像 Photoshop 图层一样,你可以使用一些图像特征,通过该特征来确定透明度。

例如,考虑使用两个 RGB 图像。图像 A 将与图像 B 重叠。为此,我们将使用图像 B 的亮度来确定透明度 (255 = 100%)。
强度=像素/255;

NewPixel = (PixelA * (1 - 强度)) + (PixelB * 强度);

由于强度是一个百分比,并且每个像素都乘以该百分比的补数,因此所得总和永远不会溢出超过 255(最大灰度级)

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));
}

。您还可以更改此算法,以便在不同的位置将图像 A 重叠到 B 上。我假设图像 B 坐标 (0, 0) 将与图像 A 坐标 (0, 0) 重叠。

但我再次不确定这是否是您正在寻找的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文