LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with selfmade Hough Transform in formula node

Solved!
Go to solution

Hello everyone,

 

 

I'm making my own Face Recognition system and I'm at the phase of making a Hough Transform of my captured CAM-image.

 

So if a pixel is not zero; I generate its sinusoidal with -90° to 90° and calculate the corresponding value with the general Hough formula. Then for the voting process I increase the value of every pixel by 1.

 

Now the output is just a bit darker but there is no transformation at all.

I think I interpreted the algorithm wrong or I missed a detail in my coding..

 

 

Thanks in advance

0 Kudos
Message 1 of 25
(3,563 Views)

I looked at your code and have some comments.

 

I looked at the Wikipedia article on the Hough transform. It appears that the definition in that article is somewhat different from your code.

 

r(\theta) = x_0 \cos \theta + y_0 \sin \theta                                         from Wikipedia

 

for(i=-90;i<=90;i++)

   { Hough_Space[x][y] = Array[x][y]*cos(i)+Array[x][y]*sin(i);

     Hough_Space[x][y]+=1;

   }                                                                                        From your VI.

 

Note that the factors multiplying the sine and cosine terms are different.

 

The sine and cosine functions in the Formula Node take arguments in radians. The -90 to +90 in your code suggests degrees.

 

You may want to use a different threshold for creating the Hough Space array. The data is unsigned integer and the minimum value in your image is 25. So no pixels in your image are excluded and very few in most images will have pixels exactly equal to zero.

 

Is there a reason you prefer to use the formula node rather than the usual LV functions? 

 

Lynn

0 Kudos
Message 2 of 25
(3,547 Views)

When I replace the formula node with approximately equivalent LV VIs and functions, the time to execute goes from 5.5 s to 60 ms and memory usage drops from 115 MB to 28 MB.

 

Lynn

0 Kudos
Message 3 of 25
(3,540 Views)

Thanks for the quick reply.

 

 

It seems I misinterpreted the formula. And I had no idea that there was so much difference between the formula node and LV VI's.

The reason why I use Formula Node that much is because I still have some trouble with all those different blocks in LV and I'm a C-programmer so the Formula Node is quite handy for me.

 

I'll firstly solve the error in my FN and when it'll work I'll implement it in LV VI.

Can you please show me how you implemented your Hough Transform?

 

 

Thanks in advance

0 Kudos
Message 4 of 25
(3,528 Views)

So I changed the code, still using formula node.

Now the output is just plain black, I'm struggling with for 4.5h straight.

 

Can you give me a push to the right direction please?

 

 

Sincerely yours

0 Kudos
Message 5 of 25
(3,516 Views)

@Sailiman wrote:

So I changed the code, still using formula node.

Now the output is just plain black, I'm struggling with for 4.5h straight.

 

Can you give me a push to the right direction please?


Unless you show us your new code, we cannot really tell what you are doing wrong. (... and why exactly are you still using the formula node?)

0 Kudos
Message 6 of 25
(3,501 Views)

My bad, I forgot to upload the code.

And as said earlier, because I'm a C-programmer the transition is easier.

 

But I promise, I'm working on it and I'm really trying to improve my LV skills 🙂

0 Kudos
Message 7 of 25
(3,495 Views)

1. You appear to be trying to work in degrees but the formula node uses radians for trigonometric functions. Cos(180) is not equal to cos(pi)!

 

2. I have not programmed in a text-based language for 30 years and never in C, but it looks like you assign Hough_Space[x][y] =  Array[x][0]*cos(i)... for 361 values of i but only use the last one?

 

Lynn

0 Kudos
Message 8 of 25
(3,486 Views)

Thanks for the response Lynn,

 

1. I converted the degrees into radian and indeed I have an image. But I suspect it's not 100% correct.

2. I don't think so, as I see it: The 2 for loops will loop for each element in the 2D-array. And for every element in the 2D-array I loop again with radials.

 

for(x=0; x<X;x++)
     {
          for(y=0; y<Y;y++)
               {
                    
                               for(i=-180;i<=180;i++)
                                    {
                                             Hough_Space[x][y] = Array[x][0]*cos((i*3,14)/180)+Array[0][y]*sin((i*3,14)/180);
                                     }
                     
                         Acc[j]=Hough_Space[x][y];
                          if(Acc[j]<Threshold) 
                          {
                                  Acc[i]=0;
                          }   
                         j++;
               }
     }

 

I tried to implement a Hough Transform with the LV VI's as you sugested but still no succes. I'm stuck for getting the x-part for my cos and y-part for my sine. How did you implement it with LV VI?

 

 

Sincerely yours

0 Kudos
Message 9 of 25
(3,453 Views)

Sailiman wrote:

1. I converted the degrees into radian and indeed I have an image.


How does the output look like? It should look like a transform, not similar to the original image as in your first attempt.

0 Kudos
Message 10 of 25
(3,448 Views)