简体   繁体   English

(EMGU) 如何拆分和合并图像?

[英](EMGU) How do I split and merge an Image?

I am working in C# on Visual Studio with Emgu.我正在使用 Emgu 在 Visual Studio 上的 C# 中工作。

I am doing a several image manipulations on a large image.我正在对大图像进行几次图像处理。 I had the idea of splitting the image in half, doing the manipulations in parallel, them merging the image.我的想法是将图像分成两半,并行进行操作,然后合并图像。

In pursuit of this goal, I have found a number of questions regarding the acquisition of rectangular parts of images for processing as well as splitting an image into channels (RGB, HSV, etc).为了实现这个目标,我发现了许多关于获取图像的矩形部分进行处理以及将图像分割成通道(RGB、HSV 等)的问题。 I have not found a question that addresses the task of taking an image, and making it into two images.我还没有找到解决拍摄图像并将其制作成两个图像的任务的问题。 I have also not found a question that addresses taking two images and tacking them together.我也没有找到解决拍摄两张图像并将它们拼接在一起的问题。

The following code is what I would like to do, where split and merge are imaginary methods to accomplish it.以下代码是我想做的,其中拆分和合并是实现它的虚构方法。

Image<Bgr,Byte> ogImage = new Image<Bgr, byte>(request.image);
Image<Bgr,Byte> topHalf = new Image<Bgr, byte>();
Image<Bgr,Byte> bottomHalf = new Image<Bgr, byte>();

ogImage.splitHorizonally(topHalf,bottomHalf);

//operations

ogImage = topHalf.merge(bottomHalf);

This is the type of question I hate asking, because it is simple and you would think it has a simple, easily available solution, but I have not found it, or I have found it and not understood it.这是我讨厌问的那种问题,因为它很简单,你会认为它有一个简单、容易获得的解决方案,但我没有找到它,或者我找到了它但不理解它。

There are a number of ways to solve this but here is what I did.有很多方法可以解决这个问题,但这就是我所做的。 I took the easiest way out;-)我采取了最简单的方法;-)

    Mat lena = new Mat(@"D:\OpenCV\opencv-3.2.0\samples\data\Lena.jpg", 
                       ImreadModes.Unchanged);

    CvInvoke.Imshow("Lena", lena);

    System.Drawing.Rectangle topRect = new Rectangle(0, 
                                                     0, 
                                                     lena.Width,
                                                     (lena.Height / 2));

    System.Drawing.Rectangle bottomRect = new Rectangle(0, 
                                                        (lena.Height / 2),
                                                        lena.Width,
                                                        (lena.Height / 2));

    Mat lenaTop = new Mat(lena, topRect);

    CvInvoke.Imshow("Lena Top", lenaTop);

    Mat lenaBottom = new Mat(lena, bottomRect);

    CvInvoke.Imshow("Lena Bottom", lenaBottom);

    Mat newLena = new Mat();

    CvInvoke.VConcat(lenaBottom, lenaTop, newLena);

    CvInvoke.Imshow("New Lena", newLena);

    CvInvoke.WaitKey(0);

Original Lena原版莉娜

莉娜原创

Lena Top Half莉娜上半场

莉娜上半场

Lena Bottom Half莉娜下半场

莉娜下半场

The New Lena Rearranged新莉娜重新安排

新莉娜

Your goal isn't splitting an image.您的目标不是分割图像。 Your goal is to parallelize some operation on the image.您的目标是并行化图像上的一些操作

You did not disclose the specific operations you need to perform.您没有透露您需要执行的具体操作。 That is important to know however, if you want to parallelize those operations.但是,如果您想并行化这些操作,那么了解这一点很重要。

You need to learn about strategies for parallelization in general.您需要了解一般的并行化策略。 Commonly, a "kernel" is executed on several partitions of the data in parallel.通常,“内核”在数据的多个分区上并行执行。

One practical approach is called OpenMP .一种实用的方法称为OpenMP You apply "pragmas" to your own loops and OpenMP spreads those loop iterations across different threads.您将“编译指示”应用到您自己的循环中,OpenMP 将这些循环迭代传播到不同的线程中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM