Hough Transform: Converted polar coordinates back to Cartesian, but still can’t plot them

So I have already implemented every part of a Hough Transform on my own, except for actually plotting the lines back onto the original image.

I can set up my array of data that I have like this.

points | theta | rho
-------|-------|----
[246,0]   -90    -246
[128,0]   -90    -128
[9,0]     -90     -9
[0,9]      0      9
[0,128]    0     128
[0,246]    0     246

The points are the points that were converted from the peaks in Polar Coordinates. So now I need to draw all six of these lines and I have had no luck.

Edit


So I tried to change my code based off suggestions. This is what I came up with.

function help(img, outfile, peaks, rho, theta)
    imshow(img);
    x0 = 1;
    xend = size(img,2);
    peaks_len=length(peaks);
    for i=1:peaks_len
        peak=peaks(i,:);
        r_ind=peak(1);
        t_ind=peak(2);
        r=rho(r_ind);
        th=theta(t_ind);
        %display([r,th,peak]);

        %// if a vertical line, then draw a vertical line centered at x = r
%         display([r, th]);

        if (th == 0)
            display('th=0');
            display([1, size(img,1)]);
            line([r r], [1 size(img,1)], 'Color', 'green');
        else
            %// Compute starting y coordinate
            y0 = abs((-cosd(th)/sind(th))*x0 + (r / sind(th)))+11;%-25; 

            %// Compute ending y coordinate
            yend = abs((-cosd(th)/sind(th))*xend + (r / sind(th)))+11;%-25;
            display('y');
            display([y0, yend]);
            display('x');
            display([x0 xend]);
             %// Draw the line
            line([x0 xend], [y0 yend], 'Color', 'green');
        end
    end
end

I had to change from r==0 to th==0 because th=0 would give NAN errors when r was not 0.

Based off the peaks, I then used that to get the data I needed to then calculate some values… but for some reason this isn’t plotting well.

If you notice the + 11 for both y values. I had to do that to get the lines to be where they need to. I have a feeling something else went wrong.

I did change it so that my Rho values are all now positive.


Download hough.transform.converted.polar.coordinates.back.to.cartesian.but.still.cant.plot.them.zip
Direct Link


Download


Download hough.transform.converted.polar.coordinates.back.to.cartesian.but.still.cant.plot.them.zip
Mediafire


Download


Download hough.transform.converted.polar.coordinates.back.to.cartesian.but.still.cant.plot.them.zip
Filedropper


Download


Download hough.transform.converted.polar.coordinates.back.to.cartesian.but.still.cant.plot.them.zip
Cramit.in


Download


Download hough.transform.converted.polar.coordinates.back.to.cartesian.but.still.cant.plot.them.zip
Google


Download

Both comments and pings are currently closed.

Comments are closed.