Skip to content

Commit af8d373

Browse files
author
flip phillips
committed
Added texturemap transforms
1 parent ce78a8b commit af8d373

File tree

6 files changed

+220
-53
lines changed

6 files changed

+220
-53
lines changed

FPTools/Geometry.wl

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
(* ::Package:: *)
2+
3+
(* ::Subsection:: *)
4+
(*LatLon / Rectangular Mapping*)
5+
6+
7+
(* ::Text:: *)
8+
(*u,v on 0-1. technically 'spherical' and not phi theta. nomenclature me.*)
9+
10+
11+
(* ::Input::Initialization:: *)
12+
RectangularToPhiTheta[{u_,v_}]:={2\[Pi] u,\[Pi](v-1)}
13+
14+
15+
(* ::Input::Initialization:: *)
16+
PhiThetaToDirection[{\[Phi]_,\[Theta]_}]:={Sin[\[Phi]]Sin[\[Theta]],Cos[\[Theta]],-Cos[\[Phi]]Sin[\[Theta]]}
17+
18+
19+
(* ::Input::Initialization:: *)
20+
RectangularToDirection[{u_,v_}]:=PhiThetaToDirection[RectangularToPhiTheta[{u,v}]]
21+
22+
23+
(* ::Input::Initialization:: *)
24+
DirectionToRectangular[{dx_,dy_,dz_}]:={1+1/\[Pi] ArcTan[-dz,dx],1/\[Pi] ArcCos[dy]}
25+
26+
27+
(* ::Subsection:: *)
28+
(*Angular Mapping*)
29+
30+
31+
(* ::Text:: *)
32+
(*u, v on 0 - 1. *)
33+
34+
35+
(* ::Input::Initialization:: *)
36+
CircularToAngular[{u_,v_}]:={ArcTan[2u-1,1-2v],\[Pi] Sqrt[(2u-1)^2+(2v-1)^2]}
37+
38+
39+
(* ::Input::Initialization:: *)
40+
AngularToDirection[{\[Theta]_,\[Phi]_}]:={Cos[\[Theta]]Sin[\[Phi]],Sin[\[Theta]]Sin[\[Phi]],-Cos[\[Phi]]}
41+
42+
43+
(* ::Input::Initialization:: *)
44+
CircularToDirection[{u_,v_}]:=AngularToDirection[CircularToAngular[{u,v}]]
45+
46+
47+
(* ::Input::Initialization:: *)
48+
DirectionToCircular[{dx_,dy_,dz_}]:=1/2+ArcCos[-dz/(2\[Pi] Sqrt[dx^2+dy^2])]{dx,dy}
49+
50+
51+
(* ::Subsection:: *)
52+
(*Cube Mapping*)
53+
54+
55+
(* ::Text:: *)
56+
(*some other time*)
57+
58+
59+
ToCartesianRules[] :=
60+
MapThread[
61+
Rule, {{r, \[Theta], \[Phi]}, ToSphericalCoordinates[{x, y, z}]}];
62+
63+
ToSphericalRules[] :=
64+
MapThread[
65+
Rule, {{x, y, z},
66+
FromSphericalCoordinates[{r, \[Theta], \[Phi]}]}];

FPTools/PacletInfo.m

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
Publisher -> "Skidmore Vision Lab",
66
Copyright -> "©2018- Flip Phillips & Misc Contributors",
77
License -> "MIT",
8-
Version -> "1.0.8",
9-
BuildNumber -> "193",
8+
Version -> "1.0.9",
9+
BuildNumber -> "198",
1010
MathematicaVersion -> "11.2+",
1111
URL -> "https://github.com/flipphillips/FPTools",
1212
Thumbnail -> "Documentation/icon.png",
@@ -33,6 +33,16 @@
3333
(* Graphics *)
3434
"FPTools`RectangleToDisk",
3535

36+
(* Geometry *)
37+
"FPTools`RectangularToPhiTheta",
38+
"FPTools`PhiThetaToDirection",
39+
"FPTools`RectangularToDirection",
40+
"FPTools`DirectionToRectangular",
41+
"FPTools`CircularToAngular",
42+
"FPTools`AngularToDirection",
43+
"FPTools`CircularToDirection",
44+
"FPTools`DirectionToCircular",
45+
3646
(* Image *)
3747
"FPTools`ImageIdentifyFP",
3848
"FPTools`BlurFaces","FPTools`FindFaceImages",

FPTools/Sugar.wl

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,3 @@
44
ApplyIf[f_, g_, x_] := If[TrueQ[f[x]], g[x], x];
55
ApplyIf[f_, g_][x_] := ApplyIf[f, g, x];
66

7-
8-
ToCartesianRules[] :=
9-
MapThread[
10-
Rule, {{r, \[Theta], \[Phi]}, ToSphericalCoordinates[{x, y, z}]}];
11-
12-
ToSphericalRules[] :=
13-
MapThread[
14-
Rule, {{x, y, z},
15-
FromSphericalCoordinates[{r, \[Theta], \[Phi]}]}];

FPTools/Usage.wl

Lines changed: 139 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
(* ::Package:: *)
22

3-
43
(* ::Section:: *)
54
(*Automatically Generated*)
65

76

7+
(* ::Text:: *)
8+
(*MetaInformation about this package*)
9+
10+
811
$FPToolsVersion::usage = "$FPToolsVersion gives its best guess as to the version we're using.";
912
$FPToolsDebug::usage = "$FPToolsDebug let's us know if the package was built with any debugging tools.";
1013

@@ -13,6 +16,10 @@ $FPToolsDebug::usage = "$FPToolsDebug let's us know if the package was built wit
1316
(*Introspection*)
1417

1518

19+
(* ::Text:: *)
20+
(*Metainformation about Mathematica. Borrowed from various stackexchange posts and some of my own code.*)
21+
22+
1623
Spelunk::usage = "Spelunk[symbol] will discover the definition of symbol. Underlined symbols in the output are clickable.";
1724
PropertiesAvailability::usage = "PropertiesAvailability[object] returns the {available, unavailable} properties for an object.";
1825
PropertiesDataset::usage = "PropertiesDataset[object] returns a TableForm of the available properties for object.";
@@ -22,110 +29,202 @@ GetSymbolsDefinedInMX::usage = "GetSymbolsDefinedInMX[mxfile] returns a list of
2229

2330
GetCompilerFunctions::usage = "GetCompilerFunctions[] returns the list of functions that are compilable.";
2431

32+
33+
(* ::Section:: *)
34+
(*Data*)
35+
36+
37+
(* ::Text:: *)
38+
(*In the past there have been problems with Import and asking for Datasets. This doesn't fix it exactly, but works better.*)
39+
40+
41+
ImportAsDataset::usage = "ImportAsDataset[f] imports f and uses the first row as column headers. Default options are \"Headers\"->True, \"RowNames\"->False, \"ImportOptions->None\" ";
42+
43+
44+
Overlap::usage = "Overlap[l1,l2] gives the intersection of the range of two lists.";
45+
46+
2547
(* ::Section:: *)
2648
(*Entity*)
2749

2850

51+
(* ::Text:: *)
52+
(*Some semantic / entity probing things used by some developmental linguistics kids last semester.*)
53+
54+
2955
EntityPropertiesDataset::usage = "EntityPropertiesDataset[entity] does its best to list all the properties associated with the entity object supplied.";
3056
ConceptBroaden::usage = "ConceptBroaden[entity,depth] recursively climbs the Concept hierarchy until it hits the terminal Concept 'Entity' or after depth dives. Returns a list of Broader Concepts at each level.";
3157
ConceptDistance::usage = "ConceptDistance[entitya,entityb] determines the distance in 'concept steps' between concept a and b.";
3258
ConceptDepth::usage = "ConceptDepth[entity] computes the distance to the root of the Entity tree.";
3359

3460

61+
(* ::Section:: *)
62+
(*Genetic Algorithms*)
63+
64+
65+
(* ::Text:: *)
66+
(*The world's simplest genetic algorithm implementation*)
67+
68+
69+
GARepopulate::usage = "GARepopulate[pop,fitfunc] creates a new population using fitfunc.";
70+
GAMutate::usage = "GAMutate[chromo] mutates a chromosome.";
71+
GACrossover::usage = "GACrossover[c1,c2] performs a random crossover of c1 & c2. Returns two offspring.";
72+
73+
74+
(* ::Section:: *)
75+
(*Geometry*)
76+
77+
78+
ToCartesianRules::usage = "A set of rules for rtp->xyz";
79+
ToSphericalRules::usage = "A set of rules for xyz->rtp";
80+
81+
82+
(* ::Text:: *)
83+
(*These are for converting to and from various texture-map coordinate systems.*)
84+
85+
86+
RectangularToPhiTheta::usage = "RectangularToPhiTheta[{u,v}] gives the phi/theta (spherical) coordinates from a latlon coordinate system. u and v are on [0,1)";
87+
PhiThetaToDirection::usage = "PhiThetaToDirection[{phi,theta}] gives the direction vector {dx,dy,dz} from the spherical coordinates phi / theta.";
88+
RectangularToDirection::usage = "RectangularToDirection[{u,v}] gives the direction vector {dx,dy,dz} from the [0,1) latlon coordinates.";
89+
DirectionToRectangular::usage = "DirectionToRectangular[{dx,dy,dz}] gives index into texture space {u,v} from the direction vector.";
90+
91+
92+
CircularToAngular::usage = "CircularToAngular[{u,v}] gives the theta/phi (angular) coordinates from a circluar coordinate system. u and v are on [0,1)";
93+
AngularToDirection::usage = "AngularToDirection[{theta,phi}] gives the direction vector {dx,dy,dz} from the angular coordinates theta / phi.";
94+
CircularToDirection::usage = "CircularToDirection[{u,v}] gives the direction vector {dx,dy,dz} from the [0,1) circular coordinates.";
95+
DirectionToCircular::usage = "DirectionToCircular[{dx,dy,dz}] gives index into circular texture space {u,v} from the direction vector.";
96+
97+
98+
(* ::Section:: *)
99+
(*Graphics*)
100+
101+
102+
RectangleToDisk::usage = "RectangleToDisk[rect] takes a rectangle and returns an equivalent disk.";
103+
104+
35105
(* ::Section:: *)
36106
(*Image*)
37107

38108

109+
(* ::Text:: *)
110+
(*Some shortcuts for face things from a recent project*)
111+
112+
39113
ImageIdentifyFP::usage = "ImageIdentifyFP[image,{n}] does the standard image identify returnig n (default 5) items and its probabilities.";
40114
BlurFaces::usage = "BlurFaces[image] blurs faces in image. Options include Method (Box,Disk,Outline,Eyes,FaceParts) and FilterRadius.";
41115
FindFaceImages::usage = "FindFaceImages[image,scale] finds faces in an image, scaling the returned image by `scale` (default 1). Larger values provide more context, smaller less.";
42-
AddAlphaChannel::usage = "AddAlphaChannel[image] adds a unity alpha channel to image.";
116+
117+
118+
(* ::Text:: *)
119+
(*Very basic ffmpeg tools*)
120+
43121

44122
$FFMpegPath::usage = "$FFMpegPath is the path to the `ffmpeg` executable.";
45123
ImportMP4Frame::usage = "ImportMP4Frame[file,frame] extracts frame `frame` from MP4 file `file`.";
46124
ImportMP4Frames::usage = "ImportMP4Frames[file,start,dur] extracts frames from start of dur from MP4 file `file`.";
47125
ImportWebFrame::usage = "ImportWebFrame[url] grabs a frame from the stream at url.";
48126

49-
LensDistortPoint::usage = "LensDistortPoint[{x,y},{p1,p2},{k1,...}] projects point x,y using the distortion specified in the p and k vectors.";
50127

51-
LensDistortionCorrection::usage = "LensDistortionCorrection[image,{tx,ty},theta,{p1,p1},{k1,k2,k3...}] performs a lens distortion correction along with a generalized translation (t) and rotation (theta). p1 and p2 specify 1st order astygmatism and k1-6 the different orders of distortion beyond that. Note you only need to supply k's up to the desired order of correction.";
128+
(* ::Text:: *)
129+
(*Compute various order lens distortion corrections. Was useful with de-barreling/fisheyeing the Sony and GoPro action cam footage.*)
52130

53-
ParallelImageApplyIndexed::usage = "ParallelImageApplyIndexed[f,im] maps f over im using parallel kernels. At this point, its only a single image plane";
54131

55-
InterleavingQ::usage = "InterleavingQ[im] returns True if im is interleaved.";
56-
ImageInformation::usage = "ImageInformation[im] returns a Dataset of the image information as per the FE's viewer.";
132+
LensDistortPoint::usage = "LensDistortPoint[{x,y},{p1,p2},{k1,...}] projects point x,y using the distortion specified in the p and k vectors.";
133+
LensDistortionCorrection::usage = "LensDistortionCorrection[image,{tx,ty},theta,{p1,p1},{k1,k2,k3...}] performs a lens distortion correction along with a generalized translation (t) and rotation (theta). p1 and p2 specify 1st order astygmatism and k1-6 the different orders of distortion beyond that. Note you only need to supply k's up to the desired order of correction.";
57134

58-
(* ::Section:: *)
59-
(*Internet*)
60135

136+
(* ::Text:: *)
137+
(*This is missing mainly because many/most of the image processing algorithms are already parallelized. Still, of course, I have found some that are not and this lets me take advantage.*)
61138

62-
$MachineAddressesExternal::usage = "$MachineAddressesExternal gives the IP address of this machine as seen by the outside world.";
63139

140+
ParallelImageApplyIndexed::usage = "ParallelImageApplyIndexed[f,im] maps f over im using parallel kernels. At this point, its only a single image plane";
64141

65-
(* ::Section:: *)
66-
(*Sugar*)
67142

143+
(* ::Text:: *)
144+
(*Some things that are missing that should be part of WL, IMHO.*)
68145

69-
ApplyIf::usage = "ApplyIf[f,g,x] applies g to x if f[x] is True.";
70146

71-
RectangleToDisk::usage = "RectangleToDisk[rect] takes a rectangle and returns an equivalent disk.";
147+
AddAlphaChannel::usage = "AddAlphaChannel[image] adds a unity alpha channel to image.";
148+
InterleavingQ::usage = "InterleavingQ[im] returns True if im is interleaved.";
149+
ImageInformation::usage = "ImageInformation[im] returns a Dataset of the image information as per the FE's viewer.";
72150

73-
ToCartesianRules::usage = "A set of rules for rtp->xyz";
74-
ToSphericalRules::usage = "A set of rules for xyz->rtp";
75151

76152
(* ::Section:: *)
77-
(*Versioning*)
153+
(*Internet*)
78154

79155

80-
VersionInformation::usage = "VersionInformation[path] gives an association with my primitive home grown versioning system.";
81-
VersionString::usage = "VersionString[path] returns the current build as a string. the option \"Build->True\" adds the build number to the end of the string.";
82-
VersionWriteInformation::usage = "VersionWriteInformation[path,vi] takes a version information structure and writes it out. At this point it doesn't validate its structure.";
83-
VersionBumpBuild::usage = "VersionBumpBuild[path] updates the build number in the version json file.";
84-
VersionBuildString::usage = "VersionBuildString[path] returns the current build number as a string.";
156+
(* ::Text:: *)
157+
(*Sometimes you're behind a DHCP and you want to know what you look like to the rest of the world.*)
85158

86-
UpdatePacletFile::usage = "UpdatePacletFile[ppath,vpath] writes a new PacletInfo file based on the current version and build in the FP version.json system.";
159+
160+
$MachineAddressesExternal::usage = "$MachineAddressesExternal gives the IP address of this machine as seen by the outside world.";
87161

88162

89163
(* ::Section:: *)
90-
(*Data*)
164+
(*Signals*)
91165

92-
ImportAsDataset::usage = "ImportAsDataset[f] imports f and uses the first row as column headers. Default options are \"Headers\"->True, \"RowNames\"->False, \"ImportOptions->None\" ";
93166

94-
UnitizedGaussianPDF::usage = "UnitizedGaussian[mu,sigma] gives a pure function of a PDF whose value at the mean = 1.0.";
167+
(* ::Text:: *)
168+
(*Signal processing tools*)
95169

96-
Overlap::usage = "Overlap[l1,l2] gives the intersection of the range of two lists.";
97-
98-
(* ::Section:: *)
99-
(*Signals*)
100170

101171
FindZeroCrossings::usage = "FindZeroCrossings[list] returns pairs that indicate zero-crossing locations in list.";
102172

173+
103174
FFTShift::usage = "Mimic MATLABs fftshift (ImagePeriodogram does this in more recent MMa).";
104175
InverseFFTShift::usage = "Mimic MATLABs ifftshift.";
105176

177+
106178
RealSphericalHarmonicY::usage = "RealSphericalHarmonicY[l,m,th,phi] returns real-valued spherical harmonics.";
107179

108-
(* ::Section:: *)
109-
(*Genetic Algorithms*)
110180

111-
GARepopulate::usage = "GARepopulate[pop,fitfunc] creates a new population using fitfunc.";
112-
GAMutate::usage = "GAMutate[chromo] mutates a chromosome.";
113-
GACrossover::usage = "GACrossover[c1,c2] performs a random crossover of c1 & c2. Returns two offspring.";
181+
UnitizedGaussianPDF::usage = "UnitizedGaussian[mu,sigma] gives a pure function of a PDF whose value at the mean = 1.0.";
182+
114183

115184
(* ::Section:: *)
116185
(*Statistics*)
186+
187+
188+
(* ::Text:: *)
189+
(*Re-implementation of some functions that were included in earlier statistics packages in MMa but have gone missing over the years.*)
190+
191+
117192
LocationReport::usage = "LocationReport[list] gives the Mean, HarmonicMean, and Median location statistics for list.";
118193
DispersionReport::usage = "DispersionReport[list] gives the Variance, StandardDeviation, SampleRange, MeanDeviation, MedianDeviation, and QuartileDeviation dispersion statistics for list.";
119194
ShapeReport::usage = "ShapeReport[list] gives the Skewness, QuartileSkewness, and KurtosisExcess shape statistics for list.";
120195

121-
StandardDeviationMLE::usage = "StandardDeviationMLE[list] gives the standard deviation of the entries in list. Division by n is used, giving a maximum likelihood estimate of the population standard deviation.";
122196

197+
StandardDeviationMLE::usage = "StandardDeviationMLE[list] gives the standard deviation of the entries in list. Division by n is used, giving a maximum likelihood estimate of the population standard deviation.";
123198
VarianceMLE::usage = "VarianceMLE[list] gives the variance of the entries in list. Division by n (rather than n-1) is used, giving a maximum likelihood estimate of the population variance (use Variance[list] for an unbiased estimate).";
124-
125199
StandardErrorOfSampleMean::usage = "StandardErrorOfSampleMean[list] gives an unbiased estimate of the standard error (standard deviation) of the sample mean, using the entries in list as a sample from the population.";
200+
CoefficientOfVariation::usage = "CoefficientOfVariation[list] gives the coefficient of variation, defined as the ratio of the standard deviation to the mean of the entries in list. If the entries are not all positive, then $Failed is returned."
201+
ZeroMean::usage = "Zeroize the data about the mean.";
126202

127-
VarianceOfSampleMean::usage = "VarianceOfSampleMean[list] gives an unbiased estimate of the variance of the sample mean, using the entries in list as a sample from the population.";
128203

129-
CoefficientOfVariation::usage = "CoefficientOfVariation[list] gives the coefficient of variation, defined as the ratio of the standard deviation to the mean of the entries in list. If the entries are not all positive, then $Failed is returned."
204+
(* ::Section:: *)
205+
(*Sugar*)
130206

131-
ZeroMean::usage = "Zeroize the data about the mean.";
207+
208+
(* ::Text:: *)
209+
(*Syntactic sugars*)
210+
211+
212+
ApplyIf::usage = "ApplyIf[f,g,x] applies g to x if f[x] is True.";
213+
214+
215+
(* ::Section:: *)
216+
(*Versioning*)
217+
218+
219+
(* ::Text:: *)
220+
(*WL interface to my json based version system. Also can parse and update a Paclet data structure*)
221+
222+
223+
VersionInformation::usage = "VersionInformation[path] gives an association with my primitive home grown versioning system.";
224+
VersionString::usage = "VersionString[path] returns the current build as a string. the option \"Build->True\" adds the build number to the end of the string.";
225+
VersionWriteInformation::usage = "VersionWriteInformation[path,vi] takes a version information structure and writes it out. At this point it doesn't validate its structure.";
226+
VersionBumpBuild::usage = "VersionBumpBuild[path] updates the build number in the version json file.";
227+
VersionBuildString::usage = "VersionBuildString[path] returns the current build number as a string.";
228+
229+
230+
UpdatePacletFile::usage = "UpdatePacletFile[ppath,vpath] writes a new PacletInfo file based on the current version and build in the FP version.json system.";

TODO.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
### build.wls
3333
- fix to create variable names correctly
34+
- check to see if `FPTools` are already installed, because otherwise we need to bootstrap the build
3435

3536
### release.sh
3637
- make use pre-release setting for sending to GitHub

version.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"major_version": 1,
55
"minor_version": 0,
66
"revision_number": 9,
7-
"build_number": 195,
8-
"date": "Sun Oct 21 13:58:08 EDT 2018"
7+
"build_number": 199,
8+
"date": "Mon Oct 22 20:00:34 EDT 2018"
99
}

0 commit comments

Comments
 (0)