Dr. belisarius
  • Member for 10 years
  • Last seen more than 4 years ago
Help find a bright object on Mars!
97 votes

Let's define a filtering chain: isolateTheSand[x_Image] := ColorNegate@ Dilation[Closing[EdgeDetect[EntropyFilter[x, 1], 10], 100], 30]; getBrightObjects[x_Image] := ...

View answer
What does # mean in Mathematica?
73 votes

# is a placeholder for an expression. If you want to define a function, $y(x)=x^2$, you just could do: f = #^2 & The & "pumps in" the expression into the # sign. That is important for ...

View answer
How to ask Mathematica to imitate Andy Warhol's pop-art painting?
Accepted answer
67 votes

Let's do it Andy's way So you are Andy. Nice to meet you. And you never got those hands on a computer. It doesn't matter, I will show you! First you need to go to Marilyn's place. Don't worry, JF ...

View answer
Changing color of an object in an image
59 votes

I wanted to change only the color of the ball, leaving all other red objects untouched: getReds[x_Image] := First@ColorSeparate[x, "Hue"] isolateSphere[x_Image] := SelectComponents[Binarize[getReds[x]...

View answer
Animating mathematica.se logo
52 votes

Breathing with occluded borders, per Toad's request: Run the following command to get the Mathematica code NotebookPut@ImportString[Uncompress@FromCharacterCode@Flatten@ImageData[ ...

View answer
How to find circular objects in an image?
Accepted answer
51 votes

The following method doesn't require parameters and discovers also oblique views. obl[transit_Image] := (SelectComponents[ MorphologicalComponents[ DeleteSmallComponents@...

View answer
How to draw a spring?
50 votes

A textbook-like animation turns = 10; aa = Table[Framed@ Show[ParametricPlot3D[ Piecewise[{{{1, x, 0}, x <= 0}, {{Cos[2 Pi turns x/r], x, Sin[2 Pi turns x/r]}, 0 ...

View answer
Performance tuning in Mathematica?
50 votes

You may use the profiler included in the Wolfram Workbench

View answer
Is it possible to draw this figure using Mathematica?
45 votes

voronoi[pts_] := ListDensityPlot[Append[#, 0]&/@ pts, InterpolationOrder-> 0, Frame -> False] pts = RandomReal[{0, 256}, {20, 2}]; cp ...

View answer
Marking points of intersection between two curves
Accepted answer
43 votes

Edited to make it a function. For the strange Exclusions specification I use below, see my answer here. Thanks to @Oleksandr and @JM for their great comments. plInters[{f1_, f2_}, {min_, max_}] := ...

View answer
Finding a function that fits the shape of an image
39 votes

The following is something I made while trying to solve another (similar) problem (*FindCurvedPath Replacement*) ClearAll[findCurvedPath2, findClosedPath2]; findClosedPath2[inptList_, cutoff_] := ...

View answer
How can I mark each of several plots with a parameter that identifies it?
39 votes

I made a function that could be used for labeling plots interactively, adding labeled Bezier arrows, preserve your labels from session to session, and a few more goodies. Some snapshots follow: ...

View answer
Visual representation of a Ranking over time (image provided)
Accepted answer
37 votes

Some function definitions first. AkimaInterpolation[] stolen from here: AkimaInterpolation[data_] := Module[{dy}, dy = #2/#1 & @@@ Differences[data]; Interpolation[Transpose[{List /@ data[[All, ...

View answer
Reconstruct a graph from an image (curved edges and edge crossings)
Accepted answer
32 votes

Without claiming much generality, I made the following. I'm using a slightly more complex image than your proposed one. i = Binarize@Import@"http://i.stack.imgur.com/qDby8.png"; idi ...

View answer
How can I create a fountain effect?
Accepted answer
30 votes

Here you have a toy to start playing with: Edit preventing the animation running at different speeds in different machines by using Clock[] and DynamicWrapper[] (due credit to @jVincent) n = 500; (*...

View answer
Tiling a square
Accepted answer
30 votes

In this article the author solves the problem of tiling a rectangle by using pieces taken from a set of polyominoes, which are plane geometric figures formed by joining one or more equal squares edge ...

View answer
Plotting Error Bars on a Log Scale
30 votes

Without using the "ErrorBarPlots`" Package dataX = Sort@RandomReal[1, 10]; dataY = RandomReal[{0.5, 1}, 10]; error = RandomReal[0.5, 10]; errorH = dataY + error; errorL = dataY - error; f[y_] := ...

View answer
How to map an image to get an illusion of 3D
29 votes

lin[cam_, obj_][t_] := cam t + (1 - t) obj s[cam_, obj_] := First@Solve[lin[cam, obj][t][[3]] == 0, t]; tr[cam_, obj_] := lin[cam, obj][t] /. s[cam, obj] // FullSimplify And that's it: tr[ ] is your ...

View answer
How to make a pie chart using custom image
Accepted answer
28 votes

i = Import@"http://i.stack.imgur.com/8I3B1.jpg"; f[{{tmin_, tmax_}, {rmin_, rmax_}}, ___] := Module[{l = Join[{{0, 0}}, Table[{Cos@t, Sin@t}, {t, tmin, tmax, (tmax-tmin)/100}]]}, {Texture[i], ...

View answer
How can I collect data for visualization of quick sort?
Accepted answer
28 votes

n = 100; (*number of points*) s = RandomSample@Range@n; (*the initial set*) (*some aux functions*) head[{x_, xs___}] := Select[{xs}, # <= x &]; tail[{x_, xs___}] := Select[{xs}, # > x &];...

View answer
Detecting an ellipse in a glaucoma photo
27 votes

Fitting an ellipse: i = Import["http://i.stack.imgur.com/W7HJk.jpg"]; lineByCenter[center_, semi_, angle_] := Rotate[Line[{#1 - #2, #1 + #2}], angle, #1]& ...

View answer
Is there a Mathematica barcode reader?
27 votes

Here is a bare bones, non-robust, use at your own risk, etc. code39 reader (*get image *) i = Binarize[Import@"http://i.stack.imgur.com/Cx3JD.png", .7] (* Char encodings from Paul's article - See ...

View answer
How could I add arrows to the axis of a figure?
Accepted answer
27 votes

Plot[1/x^5, {x, -20, 20}, AxesStyle -> Arrowheads[{0.0, 0.05}], ImagePadding -> None]

View answer
Nice formatting for the results of a dice game simulation
26 votes

After importing a free dice 3D model {pd, vd} = Import["c:\\dice.stl", #] & /@ {"PolygonData", "VertexData"}; g2 = Translate[GraphicsComplex[vd, Polygon /@ pd], {-10, -37.5, -10}]; rv = {{0, 0, -...

View answer
Improve TextRecognize[] on numbers
26 votes

TextRecognize[] accepts an undocumented Option "SegmentationMode". The allowed values are: ?Image`ExternalOCRDump`$TextRecognizeSegmentationModes { {{3, "Fully automatic page segmentation, but no ...

View answer
Symbolic area calculation for a parametric self-intersecting closed curve
26 votes

The plan is first get the "external" contour and then use Green's theorem to find its area. r[t_] := {-9 Sin[2 t] - 5 Sin[3 t], 9 Cos[2 t] - 5 Cos[3 t], 0} (*find the intersections*) tr = Quiet@...

View answer
Is there a concise form of Which or similar conditional?
26 votes

For example you may do something like f[i_] := {Red,Orange,Yellow}[[i]] Edit You can easily add some robustness: f[l_List, i_Integer ] := l[[i]] /; 1 <= i <= Length@l; ll = {Red, Orange, ...

View answer
Animating transition between all graph representations obtained from curated data
Accepted answer
26 votes

The following is a little involved, but it calculates the "minimum displacement" evolution by choosing the least total displacement alternatives from the permutations generated by the "...

View answer
Plotting discontinuous functions without spurious vertical segments
Accepted answer
26 votes

I looked for a way without redefining the function and not using explicit knowledge about it (so it can be generalized) pl[f_, lims_] := Module[{eps = 0.05}, Off[InverseFunction::"ifun"]; ...

View answer
Implementing hexagon binning in mathematica
25 votes

As this answer got much more attention than I thought at first, I felt compelled to pack the answer as a function. The following function draws three different hex-histogram representations of your ...

View answer
1
2 3 4 5
60