Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. param[x_, m_, t_] :=
  2. Module[{f, n = Length[x], nf},
  3. f = Chop[Fourier[x]][[;; Ceiling[Length[x]/2]]];
  4. nf = Length[f];
  5. Total[Rationalize[
  6. 2 Abs[f]/Sqrt[n] Sin[
  7. Pi/2 - Arg[f] + 2. Pi Range[0, nf - 1] t], .01][[;;
  8. Min[m, nf]]]]]
  9.  
  10. tocurve[Line[data_], m_, t_] := param[#, m, t] & /@ Transpose[data]
  11. SetDirectory["/home/jacobh/WORKING/Pictures"]
  12. img=Import["Coronal Holes.jpg"]
  13. img = Binarize[img~ColorConvert~"Grayscale"];
  14. lines = Cases[
  15. Normal@ListContourPlot[Reverse@ImageData[img],
  16. Contours -> {0.5}], _Line, -1];
  17.  
  18. ParametricPlot[
  19. Evaluate[tocurve[#, 100000000, t] & /@ lines], {t, 0, 1},
  20. Frame -> True, Axes -> False, ImageSize -> Large]
  21. ParametricEquations = Evaluate[tocurve[#, 100000000, t] & /@ lines]
  22. n = Length[ParametricEquations]
  23. img2 = Binarize[img~ColorConvert~"Grayscale"];
  24.  
  25. bsFs = Cases[
  26. Normal@ListContourPlot[Reverse@ImageData[img2], Contours -> {0.5}],
  27. Line[x_] :> BSplineFunction[x], All];
  28.  
  29. ParametricPlot[Evaluate[Through@bsFs@t], {t, 0, 1}, Frame -> True,
  30. Axes -> False, ImageSize -> Large, Axes -> false, Frame -> True]
  31. stepsize = 0.0001
  32. list = Table[
  33. N[Evaluate[Through@bsFs@t] /. t -> i], {t, 0, 1, stepsize}]
  34. xmatrix =
  35. Table[Table[list[[i, j, 1]], {i, 1, (1/stepsize) + 1}], {j, 1, n}]
  36. ymatrix =
  37. Table[Table[list[[i, j, 2]], {i, 1, (1/stepsize) + 1}], {j, 1, n}]
  38. Minx = Table[xmatrix[[i, Ordering[xmatrix[[i]], 1]]], {i, 1, n}]
  39. Miny = Table[ymatrix[[i, Ordering[ymatrix[[i]], 1]]], {i, 1, n}]
  40. x = Table[ParametricEquations[[i, 1]], {i, 1, n}]
  41. y = Table[ParametricEquations[[i, 2]], {i, 1, n}]
  42. Mx = Table[NMinValue[{x[[i]], 0 <= t <= 1}, t], {i, 1, n}]
  43. My = Table[NMinValue[{y[[i]], 0 <= t <= 1}, t], {i, 1, n}]
  44. NewParametricEquations =
  45. Table[{x[[i]] - (Mx[[i]] - Minx[[i]]),
  46. y[[i]] - (My[[i]] - Miny[[i]])}, {i, 1, n}]
  47. ParametricPlot[NewParametricEquations, {t, 0, 1}, ImageSize -> Large,
  48. Axes -> False, Frame -> True]
  49. xCentroids =
  50. Table[NIntegrate[
  51. NewParametricEquations[[i, 1]]^2*
  52. D[NewParametricEquations[[i, 2]], t], {t, 0, 1}]/
  53. NIntegrate[
  54. 2*NewParametricEquations[[i, 1]]*
  55. D[NewParametricEquations[[i, 2]], t], {t, 0, 1}], {i, 1, n}]
  56. yCentroids =
  57. Table[NIntegrate[-NewParametricEquations[[i, 2]]^2*
  58. D[NewParametricEquations[[i, 1]], t], {t, 0, 1}]/
  59. NIntegrate[-2*NewParametricEquations[[i, 2]]*
  60. D[NewParametricEquations[[i, 1]], t], {t, 0, 1}], {i, 1, n}]
  61. Centroids = Table[{xCentroids[[i]], yCentroids[[i]]}, {i, 1, n}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement