Tag Info

Hot answers tagged

65

This answer evolved over time and got quite long in the process. I've created a cleaned-up, restructured version as an answer to a very similar question on dsp.stackexchange. Here's my quick&dirty solution. It's a bit similar to @azdahak's answer, but it uses an approximate mapping instead of cylindrical coordinates. On the other hand, there are no ...


18

The idea is quite simple: Since any great circle can be parametrized as $\cos(\theta)u + \sin(\theta)v$ where $u$ and $v$ are two orthonormal vectors. One can start with $u=\{1,0,0\}, v=\{0,1,0\}$ and use RotationTransform to get out of the xy plane, then use RotationTransform again to spin around the z-axis to get all great circles with desired inclination. ...


16

This is just a quick sketching out of an answer (rescales galore!) textOnCurve[text_, f_, n_, p_: 0.01] := Text[Rotate[text, ArcTan @@ (f[Rescale[n + p, {0, 1}, {p, 1 - p}]] - f[Rescale[n - p, {0, 1}, {p, 1 - p}]])], f[n]] textCurve[string_, f_, stylef_: (# &), range_: {0, 1}] := With[{chars = ...


13

Here's a simple method that seems to work. Call the grid above img. Find the best/strongest line in the image: lines = ImageLines[img, MaxFeatures -> 1] We'll need the slope of this line - here's a function to do that slope[s_, e_] := ArcTan@@(e - s); (shorter version thanks to nikie). This can be applied as slopeLine = First[slope @@@ lines] For ...


13

Here is a static solution to the problem. It shows a mesh on the sphere that represents the normal lat-long coordinate system. A function representing the equator. equator[θ_] := {Cos[θ], Sin[θ], 0} A function and a plot representing the inclined circle. Note that the inclination is accomplished by a rotation of the equator about the x-axis. ...


12

Here's my stab at it, using a cylindrical projection, and TextureCoordinateFunction with a fitting parameter. Replace IMG in the code with the actual photo. The last command is a manual crop. result=With[{para = 1.69}, ParametricPlot3D[{Cos[u], Sin[u], v}, {u, 0, Pi}, {v, 0, Pi}, PlotStyle -> Texture[ImageReflect[IMG, Left -> Right]], Mesh -> ...


11

Here's another way...Text[] has a direction argument, so ArcTan is not necessary. txt1 = "Now we can follow" // Characters; txt2 = "an arbitrary path" // Characters; f[t_] := {Cos[2 \[Pi] t], Sin[6 \[Pi] t]}; totalarclength = NIntegrate[Sqrt[f'[\[Tau]].f'[\[Tau]]], {\[Tau], 0, 1}]; invarclength = First@NDSolve[{D[$t[s], s] == 1/Sqrt[f'[$t[s]].f'[$t[s]]], ...


9

AbsoluteOptions is known as very buggy function and the bug in determining the true PlotRange has very long history... You could try my Ticks-based workaround for getting the complete PlotRange (with PlotRangePadding added): completePlotRange[plot:(_Graphics|_Graphics3D)] := Quiet@Last@ Last@Reap[ Rasterize[ Show[plot, Axes -> True, ...


9

Great answers have already appeared. In the spirit of demonstrating multiple solutions to a problem with Mathematica, I would like to offer one using a different approach. First, some geometric analysis. This great circle bounds a hemisphere lying in a half-space determined by a normal direction to the circle's plane. Letting $\theta$ be the latitude at ...


8

If you have v9, here's an alternative solution: first I calculate the gradient and gradient orientation for each pixel gray = ColorConvert[img, "Grayscale"]; orientation = GradientOrientationFilter[gray, 3]; gradient = GradientFilter[gray, 3]; then I create a weighted histogram from those: wd = WeightedData[Flatten[ImageData[orientation]], ...


7

@nikie gave a very nice answer. This is a complement to it. One remaining challenge is compensating for the distortion close to the left and right edges of the image, visible for example here (image taken from nikie's post): The magnitude of the distortion cannot be estimated in the general case without having some information about what's on the label. ...


6

this approach looks promising: labelphoto = Import["/Users/acl/Desktop/labelimage.png"] label = Import["/Users/acl/Desktop/FMALS.gif"] and then locate corresponding points as follows: images = {label, labelphoto}; matches = ImageCorrespondingPoints @@ images MapThread[ Show[#1, Graphics[{Red, MapIndexed[Inset[#2[[1]], #1] & , #2]}]] &, ...


6

Surely a better solution exists! Assuming m your matrix. m = RandomReal[1, {1000, 1000}]; pat = Array[(-1)^# &, First@Dimensions[m]]; B1 = (pat #) & /@ Reverse[m, {1, 2}]; // AbsoluteTiming {0.124800, Null} Though Table is intuitive but will be pretty slow for big lists. u = Length[m]; B = Table[ m[[u - r, u - s]]*(-1)^(s + 1), {r, 0, u - ...


5

On many platforms, matrix operations are really fast, so using them is a good idea. (You have to get their dimensions correct, though!) SparseArray objects are likely to be efficient in RAM and time usage. All we have to do is code the rules used to generate the right and left matrices: arrange[c_] := Block[{m, n, sa}, {m, n} = Dimensions[c]; ...


5

As an addition to @bills's answer you can rotate by the mean of the slope of all the detected lines. slopeLine = slope @@@ lines meanslope = Mean@Join[Select[slopeLine, # > -1 &], Select[slopeLine, # < -1 &] + Pi/2] ImageRotate[img, -meanslope]


4

If the problem is that the transformation function is slow to compute, a simple way to create and use a look-up table is to memoize the function: (* create an example image *) image = RandomImage[1, {30, 20}, ColorSpace -> "RGB"] ~ ImageResize ~ Scaled[10] (* define the transformation function with memoization *) mem : func[{x_, y_}] := mem = {x + 0.01 ...


4

A completely stupid workaround that perhaps someone knows how to automate: Create a Graphics object Graphics[{GeometricTransformation[Rectangle[], RotationTransform[1.]]}] Right click the Graphics and select Get Coordinates Drag around a bit in the graphics AbsoluteOptions[< Put the object here >, PlotRange] gives the correct PlotRange It also ...


3

arrngF1 = MapAt[-1 # &, #[[Range[Dimensions[#][[1]], 1, -1], Join @@ Reverse@Partition[Range[Dimensions[#][[2]]], {2}]]], {;; , 2 ;; ;; 2}] &; arrngF2 = Module[{temp = #[[Range[Dimensions[#][[1]], 1, -1], Join @@ Reverse@Partition[Range[Dimensions[#][[2]]], {2}]]]}, temp[[;; , 2 ;; ;; 2]] = (-1) temp[[;; , 2 ;; ;; 2]]; temp] &; ...


3

You could use Reverse for the first part and define a helper function to do the rest : rM[avector_, {m1_, m2_}] := Module[{nc, local, rules}, nc = Length[avector]/2; local = {m1, m2} # & /@ Partition[avector, 2]; Flatten[ReplacePart[local, (# -> local[[ nc + 1 - #]]) & /@ Range[nc]], 1] ] The argument {m1, m2} will be used to multiply ...


3

ImageTransformation works with functions, not tables. It should be straightforward to define a function that carries out the same transformation as the table, but you will need to be aware that the #[[1]] and #[[2]] arguments go from 0 to 1 (across the image) so you will need to design the function to handle this input range. For example, you might want a ...


2

I think you have to make sure that your transformation function always handles input cleanly. Here's a test you can do to see what goes into your function. (And I think you can use real coordinates if you use the DataRange option.) i = ImageResize[ExampleData[{"TestImage", "Mandrill"}], {20, 20}]; The function: f[pt_] := (Print[pt]; {pt[[1]], pt[[2]]}); ...


1

There is a Wolfram Blog post that explains this as a subproblem: Mapping GPS Data, by Robert Raguet-Schofield. That was published in 2009 and I think is pretty nifty. But I'd recommend looking into out new URLFetchAsynchronous and perhaps updating the code. Below you see parts in the blog where he seamlessly goes from patches to a single map:


1

Ok, I feel sorry for myself by now... This was easier than I thought... So here's my proposition for a solution : Given matrix $\mathbf A$ written in mathematica as : A = {{a, b, i, j}, {c, d, k, l}, {e, f, m, n}, {g, h, o, p}} To obtain matrix $\mathbf B$ I did this : u = Length[A]; B = Table[A[[u - r, u - s]]*(-1)^(s + 1), {r, 0, u-1}, {s, 0, u-1}] ...


1

I don't know why Normal does not work, but you can perform at least the transformation shown like this: pts = {{-0.36551249999999996`, -0.29021463333333336`}, \ {-0.36509784999999995`, -0.2812481916666667`}, {-0.3619309499999999`, \ -0.2645122083333334`}, {-0.3592788999999999`, -0.25668636666666667`}, \ {-0.3520880999999999`, -0.2419782333333334`}, ...



Only top voted, non community-wiki answers of a minimum length are eligible