Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ImageProcessing
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 10:10am
Rate this: bad
good
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.
  Permalink  
Comments
kueshukri at 21-Oct-11 19:50pm
   
Thank you so much for your suggestion.
kueshukri at 21-Oct-11 20:09pm
   
Actually I am trying to program it without AForge.net . I have sent my source code. Maybe you can have a look on my code
Rate this: bad
good
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;
 
            bmpA.UnlockBits(bmpData_A);
            bmpB.UnlockBits(bmpData_B);
 

            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);
 
            
            unsafe
            {
                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++;
                            p2++;
                            p3++;
                            
 
                    }
 
                    p1 += ptr1;
                    p2 += ptr2;
                    p3 += ptr3;
 
                }
 
            }
 
            input_img1.UnlockBits(bmpdata1);
            input_img2.UnlockBits(bmpdata2);
            output_image.UnlockBits(bmpoutput);
 
            return output_image;
 
        }
As always, Thank you so much for your comments and advices. I appreciate it a lot.
  Permalink  

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



Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 21 Oct 2011
Copyright © CodeProject, 1999-2014
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