Click here to Skip to main content
13,003,102 members (58,645 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi everyone,

I am using C# programming language and I am currently trying to stitch between two images by using the concept of image subtraction . I choose two images as input which identically sized images and produces as output a third image. The images are the gray scale images. Basically my result images should be the panorama images. Is it possible by using that concept to stitch the images? Thanks for your comments and advises
Posted 21-Oct-11 9:10am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Yes it is possible.

I assume by subtraction you are wanting to have the area of which is more 0ed be the stictched area.

You will need some thresholding and such, but it is really not that complicated. If performance matters though, you may want to consider a few things such as processing in native code or using 3rd party libraries. Using the GetPixel and SetPixel is extremly slow and this process will require you to touch a lot of pixels. If you want to stay in C# and don't want to use 3rd party I recomend using unsafe code chuncks.

AForge[^] is a pretty good open source library and there are also numerous others (just google around for Image Libraries).

If you do not need many other image processing techniques though building it yourself would not be too hard and you would learn quite a bit. If you get stuck feel free to post some more specific questions and I am sure you will get some help.
kueshukri 21-Oct-11 19:50pm
Thank you so much for your suggestion.
kueshukri 21-Oct-11 20:09pm
Actually I am trying to program it without . I have sent my source code. Maybe you can have a look on my code
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

And this the source code which I have written so far. But this source code still has some mistakes. I am still unable to stitch the image but my source code can subtract between the two images and merge them together.

The problems are :
1. The images are only "merged" together but they are not stitched together.
2. The size of the output images are still same. I need to get the size of the output image base on the size of the stitched image. So in other words the size of the image should change after I apply the result.

       public Bitmap Substraction(Bitmap bmpA, Bitmap bmpB)
            BitmapData bmpData_A = bmpA.LockBits(new Rectangle(0, 0, bmpA.Width, bmpA.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
            BitmapData bmpData_B = bmpB.LockBits(new Rectangle(0, 0, bmpB.Width, bmpB.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
            int width_A = bmpData_A.Width;
            int width_B = bmpData_B.Width;
            int height_A = bmpData_A.Height;
            int height_B = bmpData_B.Height;

            Bitmap input_img1 = new Bitmap(bmpA, width_A, height_A);
            Bitmap input_img2 = new Bitmap(bmpB, width_B, height_B);
            int width_output = width_A + width_B;
            int height_output = height_A + width_B;
            Bitmap output_image = new Bitmap(width_A, height_B);
            BitmapData bmpdata1 = input_img1.LockBits(new Rectangle(0, 0, input_img1.Width, input_img1.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
            BitmapData bmpdata2 = input_img2.LockBits(new Rectangle(0, 0, input_img2.Width, input_img2.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
            BitmapData bmpoutput = output_image.LockBits(new Rectangle(0, 0, output_image.Width, output_image.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
                int ptr1 = bmpdata1.Stride - bmpdata1.Width * 3;
                int ptr2 = bmpdata2.Stride - bmpdata2.Width * 3;
                int ptr3 = bmpoutput.Stride - bmpoutput.Width * 3;
                //Pointing towards the 1st byte in Array
                byte* p1 = (byte*)bmpdata1.Scan0;
                byte* p2 = (byte*)bmpdata2.Scan0;
                byte* p3 = (byte*)bmpoutput.Scan0;
                for (int y = 0; y < height_A; y++)
                    for (int x = 0; x < width_A * 3; x++)
                            p3[0] = (byte)(Math.Abs(p2[0] - p1[0]));
                    p1 += ptr1;
                    p2 += ptr2;
                    p3 += ptr3;
            return output_image;

As always, Thank you so much for your comments and advices. I appreciate it a lot.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170626.1 | Last Updated 21 Oct 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100