Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8186261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:08:03+00:00 2026-06-07T02:08:03+00:00

I am working on a project which requires to find how much a new

  • 0

I am working on a project which requires to find how much a new image has shifted and rotated w.r.t the old image. I am trying to implement it using fft. However, it works for some cases and fails for others. The steps i follow are:

  1. take the two images, implement canny edge detection
  2. find out the shift using fft and remove the shift
  3. transform the image to polar domain and find the shift and convert the answer to radians

In some cases, I get the correct answer but in other cases I get shift as (0,0) and rotation as 0 radians. Please suggest the reason why this may happen.

Here is the code:

class Register:
    '''
        Class for registering images based on FFT. The usage is as follows:
        >>> im0 = imread('image0.jpg', flatten = True)
        >>> im1 = imread('image1.jpg', flatten = True)
        >>> reg = Register(im0, im1)
        >>> shift = reg.shift
        >>> rotation = reg.theta

        Note:
            1. This image registration technique is not very reliable and
               is valid only for small rotation
            2. The class is very slow, since it depends on canny edge detection
               module for finding edges.
    '''
    def __init__(self,imin0, imin1, PROCESSED = False):
        '''
            This method is used to execute all the routines required to get the
            shift and the rotation
        '''
        # find edges to remove low frequency signals and suppress information
        if PROCESSED:
            im0 = imin0
            im1 = imin1
        else:
            im0 = Canny(imin0, 0.85, 5).grad
            im1 = Canny(imin1, 0.85, 5).grad

        # A major drawback of this method is that it can operate only on square
        # images. Hence we will make square image of any input image

        im0 = self.createsquareim(self.clearBorder(im0))
        im1 = self.createsquareim(self.clearBorder(im1))

        self.shift = self.findShift(im0,im1)
        imtrans = shift(im1, self.shift)
        # Remove the shift in the image. This is mandatory before we find theta
        impolar0 = self.makePolar(im0)
        impolar1 = self.makePolar(imtrans)
        self.index = self.findShift(impolar0, impolar1)[1]
        self.theta = ((self.index*90.0)/impolar1.shape[0])

    def clearBorder(self,im,width = 50, color = 255):
        '''
            A little house keeping to clear any border noise
        '''
        im[:,:width] = color
        im[:,-width:] = color
        im[:width,:] = color
        im[-width:,:] = color

        return im

    def createsquareim(self, im):
        """
        function createsquareim
        input:numpy ndarray
        output:numpy ndarray

        The function takes in an image array and converts it into square
        image by creating empty columns and rows.
        """
        lenmax = max(im.shape[0],im.shape[1])
        imout = zeros((lenmax,lenmax))
        imout[:,:] = 255
        imout[:im.shape[0],:im.shape[1]] = im
        return imout

    def findShift(self, im0, im1):
        '''
            This method is based on fft method of registering images.
        '''
        IM0 = fft2(im0)
        IM1 = fft2(im1)

        numer = IM0*conj(IM1)
        denom = abs(IM0*IM1)

        pulse_im = ifft2(numer/denom)
        mag = abs(pulse_im)
        x, y = where(mag == mag.max())

        x = array(x.tolist())   # Issues with read only arrays
        y = array(y.tolist())

        X, Y = im0.shape

        if x > X/2:
            x -= X
        if y > Y/2:
            y -= Y

        return [x[0], y[0]]

    def makePolar(self, im):
        '''
            This method will convert the cartesian coordinates image
            to polar coordinates image. The relation between the two
            domains is
              F(r,theta) = f(r*cos(theta),r*sin(theta))
            To make the process fast, we are using map_coordinates function
        '''
        m, n = im.shape
        r_max = hypot(m, n)

        r_mat = zeros_like(im)
        t_mat = zeros_like(im)

        r_mat.T[:] = linspace(0, r_max, m)
        t_mat[:] = linspace(0, pi/2, n)

        x = r_mat*cos(t_mat)
        y = r_mat*sin(t_mat)

        imout = zeros_like(im)
        imout = map_coordinates(im, [x, y], cval = 255)

        return imout
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T02:08:05+00:00Added an answer on June 7, 2026 at 2:08 am

    I have written a python script for image registration using SIFT and RANSAC algorithm, you can find the code at http://github.com/vishwa91/pyimreg. Also, a small intro to the same can be found at http://cyroforge.wordpress.com/2012/07/05/image-registration-using-python/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a new project which requires a image gallery as well
Can anyone help me find an up-to-date, working ATL project which has a main
i am working on a project which requires some image processing, i also asked
I'm working on a project that requires threaded conversation: someone posts something new which
I was working on a project which requires to download content from a database.
Hello everyone i am working on a project which requires me to export some
I have started working on a project which requires Natural Language Processing. We have
I am working on a project report which requires some tricky output from a
I'm working on a project for my companies intranet which requires that multiple attached
A project I'm working on needs avro, which requires python-snappy, which requires snappy. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.