# How can I fit and then overlay 2 images which have different resolution ?

One represents has a mesh, which is supposed to overlay the Layer1 . I didn't find how can I do this using the opencv. I know that is possible change image resolution, however, I don't know how to fit both images

This is the main image: image1 - (2.6 MB)

I have this one, which has the correct mesh to the image above:

image2 - (26.4 MB)

The code to change resolution is more or less this :

#!/usr/bin/python

import cv2
from matplotlib import pyplot as plt
import numpy as np

row1,cols1, ch1 = img1.shape
row2,cols2, ch2 = img2.shape

res = cv2.resize(img2, None , fx = (1.* row1 /row2 ), fy =(1.* cols1 /cols2 ), interpolation = cv2.INTER_CUBIC)

edit retag close merge delete

check this answer hereaddWeighted should do the trick ;-)

( 2016-05-27 11:27:04 -0500 )edit

thx tor the tip @theodore. However, It could only help me with the overlay part. How can I fit properly the shapes? If you look at the booth images they must fit. The mesh should be the "boundary".

( 2016-05-27 17:46:35 -0500 )edit
1

( 2016-05-28 07:23:17 -0500 )edit

Sort by ยป oldest newest most voted

@marcoE sorry I thought that the two images were already alingned, my bad. Well, what you need is to find the transformation matrix between the two images, with the findHomography() function. In order to do that you need to find at least 4 points that correspond to each other in the two images and then apply the transformation by using the extracted transformation matrix in the warpperspective() function. Usually, people for that they use a feature keypoints extraction algorithm, like surf,sift, etc... find the matched points and then use them to extract the transformation matrix as I described above. You need these 4 points at least, so if you have them somehow from a previous process (contours, canny, whatever...) to the two images you can use them, if not then you need to extract them somehow. Looking at your two images, extracting features with a keypoints algorithm I do not think that it will work. What I see that you can do is to extract the horizontal and vertical lines and use the endpoints as the needed points for the homography and then apply the transformation as I described above.

In order to see about what I am talking have a look in some examples here and here. if you search about warpperspective align two images opencv in the web you will find some other examples as well.

more

@theodore thank you for your time, patience and kindness. It is difficult to do what I need to do :\ I need to do something kike that : link text . This was made with imagemagick. However, the images were with lower resolution, and the mesh is different. I think with this image you are able to figure out what I need to do. I will see the algorithm.

( 2016-05-28 05:58:08 -0500 )edit

I do not think that it is that hard, what you want to do. More or less you have the material you need. You just need to mix them in the proper way. Unfortunately, I do not have that much free time at the moment otherwise I could help you with some code as well.

( 2016-05-28 06:27:12 -0500 )edit

@LBerger , Yes, as I mentioned there are different images, with similarities on shape. I want to do something like this: http://i.stack.imgur.com/fyixS.jpg

( 2016-05-28 15:00:29 -0500 )edit

@LBerger , @theodore , @sturkmen , any brillant idea?

( 2016-05-30 05:09:12 -0500 )edit

@LBerger the image with the mesh is a render created using matplotlib. From this image, using potrace I got this vector, which allows me get the mesh using trimesh pythom modulel stl, using matplotlib to render, I got the mesh that you've seen .

( 2016-05-30 07:46:43 -0500 )edit

This is not easier or trivial :\

( 2016-05-31 06:20:22 -0500 )edit

@LBerger it is not a really alighment .If you look here . you'd notice the mesh (at red) it is the internal countour of the overlaied picture. This example it's with other images and it was done with imagemagick.

( 2016-05-31 07:34:37 -0500 )edit

In your example you have two images R and B(red and black). I think you want to minimize |R(x,y)-B(ax+x0,by+y0)]^2 relative to unknown a,b,x0,y0

( 2016-05-31 08:03:57 -0500 )edit

@LBerger I think I'm getting what your telling. However, I don't think if it solves the aligment problem. I was thinking about the problem. If at the primary image (the one with the boundaries, which later is used to generate the mesh) it is added points (for instance, holes center), later at the mesh image, could they be matched ? If the points are the same in all images (all the images have holes center) could it solve the problem? Like a plot layer to guide the others. I don't know how to do it, I'm just thinking from the concept point of view.

( 2016-05-31 15:26:14 -0500 )edit

Something like this : holes with center

( 2016-06-01 09:21:32 -0500 )edit

Official site

GitHub

Wiki

Documentation