Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- param[x_, m_, t_] :=
- Module[{f, n = Length[x], nf},
- f = Chop[Fourier[x]][[;; Ceiling[Length[x]/2]]];
- nf = Length[f];
- Total[Rationalize[
- 2 Abs[f]/Sqrt[n] Sin[
- Pi/2 - Arg[f] + 2. Pi Range[0, nf - 1] t], .01][[;;
- Min[m, nf]]]]]
- tocurve[Line[data_], m_, t_] := param[#, m, t] & /@ Transpose[data]
- SetDirectory["/home/jacobh/WORKING/Pictures"]
- img=Import["Coronal Holes.jpg"]
- img = Binarize[img~ColorConvert~"Grayscale"];
- lines = Cases[
- Normal@ListContourPlot[Reverse@ImageData[img],
- Contours -> {0.5}], _Line, -1];
- ParametricPlot[
- Evaluate[tocurve[#, 100000000, t] & /@ lines], {t, 0, 1},
- Frame -> True, Axes -> False, ImageSize -> Large]
- ParametricEquations = Evaluate[tocurve[#, 100000000, t] & /@ lines]
- n = Length[ParametricEquations]
- img2 = Binarize[img~ColorConvert~"Grayscale"];
- bsFs = Cases[
- Normal@ListContourPlot[Reverse@ImageData[img2], Contours -> {0.5}],
- Line[x_] :> BSplineFunction[x], All];
- ParametricPlot[Evaluate[Through@bsFs@t], {t, 0, 1}, Frame -> True,
- Axes -> False, ImageSize -> Large, Axes -> false, Frame -> True]
- stepsize = 0.0001
- list = Table[
- N[Evaluate[Through@bsFs@t] /. t -> i], {t, 0, 1, stepsize}]
- xmatrix =
- Table[Table[list[[i, j, 1]], {i, 1, (1/stepsize) + 1}], {j, 1, n}]
- ymatrix =
- Table[Table[list[[i, j, 2]], {i, 1, (1/stepsize) + 1}], {j, 1, n}]
- Minx = Table[xmatrix[[i, Ordering[xmatrix[[i]], 1]]], {i, 1, n}]
- Miny = Table[ymatrix[[i, Ordering[ymatrix[[i]], 1]]], {i, 1, n}]
- x = Table[ParametricEquations[[i, 1]], {i, 1, n}]
- y = Table[ParametricEquations[[i, 2]], {i, 1, n}]
- Mx = Table[NMinValue[{x[[i]], 0 <= t <= 1}, t], {i, 1, n}]
- My = Table[NMinValue[{y[[i]], 0 <= t <= 1}, t], {i, 1, n}]
- NewParametricEquations =
- Table[{x[[i]] - (Mx[[i]] - Minx[[i]]),
- y[[i]] - (My[[i]] - Miny[[i]])}, {i, 1, n}]
- ParametricPlot[NewParametricEquations, {t, 0, 1}, ImageSize -> Large,
- Axes -> False, Frame -> True]
- xCentroids =
- Table[NIntegrate[
- NewParametricEquations[[i, 1]]^2*
- D[NewParametricEquations[[i, 2]], t], {t, 0, 1}]/
- NIntegrate[
- 2*NewParametricEquations[[i, 1]]*
- D[NewParametricEquations[[i, 2]], t], {t, 0, 1}], {i, 1, n}]
- yCentroids =
- Table[NIntegrate[-NewParametricEquations[[i, 2]]^2*
- D[NewParametricEquations[[i, 1]], t], {t, 0, 1}]/
- NIntegrate[-2*NewParametricEquations[[i, 2]]*
- D[NewParametricEquations[[i, 1]], t], {t, 0, 1}], {i, 1, n}]
- Centroids = Table[{xCentroids[[i]], yCentroids[[i]]}, {i, 1, n}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement