l'image de fond

fr       en

Gray Level Image Processing

Hough Transform

This transformation allows lines detection in images. It needs binary images. Every pixel of the binary image is represented by a line in the Hough space. Look at the next image:
At left, the original image with a single dot to 1. At right, It's transform in Hough space. We can see that the dot has been transformed in line. Now, look at what's happend for several dot belong to one line.
We note that the pixels trasformation make lines which converge to one single dot (into the red circle). Thanks to this dot, we can find the line which pass trough every dot of original image.


We start with a edge detection on the original image. tHe aim is to transform the image into binary image and detect the line on edges. The size of the transform matrix will be size of the line for θ and the size of the diagonal of image for rho. as:
s i z e r h o = ( M 2 + N 2 ) 0.5
Where M is the number of raw and N the number of column. This matrix is initialized to 0. Now, for every pixel of image equal to 1, we make the Hough transform. Each dot represent a line in Hough space. In the transform matrix we will increase of 1 for all the line. In that way, every time a line pass to a dot of the matrix, it's value increase. More lines pass to a dot more it's value is high. The compute to find the coordinate to increase is as:
for every pixel of the image to 1 we do for θ from 0 to π
r h o = x . cos ( θ ) + y . sin ( θ )
Where x is coordinate of pixel in raw and y coordinate in column. Thanks to the coordinate (rho, θ ) we know the dot to increase.
Once the transformation is made on the entire imag, we find a result which look like at:
Now, we have to find the dots with high value. In the program, I used a threshold and local maxima detection.
As we have the coordinates the most important, we can rebuild lines. We saw above that each dot in Hough space give us a line in x and y of the image. The method is to compute for every pixel of image if it correspond or not to the line coordinate issu. In each coordinate, we have a rho and a θ . we compute for every x and y as x=[1 M] and y=[1 N]:
r h o ' = x . cos ( θ ) + y . sin ( θ )
if r h o = r h o ' then we put the result matrix (x,y) to 1, else we let 0.


function guihoug
clear all;
close all;
figure(  'Name','translation',...
            'color',[0.3137 0.3137 0.5098]);
    'position',[0.05 0.55 0.35 0.35]);
    'position',[0.5 0.55 0.35 0.35]);
    'position',[0.05 0.1 0.35 0.35]);
    'position',[0.5 0.1 0.35 0.35]);
uicontrol(  'style','pushbutton',...
            'Position', [10 10 50 20],...
uicontrol(  'style','pushbutton',...
            'Position', [290 10 100 20],...
uicontrol(  'style','edit',...
            'Position', [180 10 50 20],...
text(1)=uicontrol(  'style','text',...
            'string','number of line: ',...
            'Position', [80 10 100 20]);
%parametre initial

function loadimage(~,~)
    % appeler quand appui check box
    [filename, pathname] = uigetfile({'*.jpg;*.tif;*.png;*.gif;*.bmp','All Image Files';...
          '*.*','All Files' },'mytitle',...

    x = imread(filename);
    if (length(size(x))>2)
        x=x(:,:,1);% on prend une seul plan image noir et blanc chaque plan sont egaux
    k = whos('x');
    if k.class == 'uint8'
    title('original image')

function executer(hObj,~,Name)

     type = getappdata(1,'type');
     img = getappdata(1,'x');
     nline = getappdata(1,'nline');
     [ligne colonne]=size(img);
     centreligne = round(ligne/2);
     centrecolonne = round(colonne/2);
     %détection de contour
     %edge detection
     %imgedge = edge(img,'canny');prewitt
     imgedge = edge(img,'prewitt');
     title('edge detection')
     theta_step = pi/(ligne);
     r_max = ceil(((ligne^2 + colonne^2)^0.5 / 2)) ;
     A=zeros(ligne,r_max*2+1);%A(theta, r)
     for i = 1 : ligne
         for j = 1 : colonne
             if (imgedge(i,j))==1
                 for t = 1 : ligne
                     theta = t * theta_step;
                     r = r_max  + 1+round(x * cos(theta) + y * sin(theta));
                    % h(p)=r;
                     A(t,r)= A(t,r) + 1;
     title('hough tranformation')
     threshold = max(max(A))*0.4;
     A = wextend(2,'zpd',A,2);
     for i = 3 : size(A,1)-3
         for j = 3 : size(A,2)-3
             if A(i,j)~=maxi
     maxlocaux=[]; %[theta r]
     for i = 1 : size(A,1)
         for j = 1 : size(A,2)
             if A(i,j) ~=0
     [value tri] = sort(maxlocaux(:,3),1,'descend');
     if nline>length(maxlocaux(:,3));
         nline = length(maxlocaux(:,3));
     for i = 1 : nline
     for p = 1 : length(maxlocauxsort)
         for i = 1 : ligne
             for j = 1 : colonne
                 %r = r_max  + 1+round( i* cos(-pointH(1)*theta_step) + j * sin(-pointH(1)*theta_step))
                 r = r_max  + 1+round( x* cos(pointH(1)*theta_step) + y * sin(pointH(1)*theta_step));
                 if r == pointH(2)
function nbline(hObj,~,Name)
    % Called when user activates popup menu
    val = str2num(get(hObj,'String')); %0|1=ligne, 2=colonne, 3=croix, 4=carre



Copyright © 2010-2014, all rights reserved, contact: operationpixel@free.fr