I'm new to mathematica and want to learn more about this powerful tool.
So I want to generate a vector map from image showing how fast some values goes from lighter to darker colors. I found function GradientOrientationFilter very useful, in particular first "neat example" from link is almost what I'm looking for. Except the fact that orientation of the vector should be flipped by Pi if the tale located in brighter than arrowhead area. I'm working with gray scaled data images. And want to get something like that with exception that vectors should point from light to dark area
So here is a slightly altered example from that link
dims = ImageDimensions[img];
radius = 3;
dirs = ImageData[GradientOrientationFilter[img, radius]];
magnitudes = ImageData[GradientFilter[img, radius]];
ar1 = Join[Partition[Flatten[dirs], 1],
Partition[Flatten[magnitudes], 1], 2];
ar2 = Partition[ar1, First[dims]];
That's all I got so far, rest of the code remains unchanged compared with neat example:
orientations =
MapThread[#1 {-Sin[#2], Cos[#2]} &, {magnitudes, dirs}, 2];
Show[img,
ListVectorPlot[
MapIndexed[{{#2[[2]], dims[[2]] - #2[[1]]}, #1} &,
orientations, {2}], VectorColorFunction -> (Yellow &)]]
As you can see I made a list ar2 in which elements of the highest level have values for orientation and magnitude together, but here I stuck. I don't know how to go through this ar2 list (which for example have values
{{A11, B11}...{An1, Bn1}
...
{A1m, B1m}...{*Anm, **Bnm}}
where A is orientation, B is magnitude, and nm are XY indexes of pixels) and compare some element kl of image with element in the end of the vector (somehow recognized from Akl and Bkl) and depending on comparison of kl with this element either change Akl or leave it as is.
I'm apologizing for confusing explanations and rely on your help. Thank you.
ar1 = Join[Partition[Flatten[dirs], 1], Partition[Flatten[ImageData[img]], 1], 2]
$\endgroup$