How to place path lines on an image
This is what a Fourier approach could look like.
img = Import["http://i.stack.imgur.com/KfoXJ.png"];
gray = ColorConvert[RemoveAlphaChannel[img], "Grayscale"];
data = ImageData[gray];
ft = Fourier[data];
ft = RotateLeft[ft, Floor[Dimensions[ft]/2]];
ft // Abs // Log // Rescale // Image
We're interested in the maximum of the Fourier transform, as this corresponds to the strongest frequency. However we're not interested in the frequency zero, so before we look for a maximum we blot out that frequency.
pos = Position[
Abs[ft],
Max[Abs[ft] (CenterArray[DiskMatrix[10], Dimensions[ft]] /. {0 -> 1, 1 -> 0})]
];
invft = InverseFourier[SparseArray[pos -> 1, Dimensions[ft]] ft];
invimg = invft // Abs // Rescale // Image;
ImageMultiply[invimg, img]
It doesn't look like there's one line per path, it's more like one line on each side of each path. In any case these lines encapsulate at least some information about the paths and the rows of plants.
The position of a maximum gives the direction of a line that runs orthogonally to the rows:
ArcTan[207, 254] // N
0.886999
Too long illustration,sorry for comprehensive ability.:)Just provide a non-perfect solution:
pic = Import["http://www.dccs.com.br/images/dudu1.png"];
bin = MaxDetect[
ImageAdjust@
ColorNegate@ColorSeparate[ColorConvert[pic, "CMYK"]][[2]], .1]
As you see,not all the path
lines = ImageLines[Dilation[bin, IdentityMatrix[15]] // Thinning];
HighlightImage[pic, {Thick, Line /@ lines}]
This is not a full answer, but may be a starting point for further optimization.
sep = DominantColors[img, Automatic, {"CoverageImage", "Color"}]
This gives two dominat brown colors of the soil.
opt = Pruning[Thinning[Erosion[sep[[1, 1]], 1]]]
This uses the main dominat color and applies Erosion
, Thinning
and Pruning
to get like "walking paths" on the soil.
ImageMultiply[img, opt]
ImageAdd[img, opt]
You may use further optimization algorithms to remove small lines or play with the Pruning
function etc.