如何在不合并边框的情况下合并两个图像 [英] how to merge two images without merging their borders

查看:128
本文介绍了如何在不合并边框的情况下合并两个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个C#解决方案来合并两个单独的图像,而不会在它们合并时合并它们之间的一条线。





< a href =https://social.msdn.microsoft.com/Forums/vstudio/en-US/efe0abc4-27ef-4d09-a56a-d4a44527bb35/how-to-merge-two-images-without-merging-their- border-pointing-picture?forum = csharpgeneral>问题图片



只需合并2张图片,一行显示b / w因为颜色区别,我想消失那条线,



代码:



i need a solution in C# to merge two separate images without merging a line between them at they merge..


Problem pic

just merg 2 images, a line show b/w them because of color difference, i want to disappear that line,

CODE:

private Bitmap Merge_Images(Bitmap bmp_1, Bitmap bmp_2)
       {
           if (bmp_1 == null || bmp_2 == null)
               return null;


     int bmp_1_Height, bmpWidth, bmp_2_Height;
               bmpWidth = bmp_1.Width;
               bmp_1_Height = bmp_1.Height;

               bmp_2_Height = bmp_2.Height;

               int firstMatchedRow = bmp_1.Height;

               byte[,] bmp2_first2rows = new byte[3 * bmpWidth, 2];


               Bitmap bmp = new Bitmap(bmpWidth, bmp_1_Height + bmp_2_Height);
               Graphics g = Graphics.FromImage(bmp);
               Rectangle RectDst = new Rectangle(0, 0, bmpWidth, bmp_1_Height);
               Rectangle RectSrc;
               g.DrawImage(bmp_1, RectDst, RectDst, GraphicsUnit.Pixel);
               RectDst = new Rectangle(0, bmp_1_Height, bmpWidth, bmp_2_Height);
               RectSrc = new Rectangle(0, 0, bmpWidth, bmp_2_Height);
               g.DrawImage(bmp_2, RectDst, RectSrc, GraphicsUnit.Pixel);

               int recx,recy,recw,rech;
     rech=10;
     recw=bmpWidth;

     recx=0;
     recy=firstMatchedRow-5;

               Rectangle r1 = new Rectangle(recx,recy, recw, rech);

               //Bitmap b2 = Blur(bmp, r1, 5);

               /// pictureBox4.Image = bmp;
               return bmp;

       }

推荐答案

看看这里:在.NET中存储图像 [ ^ ]



更多,你可以在这里找到:搜索盒 [ ^ ]
Have a look here: Merging Images in .NET[^]

More, you can find here: SearchBox[^]


这可以使用<$ c中的 Graphics 类来完成$ c> System.Drawing 命名空间。首先,您已加载要合并的两个图像。然后,您创建一个新的空位图,其中宽度是加载图像的两个宽度的总和,高度是这些图像的最大高度。完成后,从该位图创建 Graphics 并使用 DrawImage 方法在图形上绘制图像。最后,新的位图将包含一个合并的图像,您需要保存它。该代码还包含一些 Dispose()调用,这些调用将释放这些对象使用的所有资源。注意:如果以后需要,请不要丢弃对象。

This can be done using the Graphics class in the System.Drawing namespace. First, you have load the two images you want to merge. Then, you create a new empty Bitmap where the width is the sum of the two widths of the loaded images, and the height is the maximum height of those images. After doing that, create a Graphics from that Bitmap and use the DrawImage method to draw the image on the graphics. At the end, the new Bitmap will contain a merged image, which you'll need to save. The code also contains a few Dispose() calls, which releases all used resources by those objects. Note: don't dispose an object if you need it later.
Image img1 = Image.FromFile("part1.png");
Image img2 = Image.FromFile("part2.png");
int newHeight = Math.Max(img1.Height, img2.Height);
int newWidth = img1.Width + img2.Width;
Bitmap merged = new Bitmap(newWidth, newHeight);
Graphics gr = Graphics.FromImage(merged);
gr.DrawImage(img1, new Point(0, 0));
gr.DrawImage(img2, new Point(img1.Width, 0));
gr.Dispose();
merged.Save("result.png", ImageFormat.Png); // or another format
img1.Dispose();
img2.Dispose();
merged.Dispose();


是否可以以没有异常边界(工件)将出现在合并的图像中,完全取决于您尝试合并的图像!



而且,我建议你......除非你处于具有相同背景,照明和聚焦等的图像的幸运位置......你无法自动化:需要熟练的操作人员决定在何处裁剪每个图像在重新粉刷之前获得看起来不像修补挡泥板的东西:)



Adob​​e拥有世界级的计算机科学家,他们已经工作了很长时间 - 是时候在PhotoShop中开发当前的内容感知填充,缩放,修复,修补和移动工具。这些工具使用的算法非常复杂!



即使使用这些工具:在当前的PhotoShop CC(我使用的)中,尽可能好,大多数当合并之前以及合并之后,使用PhotoShop进行进一步处理的时间。通常,您可以进行预合并调色板校正,对比度和亮度校正以及合并后,执行锐化/模糊/消除锯齿(羽化)的一些组合,并应用其他滤镜。



我不是说你不能创建一个对简单合并有用的工具;只是告诉你这是一个复杂的问题领域,你将受到你必须使用的图像的约束。



在实际的基础上,我想要看到一个用户界面,至少:



1.显示两个图像,显示有关它们的摘要信息:大小,位深度,任何颜色调色板信息在EXIF(sRGB?或???)。



2.让您将其中一个或两个转换为您选择的位深度和调色板。



3.让你通过一些鼠标动作ui,或通过数字输入,一个或两个图像来裁剪



4.让你调整相对对比度和亮度。



5.让你指定最终输出尺寸



6.预览最终输出'撤消



我知道你将从这个挑战自己的绝佳机会中学到很多东西!
Whether two images can be merged (composited) in a way that no unusual boundary (artifacts) will appear in the merged image, depends entirely on the images you are attempting to merge !

And, I propose to you that ... unless you are in the fortunate position of having images with the same background, and lighting, and focus, etc. ... there's no way you can "automate" that: that it will take a skilled human operator making decisions on where to crop each image to get something that's doesn't look like patched-up fender before it's repainted :)

Adobe has world-class computer scientists who've worked for a very long-time to develop the current "Content Aware" Fill, Scale, Heal, Patch, and Move, tools in PhotoShop. The algorithms those tools use are extremely complex !

And, even with those tools: in the current PhotoShop CC (which I use), as good as they are, most of the time it will take further processing by the person using PhotoShop to tweak the images before they are merged, and after they are merged. Typically you might do pre-merge color palette correction, contrast and brightness correction, and post-merge, perform some combination of sharpening/blur/anti-alias (feathering), and apply other filters.

I'm not saying you can't create a tool that's useful for simple merges; just advising you that this is a complex problem domain, and you will be constrained by the images you have to work with.

On a practical basis, I'd want to see a user-interface that, at minimum:

1. showed both images, presented summary information about them: size, bit-depth, any color-palette information in the EXIF (sRGB ? or ???).

2. let you convert either or both to a bit-depth and color palette you chose.

3. let you crop by some mouse-action ui, or by numeric entry, either, or both, images

4. let you adjust relative contrast, and brightness.

5. let you specify final output size

6. preview final output with 'undo

I know you will learn a lot from this wonderful opportunity to challenge yourself !


这篇关于如何在不合并边框的情况下合并两个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆