Ask Your Question
0

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

asked 2016-05-27 10:12:25 -0600

marcoE gravatar image

updated 2016-05-28 07:21:36 -0600

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
img1 = cv2.imread('transparency.jpg')

img2 = cv2.imread('La1.png')


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 flag offensive close merge delete

Comments

check this answer hereaddWeighted should do the trick ;-)

theodore gravatar imagetheodore ( 2016-05-27 11:27:04 -0600 )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".

marcoE gravatar imagemarcoE ( 2016-05-27 17:46:35 -0600 )edit
1

@marcoE please don't upload such a big files.

sturkmen gravatar imagesturkmen ( 2016-05-28 07:23:17 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-05-28 05:53:10 -0600

theodore gravatar image

updated 2016-05-28 05:56:47 -0600

@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.

edit flag offensive delete link more

Comments

@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.

marcoE gravatar imagemarcoE ( 2016-05-28 05:58:08 -0600 )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.

theodore gravatar imagetheodore ( 2016-05-28 06:27:12 -0600 )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

marcoE gravatar imagemarcoE ( 2016-05-28 15:00:29 -0600 )edit

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

marcoE gravatar imagemarcoE ( 2016-05-30 05:09:12 -0600 )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 .

marcoE gravatar imagemarcoE ( 2016-05-30 07:46:43 -0600 )edit

This is not easier or trivial :\

marcoE gravatar imagemarcoE ( 2016-05-31 06:20:22 -0600 )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.

marcoE gravatar imagemarcoE ( 2016-05-31 07:34:37 -0600 )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

LBerger gravatar imageLBerger ( 2016-05-31 08:03:57 -0600 )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.

marcoE gravatar imagemarcoE ( 2016-05-31 15:26:14 -0600 )edit

Something like this : holes with center

marcoE gravatar imagemarcoE ( 2016-06-01 09:21:32 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-05-27 10:12:25 -0600

Seen: 4,072 times

Last updated: May 28 '16