I have an image with a grid of equal separations. I would like to detect the lines in this image. I tried with ImageLines in but it does not work.
@MelaGo Thank you for the solution. Unfortunately, I got some error while I run into my Mathematica. I wonder if you could look at it.
Clear[x0, y0, angle]
grid[x0_?NumericQ, y0_?NumericQ, angle_?NumericQ] :=
RotationTransform[angle, {pix/2, pix/2}][
Flatten[Table[{x0 + x, y0 + y}, {x, 0, pix, div}, {y, 0, pix,
div}], 1]];
minfunc[x0_?NumericQ, y0_?NumericQ, angle_?NumericQ] :=
Total[EuclideanDistance[#, Nearest[grid[x0, y0, angle], #][[1]]] & /@
cents]
sol = FindMinimum[{minfunc[x0, y0, angle]}, {{x0, 10}, {y0,
10}, {angle, 0}}, Method -> "PrincipalAxis"]
(**Errors**)
Nearest::neard: The default distance function does not give a
real numeric distance when applied to the point pair
{319.5,488.5} and {x0 Cos[angle]-250 (-1+Cos[angle]-
Sin[angle])-y0 Sin[angle],y0 Cos[angle]+x0 Sin[angle]-250
(-1+Cos[angle]+Sin[angle])}.
Thread::tdlen: Objects of unequal length in {319.5,488.5}-{{x0
Cos[angle]-250 (-1+Cos[angle]-Sin[<<1>>])-y0 Sin[angle],y0
Cos[angle]+x0 Sin[angle]-250 (-1+Cos[angle]+Sin[angle])},{x0
Cos[angle]-250 (-1+Cos[angle]-Sin[<<1>>])-(26+y0) Sin[angle],
(26+y0) Cos[angle]+x0 Sin[angle]-250 (-1+Cos[angle]+Sin[angle])},<<48>>,<<350>>} cannot be combined.










