33

Is there a tool in Ubuntu to automatically merge two images having a common strip? I need to scan a large image, which will not fit at once in the scanner. I was thinking about scanning it in two parts and hand-editing the result in Gimp to join them. But probably an automatic tool can do the same more quickly and better.

EDIT I think I may have not made my point clear. My difficulty is not aligning two images. My problem is that one has to compensate for the rotation or distortion introduced by the manual process of putting the sheet into the scanner, and an automatic tool should obtain more precise results at analyzing common patterns in the two images to rotate and align them seamlessly.

4 Answers 4

43

Using the tools provided with ImageMagick

Install via the software center

We can easily join, i.e. "montage" images into one large image with the following command

montage -geometry 500 image1 image2 [...] output

See the project page for many parameters of the geometry option. CAUTION: the output argument is non-optional, having just two images on argument list ends up replacing image2 without warning. In the example above all images will be scaled to a width of 500 pixels before they are joined. Adapt this value for your image sizes. In case you need to have a fixed height choose x500 instead. The other dimension will be scaled to preserve the aspect ratio.


Inspired by this post saying that ImageMagick has command line tool named convert to merge images. To join images horizontally (in alphabetical order):

convert +append *.png out.png 

To stack images vertically:

convert -append *.png out.png

That should be run in a terminal into the folder containing png files to join them all.

A gui for that would be:

a file manager context menu to join selected images.

An easy way when it comes to that is Thunar's custom actions:

To join selected images vertically (into one png file, in alphabetical order, no matter their extension) add this custom action:

convert -append %F joined-vertical.png

To join horizontally:

convert +append %F joined-horizontal.png

For a more sophisticated way to assemble images you may want to search for panorama photo stitcher software such as hugin Install hugin

Install via the software center

or the Pandora plugin for Gimp.

9
  • Will montage automatically match similar parts in the two images?
    – Andrea
    Jul 22, 2012 at 20:06
  • Sorry, then this is not what I am looking for. The whole point of the question is finding a tool that will match similar parts in the two images automatically.
    – Andrea
    Jul 22, 2012 at 20:10
  • 1
    you are the best :)
    – stupidity
    Nov 6, 2013 at 3:18
  • @Andrea: have you found any way to solve your problem? Montage is not for you, but have a look at other command: imagemagick.org/script/command-line-tools.php
    – Ooker
    Jul 18, 2014 at 12:25
  • 1
    @landroni - I've made an edit that provides a way to join vertically as well
    – user47206
    Mar 5, 2017 at 13:38
6

You can easily achieve that with Gimp.

1)Make a new file File->New

At the "create new image" dialog add the desired height and width.That will give you your new file which may look like this (depending on the dimensions you set) :

2)Open the two images you want to merge from File -> Open...

3)Then click copy at the image Edit -> Copy...

4)Go to the empty file you created first at step 1 and paste the images (Copy and paste the first image and then copy and paste the second) Edit -> Paste

5)Position the two images using the "Move" option from the Toolbox

When the pasted image is where you want it, set it in place. Either move your cursor on the canvas until you see a little anchor symbol, or click "Layer" on the Toolbar, then select "Anchor":

6)Scale the new file with the two merged pictures Image -> Scale Image...

3
  • This is what I was thinking to do. Then again, probably an automatic tool can do the same more quickly and better. My point is that an automatic tool should align things better than I do by hand.
    – Andrea
    Jul 22, 2012 at 16:47
  • I am not aware if there are any programs for such a simple thing really.But still, I am sure you cannot be THAT lazy..it won't take you more than 5 minutes :)
    – dlin
    Jul 22, 2012 at 19:52
  • The point is not laziness. Putting the big sheet into the scanner produces two images that are slightly rotated, and I need to compensate for that. Doing that by hand so that the result is seamless is not so easy
    – Andrea
    Jul 22, 2012 at 20:05
5

I finally settled for Hugin. It requires some manual intervention, but has produced a really good result.

Here is a tutorial that explains how to use Hugin so that it will not try to deform your flat images (the tool was born to produce panorama images from single pictures, hence it usually compensates for the perspective effects).

1
  • why don't you accept this?
    – Ooker
    Jul 18, 2014 at 17:23
1

I've successfully joined jpg's into panorama by using a program called fotoxx. It has a tool for just that purpose under the toolbar "Combine"

1
  • Aha. Now how can I install and use that program? Is there any procedure?
    – Braiam
    Nov 30, 2013 at 18:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .