#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    7
    Rep Power
    0

    Image Stitching in Python


    Hello everybody.. I am working to develop a code for image stitching in python. As input I use hdf5 images which I convert into tiff files for ease of use. I also have a naive stitching method which stitches images -- infact opens images one after another. But the stitching i am trying to achieve is that these images should be stitched by taking the common regions between them. i.e. the second image has some region which is similar to the first image, the third image with some region similar to the second and so on. In total there are 16 such images. The code should be able to find the common regions and then stitch them...

    I am new to python programming and any help and code snippets would greatly benefit me to proceed further...

    Thanks in advance !!!
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,900
    Rep Power
    481
    I'd use Nelder-Mead optimization with scipy module
    http://docs.scipy.org/doc/scipy/reference/tutorial/optimize.html

    How many degrees of freedom need you account for?

    You described translation in at least one direction,

    Possibly translation in the perpendicular direction as well,

    If you changed the focal length you'd need a scale factor,

    Did the camera tilt? You'd need to account for rotation.

    Change a color filter? Maybe you could convert the images to gray scale and include a pixel value scale factor. (Or you could eliminate this variable before optimization by adjusting brightness to make the approximate overlapped regions have same average brightness.)

    Some of these parameters could be constrained. I usually construct artificial large values to steer around invalid data values.

    I've solved a similar problem using a coordinate measuring machine to characterize a part that was a good deal larger than fit. Instead of pixel data I had grids of accurate 3D Cartesian data to match. In my case I had, you might say, large pixels corresponding to the measurement grid. I mapped the continuous surface using interpolation to account for sub-pixel manipulation. I presume in your case you'd be satisfied to match pixels---they are (probably) small.

    You could do all the image manipulation with the imagemagick convert program although that would be slow if you have to do this many times. convert would handle rotation and cropping---probably the only parameters you need. The value to minimize would be the sum of squared differences between pixel values of the cropped portion of the first picture with the cropped portion of the second rotated picture.

    Anyway, I could write the code but then again, maybe you can too. Sound up if you want additional help.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    7
    Rep Power
    0
    @ b49P23TIvg : Thank you so much for your reply..
    We dont use a camera here but an imaging source - X-ray or CT imaging. So the image is captured in the detector. Since the whole sample cannot be scanned at one shot we scan the sample at multiple positions. This gives a dataset which are in the form of hdf5 images. So for easy processing I converted them to tif files.

    The problem that you have solved looks similar as the end result is to have all the images stitched with difference in similar regions properly blended. I am am enclosing the first 8 images of the total 16.. You can have a look at them and then maybe try with your code.

    The matching can be done automatically i.e the code finds the similar regions and blends them automatically; or the user loads the images one by one in a UI and then moves the second image over the first image and then the blending should take place.

    Your help would be greatly appreciated.....
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    7
    Rep Power
    0
    I am not able to post my images here.. No permit to paste URLS
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    7
    Rep Power
    0

    https://www.dropbox.com/s/bogxhd3kfejn27v/tiffdpc.zip


    Atlast the images
  10. #6
  11. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,900
    Rep Power
    481
    The strips fit together as shown (attached)? Left to right in sequence number with fairly small overlap, top and bottom strips are noise to ignore. The images appear brighter on the right hand side.

    [edit]The brightness feature looks more like varied shadowing from a point source of your x-rays[/edit]

    [edit] picture removed, we've agreed about how the images fit together [/edit]
    Last edited by b49P23TIvg; July 18th, 2012 at 10:06 PM.
    [code]Code tags[/code] are essential for python code and Makefiles!
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    7
    Rep Power
    0
    Great this looks really nice... Could you be kind enough to share the code so that I can play around a bit... Thank you so much for your help.....
  14. #8
  15. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,900
    Rep Power
    481
    OK, here's code written in j, executable Iverson notation that merges two bitmap files. It works with bitmap files (.bmp) and you'll need the graphics addon. If you'd like a python program that does the job I'm available for hire. The attachment shows your 2 and 3 files merged in red. The overlap appears in the noisy region top center.

    Code:
    load'bmp'
    'LEFT RIGHT'=:(255(#.1 0 0 0 1)b.readbmp@:(,&'.bmp'))&.:>;._2'rec_dpc_0002 rec_dpc_0003 '
    goal=:[:+/*:@:-&,
    SLAB=:401 20{.112}.RIGHT
    I=:1000+(i.<./),(0 1,:401 20)((SLAB)&goal;._3)112 1000}.LEFT
    S=:I-~{:$LEFT
    mean=:+/%#
    MERGED=:((_,I){.LEFT),.(<.@:mean((0,I)}.LEFT),:(_,S){.RIGHT),.(0,S)}.RIGHT
    MERGED writebmp'/tmp/23.bmp'
    (I may need to delete other attachments to fit this picture.)
    [edit]Also I'll reduce the size to 1/4. picture uploaded[/edit]
    [edit2]Given the nature of the problem I used a simpler technique than Nelder-Mead optimization. I had originally thought you might be making a panoramic composite picture from a hand held camera on a windy mountain top.[/edit2]
    Attached Images
    • File Type: png 23.png (561.9 KB, 104 views)
    Last edited by b49P23TIvg; July 18th, 2012 at 10:16 PM.
    [code]Code tags[/code] are essential for python code and Makefiles!
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    7
    Rep Power
    0
    Cool stuff... Would be great if i could have a python program doing this job.. I could then test it with different algorithms...
  18. #10
  19. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,900
    Rep Power
    481
    I'm unemployed, the work involves experience and education.
    [code]Code tags[/code] are essential for python code and Makefiles!
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    7
    Rep Power
    0
    Thanks for your help till now...
  22. #12
  23. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,900
    Rep Power
    481
    You have access to unusual equipment, and therefor resources of some sort.
    Are you a poor graduate student seeking thesis help?
    Are you part of an R&D group hoping to advance your career?
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo