|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "Image Stitching: Part 2" |
| 4 | +date: 2017-06-26 |
| 5 | +mathjax: true |
| 6 | +widgets: true |
| 7 | +--- |
| 8 | + |
| 9 | +This is Part 2 of 2 in my posts about how to stitch two images together using Julia. It's rough around the edges, since I'm learning how to do this myself. In [Part 1]({% post_url 2017-03-26-image-stitching-part-2 %}) I talked about finding keypoints, descriptors, and matching two images together. This time, in Part 2, I'll talk about how to estimate the image transformation and how to actually do the stitching. |
| 10 | + |
| 11 | +## Updating Julia versions |
| 12 | + |
| 13 | +For Part 2 of image stitching, I upgraded to Julia 0.6.0. The process was quite painless - download the `.tar.gz` file from the [julialang.org](http://julialang.org), extract it, and add the `bin/` directory from the extracted archive into my path, as I described in my [initial post about setting up Julia]({% post_url 2017-02-19-launching-learning-julia %}). |
| 14 | + |
| 15 | +Because I wanted to use the latest versions of some packages (and in Julia, they change often!) I had to do some updates before launching the Jupyter Notebook: |
| 16 | + |
| 17 | +``` |
| 18 | +>>> Pkg.add("IJulia"); |
| 19 | +>>> Pkg.clone("https://github.com/JuliaImages/ImageFeatures.jl"); |
| 20 | +>>> Pkg.add("Images"); |
| 21 | +>>> Pkg.clone("https://github.com/JuliaImages/ImageDraw.jl"); |
| 22 | +>>> Pkg.add("FileIO"); |
| 23 | +>>> Pkg.update(); |
| 24 | +>>> using IJulia; |
| 25 | +>>> notebook(dir="notebooks/", detached=true); |
| 26 | +``` |
| 27 | + |
| 28 | +I also had to make sure to change my Jupyter kernel to Julia 0.6.0 - in the menu bar at the top of the page, click on "Kernel" --> "Change Kernel" --> "Julia 0.6.0". No reason to stay stuck to old code! |
| 29 | + |
| 30 | +## Updating some image drawing functions |
| 31 | + |
| 32 | +One of the packages that I had to image ([ImageDraw](https://github.com/JuliaImages/ImageDraw.jl), used for drawing shapes on images), updated their API for drawing lines. There is no longer a syntactic sugar called `line` for drawing lines on images; instead, there is a single `draw` method that accepts targets and `Drawable` objects. I changed my previous code: |
| 33 | + |
| 34 | +``` |
| 35 | +line!(grid, m[1], m[2] + offset) |
| 36 | +``` |
| 37 | + |
| 38 | +to |
| 39 | + |
| 40 | +``` |
| 41 | +draw!(grid, LineSegment(m[1], m[2] + offset)) |
| 42 | +``` |
| 43 | + |
| 44 | +And everything worked great. |
| 45 | + |
| 46 | +BELOW THIS IS OLD STUFF |
| 47 | + |
| 48 | +<!--more--> |
| 49 | + |
| 50 | +I've included my notebook here. You can see the original [on Github](https://github.com/mprat/learningjulia/blob/master/notebooks/05-image-stitching-part-1.ipynb) if you like. |
| 51 | + |
| 52 | +_Note: There are a number of places where I've included the Jupyter Notebook widgets in the rendering below. You can click buttons and slide sliders, but it does not affect the output. It's fun to play with the widgets though!_ |
| 53 | + |
| 54 | +You can also skip to any of the headers below: |
| 55 | + |
| 56 | +* [Setting up and loading images](#Setting-up-and-loading-images) |
| 57 | +* [Extracting feature points](#Extracting-Feature-Points) |
| 58 | +* [Visualizing keypoints](#Visualizing-keypoints) |
| 59 | +* [Calculating descriptors](#Calculating-descriptors) |
| 60 | +* [Matching keypoints and descriptors](#Matching-keypoints) |
| 61 | +* [The end result](#The-end-result) |
| 62 | + |
| 63 | +{% include notebook.html name='05-image-stitching-part-1' %} |
| 64 | + |
| 65 | +## Final thoughts |
| 66 | + |
| 67 | +Extracting image features is a tricky business, and it is often dependent on the domain, type of image, white balance, etc. Before neural networks became popular, these manual orientation and gradient methods were all the rage. In computational photography and graphics, these methods are still going strong because they yield great results. I would be interested, when I'm more familiar with Julia, to dive into using a neural-network-based approach to extracting and matching keypoints between images. Who knows where my next project will take me! |
| 68 | + |
| 69 | +Thank you for reading, as usual! I would love to hear from you if you have any suggestions, comments, or ideas for what I should learn next. |
0 commit comments