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 6877651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:37:34+00:00 2026-05-27T04:37:34+00:00

I’m trying to implement hough transform for lines in matlab. And I have been

  • 0

I’m trying to implement hough transform for lines in matlab. And I have been struggling with this for days, I don’t know why my code isn’t working the way it should. Yes, it is part of the homework, but please help me out, because I totally gave up.

Input paramaters: Ie – logical “edge” image (0 means not an edge, 1 means edge).

function [out_ro, out_theta]=houghTransform(Ie,nBinsRo,nBinsTheta,tresh)

A = zeros(nBinsRo, nBinsTheta);

theta = 1:nBinsTheta;

theta = scale(theta, nBinsTheta, 1, (pi / 2), - (pi / 2));

D = size(diag(Ie));

D = D(1);

ro = 1:nBinsRo;

ro = scale(ro, nBinsRo, 1, D, -D);

len = size(Ie);

%checks all edges

for i = 1:len(1)

for j = 1:len(2)

    %if it is an edge

    if ((Ie(i,j) == 1))

        %generate all functions x cos(theta) + y sin(theta) = ro
        for m=1:nBinsTheta

            roVal = i * cos(theta(m)) + j * sin(theta(m));

            idx = scale2(roVal, D, -D, nBinsRo, 1);

            if (idx > 0 && idx < nBinsRo)

                A(idx, m) = A(idx, m) + 1;

            end

        end

    end

end

end

figure(1);
clf;
imagesc(A)


% -------------------------------------------------- %

function idx = scale(val, max_val_in, min_val_in, max_val_out, min_val_out)

skalirni_faktor = (max_val_out - min_val_out) / (max_val_in - min_val_in) ;

idx = min_val_out + (val-min_val_in) .* skalirni_faktor;

% -------------------------------------------------- %

function idx = scale2(val, max_val_in, min_val_in, max_val_out, min_val_out)

skalirni_faktor = (max_val_out - min_val_out) / (max_val_in - min_val_in) ;

idx = min_val_out + round((val-min_val_in) .* skalirni_faktor);

Thank you very much for your time and answers.

  • 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-27T04:37:34+00:00Added an answer on May 27, 2026 at 4:37 am

    I couldn’t find what was wrong with the code, but I assume that scaling is problematic.

    If anyone finds this, here is another implementation of hough transform.

    function [rho,theta,houghSpace] = houghTransform(theImage,thetaSampleFrequency)
    
    %#Define the hough space
    theImage = flipud(theImage);
    [width,height] = size(theImage);
    
    rhoLimit = norm([width height]);
    rho = (-rhoLimit:1:rhoLimit);          
    theta = (0:thetaSampleFrequency:pi);
    
    numThetas = numel(theta);
    houghSpace = zeros(numel(rho),numThetas);
    
    %#Find the "edge" pixels
    [xIndicies,yIndicies] = find(theImage);
    
    %#Preallocate space for the accumulator array
    numEdgePixels = numel(xIndicies);
    accumulator = zeros(numEdgePixels,numThetas);
    
    %#Preallocate cosine and sine calculations to increase speed. In
    %#addition to precallculating sine and cosine we are also multiplying
    %#them by the proper pixel weights such that the rows will be indexed by 
    %#the pixel number and the columns will be indexed by the thetas.
    %#Example: cosine(3,:) is 2*cosine(0 to pi)
    %#         cosine(:,1) is (0 to width of image)*cosine(0)
    cosine = (0:width-1)'*cos(theta); %#Matrix Outerproduct  
    sine = (0:height-1)'*sin(theta); %#Matrix Outerproduct
    
    accumulator((1:numEdgePixels),:) = cosine(xIndicies,:) + sine(yIndicies,:);
    
    %#Scan over the thetas and bin the rhos 
    for i = (1:numThetas)
        houghSpace(:,i) = hist(accumulator(:,i),rho);
    end
    
    pcolor(theta,rho,houghSpace);
    shading flat;
    title('Hough Transform');
    xlabel('Theta (radians)');
    ylabel('Rho (pixels)');
    colormap('gray');
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) 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.