Bug introduced in 9.0.0 and fixed in 9.0.1

I want to get a Hough transform of some edged image.

When I compare the same transformation on the same image I got different results.

i = 0; While[i < 10, i++; Print[Radon[imgEdged, Method -> "Hough"] == 
               Radon[imgEdged, Method -> "Hough"]]]

Why isn't repeatability provided in result of this function?


imgEdged = edged image

  • 1
    $\begingroup$ Hi jhilary, welcome to Mathematica.SE! Could you please consider uploading your imgEdged so others can have a full view on your question? $\endgroup$
    – Silvia
    Dec 29, 2012 at 14:31
  • 1
    $\begingroup$ I cannot test this (Radon is new) but you may try setting e.g. SeedRandom[1] before every use of Radon in case the latter makes use of random numbers without using BlockRandom (which also might be applicable). $\endgroup$
    – Mr.Wizard
    Dec 29, 2012 at 14:42
  • $\begingroup$ I find Radon[] is giving consistent results for a set of test images in MMa 8.0 Perhaps your particular image has some particularity. Please post a link to it. $\endgroup$ Dec 29, 2012 at 15:08
  • $\begingroup$ I get a different Radon transform every time... !Mathematica graphics $\endgroup$
    – chris
    Dec 29, 2012 at 15:40
  • $\begingroup$ I tried post image in question, but they said that not enough reputation i.stack.imgur.com/UeSlT.jpg $\endgroup$
    – jhilary
    Dec 29, 2012 at 15:46

3 Answers 3


I think I found more hints on what might explain the fact that Hough gives different results each time it is called. But this is too small to fit in a comment.

This is assuming the implementation by Mathematica is as explained in the Wikipedia article for Hough transform. The Hough implementation uses (from the link)

The Hough transform algorithm uses an array, called an accumulator, to detect the existence of a line $y = mx + b$

Then later on it says:

the number of page swaps required for this will be very demanding because the accumulator array is used in a randomly accessed fashion

Notice the word randomly accessed. This is the key.

It seems to work in a fashion similar to Monte Carlo method for numerical integration in the sense only that it uses randomness to do its work for speed vs. quality.

But since using SeedRandom[1] did not resolve the differences between calls as can be seen here:

With[{imgEdged = Image[CellularAutomaton[30, {{1}, 0}, 40], "Bit"]},
   im1 = Radon[imgEdged, Method -> "Hough"];
   im2 = Radon[imgEdged, Method -> "Hough"];
   Sow[im1 == im2], {i, 100}]]

Mathematica graphics

My guess now is that Radon[], or the function that implements the Method->Hough does not use the same random number generator that SeedRandom[] resets (the global one), but its own, in the Kernel, and it forgets to reset its own at random number generator at start of each call? Just a guess, since nothing else seems to make sense ;)

You might also want to look at Randomized Hough transform

  • $\begingroup$ The link you shared mentions this — Hough generally uses polling and binning, and I presume it uses a random initialization each time. $\endgroup$
    – rm -rf
    Dec 29, 2012 at 17:27
  • $\begingroup$ Interesting. I still get True always i.stack.imgur.com/a4Y6b.png $\endgroup$ Dec 29, 2012 at 20:18
  • $\begingroup$ @NasserM.Abbasi Mma 8.0 on WinXp $\endgroup$ Dec 30, 2012 at 5:45
  • 3
    $\begingroup$ I'm not convinced on the "random access" point. In computer engineering this simply means that the access pattern is not predictable by memory controller, not literally that the access occurs at a randomly chosen point. Basically it is the antonym of "sequential" in this context, although modern processors can predict some nonsequential access patterns as well. $\endgroup$ Jan 2, 2013 at 20:11

That was a bug which got fixed in Mathematica 9.0.1.


Thanks to @Nasser I search about probablistic hough transform. Maybe it used in Mathematica implementation for speeding-up. I found good explanation here: http://www.cvmt.dk/education/teaching/f09/VGIS8/AIP/hough_09gr820.pdf

The Hough transform is not a fast algorithm for finding infinite lines in images of a certain size. Since additional analysis is required to detect finite lines, this is even slower. A way to speed up the Hough Transform and finding finite lines at the same time is the Progressive Probabilistic Hough Transform (PPHT). The idea of this methood is to transform randomly selected pixels in the edge image into the accumulator. When a bin in the accumulator corresponding to a particular infinite line has got a certain number of votes, the edge image is searched along that line to see if one or more finite line(s) are present. Then all pixels on that line are removed from the edge image. In this way the algorithm returns finite lines. If the vote threshold is low the number of pixels to evaluate in the accumulator gets small

And important part:

An issue with this algorithm is, that severel runs may may yield different results. This can be the case if many lines share pixels. If two lines cross, the fist line to be detected removes the common pixel (and a band around it) resulting in a gab in the other line. If many lines cross, then many pixels can miss in the last lines, and the votes in the accumulator may not reach the threshold.

So If you want after hough transform get expected lines, I think it's not very useful use hough transform (ImageLines function use Hough transform method inside (or RANSAC, which is randomized too)).

For example OpenCV hough lines provide choice which algorithm used in lines' search.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.