# Create an accumulator array from a function

I am making some images for a project about the hough transform line detection, I am showing the slope-intercept form , the normal form and their accumulator arrays to show the peaks. I am kind of new to Mathematica.

Data = Table[{x, x + 1}, {x, -5, 5}];

Show[
ListPlot[Data, PlotMarkers -> {Automatic, 11}, Joined -> False]
]

pSIF[m_, x_, y_] := -x*m + y
pNF[t_, x_, y_] := x*Cos[t] + y*Sin[t]

Show[
Plot[Apply[pSIF[m, #1, #2] &, Data, {1}], {m, -2.5, 2.5},
Evaluated -> True, PlotRange -> {Automatic, Automatic}]
]
Show[
Plot[Apply[pNF[m, #1, #2] &, Data, {1}], {m, 0, Pi},
Evaluated -> True, PlotRange -> {{0, Pi}, Automatic}]
]


I have done the slope-intercept and normal form plots, but I don't know how to quantize the plot and make the accumulator array. I am trying to round it and move it to a table but without success.

Show[
Plot[Round[Apply[pNF[m, #1, #2] &, Data, {1}]], {m, 0, Pi},
Evaluated -> True, PlotRange -> {{0, Pi}, Automatic}]
]

• Greetings! Welcome to Mma.SE and thanks for taking the tour. Help us to help you, write an excellent question. Edit if improvable, show due diligence, give brief context, include minimal working examples of code and data in formatted form. As you receive give back, vote and answer questions, keep the site useful, be kind, correct mistakes and share what you have learned. – rhermans Feb 25 '16 at 22:51

I think you want to first create these data points:

data2 = Flatten[
Table[{m, #} & /@ Apply[pNF[m, #1, #2] &, Data, {1}], {m, 0, Pi, 0.1}], 1]


This gives you a list of points:

{ {0.,-5.}, {0., -4.}, ...., {3.1, -3.78}, {3.1, -4.74} }


Then you can use BinCounts to see how many of these point fit in a given bin (I am using bins of size 0.25x0.25 here:

 bc = BinCounts[data2, {Range[0, \[Pi], .25]}, {Range[-8, 8, .25]}]
Grid[bc]


And then you can use ArrayPlot to visualize the bin counts (accumulator):

ArrayPlot[bc] Let me know if I complete misunderstood your question?

Here is a slightly more complicated case, using more data points and two lines:

data = Join[
Table[{x, -.45 x + 1}, {x, -5, 5, .1}],
Table[{x, 1.2 x - 1}, {x, -5, 5, .1}]
]


It looks like this:

Graphics[Point[data], Frame -> True, PlotRange -> 5] Again, compute data2:

data2 = Flatten[
Table[{m, #} & /@ Apply[pNF[m, #1, #2] &, data, {1}], {m, 0, Pi, 0.1}], 1];


And get the bin counts bc:

bc = BinCounts[data2, {Range[0, \[Pi], .1]}, {Range[-5, 5, .1]}];


And make an array plot to visualize the bin counts:

ArrayPlot[bc] • This is what I was looking for, here is the result after some small changes, images , you have my thanks. – EinsL Feb 26 '16 at 6:51
• Good to hear my reply was useful. I know far too little in the area of hough and radon transforms, just enough to get myself into trouble. But these are powerful transforms and very useful in object reconstruction. There is also a built-in function Radon which does the radon transform. – Arnoud Buzing Feb 26 '16 at 15:35