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

  • SEARCH
  • Home
  • 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 567107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:02:52+00:00 2026-05-13T13:02:52+00:00

After detecting the lines in an image using Hough lines , how can I

  • 0

After detecting the lines in an image using Hough lines, how can I use it to calculate the change in angle (rotation) of the lines of a reference image?

  • 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-05-13T13:02:53+00:00Added an answer on May 13, 2026 at 1:02 pm

    Note to readers: This is a follow-up question, refer to these for background:

    • How to select maximum intensity in Hough transform in MATLAB?
    • Calculating displacement moved in MATLAB

    The process is similar to what I showed before. Below I am using the images from your previous question (since you provided only one, I created the other by rotating the first by 10 degrees).

    We start by detecting the lines for the two images. We do this with the help of the Hough transform functions. This what it looks like applied to both images:

    Images with detected lines and points order

    Next, we want to perform image registration using the line endpoints as control-points. First, we make sure the points correspond to each other in the two images. I do this by computing the convex hull using convhull which automatically sorts them in counterclockwise-order (or is it in the opposite direction!). The numbers shown above indicate the order.

    Finally, we use the function cp2tform to get the transformation matrix, which we use to align the images and extract the translation, rotation, and scaling.

    The following is the complete code:

    %% # Step 1: read and prepare images
    %# (since you provided only one, I created the other by rotating the first).
    I1 = imread('https://i.stack.imgur.com/Se6zX.jpg');
    I1 = rgb2gray( imcrop(I1, [85   35  445  345]) ); %# Get rid of white border
    I2 = imrotate(I1, -10, 'bilinear', 'crop'); %# Create 2nd by rotating 10 degrees
    
    %% # Step 2: detect the cross sign endpoints (sorted in same order)
    p1 = getCross(I1);
    p2 = getCross(I2);
    
    %% # Step 3: perform Image Registration
    %# Find transformation that maps I2 to I1 using the 4 control points for each
    t = cp2tform(p2,p1,'affine');
    
    %# Transform I2 to be aligned with I1
    II2 = imtransform(I2, t, 'XData',[1 size(I1,2)], 'YData',[1 size(I1,1)]);
    
    %# Plot
    figure('menu','none')
    subplot(131), imshow(I1), title('I1')
    subplot(132), imshow(I2), title('I2')
    subplot(133), imshow(II2), title('I2 (aligned)')
    
    %# Recover affine transformation params (translation, rotation, scale)
    ss = t.tdata.Tinv(2,1);
    sc = t.tdata.Tinv(1,1);
    tx = t.tdata.Tinv(3,1);
    ty = t.tdata.Tinv(3,2);
    scale = sqrt(ss*ss + sc*sc)
    rotation = atan2(ss,sc)*180/pi
    translation = [tx ty]
    

    And here’s the function that extract the lines endpoints:

    function points = getCross(I)
        %# Get edges (simply by thresholding)
        I = imfilter(I, fspecial('gaussian', [7 7], 1), 'symmetric');
        BW = imclearborder(~im2bw(I, 0.5));
    
        %# Hough transform
        [H,T,R] = hough(BW);
    
        %# Detect peaks
        P  = houghpeaks(H, 2);
    
        %# Detect lines
        lines = houghlines(BW, T, R, P);
    
        %# Sort 2D points in counterclockwise order
        points = [vertcat(lines.point1); vertcat(lines.point2)];
        idx = convhull(points(:,1), points(:,2));
        points = points(idx(1:end-1),:);
    end
    

    with the result:

    Resulting aligned image

    scale =
        1.0025
    rotation =
       -9.7041
    translation =
       32.5270  -38.5021
    

    The rotation is recovered as almost 10 degrees (with some inevitable error), and scaling is effectively 1 (meaning there was no zooming). Note that there was a translation component in the above example, because rotation was not performed around the center of the cross sign).

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

Sidebar

Ask A Question

Stats

  • Questions 324k
  • Answers 324k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If I understand correctly, you wish to draw a square… May 14, 2026 at 1:22 am
  • Editorial Team
    Editorial Team added an answer LINQ-to-entities is simply doing something wrong. No, it's working as… May 14, 2026 at 1:22 am
  • Editorial Team
    Editorial Team added an answer You could try this: import ctypes print ctypes.windll.shell32.IsUserAnAdmin() May 14, 2026 at 1:22 am

Related Questions

I must be missing something really obvious, but for some reason, the command-line version
I've just learned the basics of Ruby after being very happy with Python for
Is it possible to detect binary data in JavaScript? I'd like to be able
I would like to monitor a log file that is being written to by
After loading an existing MFC application in Visual Studio 2008, I am left with

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.