# Tag Info

38

Needs["PolyhedronOperations`"] poly = Geodesate[PolyhedronData["Dodecahedron", "Faces"], 4]; amplitude = 0.15; twist = 4; verts = poly[[1]]; faces = poly[[2]]; phases = RandomReal[2 Pi, Length[verts]]; newverts[t_] := MapIndexed[{Sequence @@ (RotationMatrix[twist Last[#1]].Most[#1]), Last[#1]} (1 + amplitude Sin[t + phases[[First@#2]]]) &, ...

35

The following method doesn't require parameters and discovers also oblique views. obl[transit_Image] := (SelectComponents[ MorphologicalComponents[ DeleteSmallComponents@ChanVeseBinarize[#, "TargetColor" -> Red], Method -> "ConvexHull"], {"Count", "SemiAxes"}, Abs[Times @@ #2 Pi - #1] < #1/100 &]) & @ transit; ...

29

Obtain the image: i = Import["http://i.stack.imgur.com/iab6u.png"]; Compute the distance transform: k = DistanceTransform[ColorNegate[i]] // ImageAdjust; ReliefPlot[Reverse@ImageData[k]] (* To illustrate *) Identify the "peaks," which must bound the Voronoi cells: l = ColorNegate[Binarize[ColorNegate[LaplacianGaussianFilter[k, 2] // ImageAdjust]]]; ...

29

Basically, you want to fit a shape to a set of points with outliers. One common algorithm to do this is RANSAC (random sample consensus). The basic outline of this algorithm is: Select N points at random (where N is the minimum number of points required for fitting the shape, i.e. 2 for a line, 3 for a circle and so on) Fit the shape to these points Repeat ...

25

==== Method 1 === Here is a way to get a graph from an image. MorphologicalGraph can get you started. img = Import["http://i.stack.imgur.com/9HXZ5.png"]; g = MorphologicalGraph[img] And here is your KirchhoffMatrix of the graph. Please note that MatrixPlot averages values for the best visual representation, - actual plot would be too detailed to be a ...

23

Forward Mapping One way to do it is to create the texture for one tile and then transform repeated copies of it in a way that resembles the original illusion. First we create the tile: tile = Module[{KeyHole}, KeyHole[base_] := Sequence[ Disk[{0, 1/3} + base, 1/10], Rectangle[{-1/30, 1/15} + base, {1/30, 1/3} + base] ]; ...

20

One standard way to detect circular shapes is to binarize the image and apply a distance transform: The maxima locations of the distance transform are the centers of the circles. To make this work on your ellipses, I first have to stretch them to be (roughly) circular, as @Rahul Narain suggested in a comment: img = ...

18

Preload all chemical data: ChemicalData[All, "Preload"]; RebuildPacletData[]; (* the latter should not really be necessary *) Get all names: cd = ChemicalData[]; Get their molecular formulae: l = ChemicalData[#, "MolecularFormulaString"] & /@ cd; By counting the Cs, Os and Hs in the tattooed diagram we know we have to find ...

17

On my system (Windows 7 64-bit, 12GB, Mathematica v8) I only see a factor of 2 between the image file size and the memory used by the image data. This agrees with the observation that packed arrays of integers use 32 bits per element. To confirm this, a ConstantArray containing values of $2^{31}-1$ (the maximum signed 32-bit integer) is packed and has a ...

17

Here a quick hack for PNG images. As its Wikipedia page shows the format works with coded chunks and you can make up and insert chunk types yourself. I'm not sure how safe it is to add beyond the official end of file marker as Simon Woods suggests in his answer. It seems like a breach of the standard to me. The following code, which more closely seems to ...

17

When thinking about graphics formats that can be displayed in web browsers and also in Word, the first thing that comes to mind is a rasterized image. However, there is one alternative that makes including comments a complete no-brainer: SVG (scalable vector graphics). The way you do it is similar to what cormullion suggested for EPS, except that EPS of ...

17

Here's a method based on creating a MeshRegion from the text: text = Style[HoldForm @ Sum[x^2, {x, 0, 10}], 100, Bold]; graphics = First[text ~ExportString~ "PDF" ~ImportString~ "PDF"]; region = DiscretizeGraphics[graphics, MaxCellMeasure -> 5]; image = ExampleData[{"ColorTexture", "Kingwood"}]; RegionPlot[region, Frame -> False, ...

16

This is more of an add-on to Vitaliy's excellent answer, than a completely new approach. I wanted to try to simulate some of the image distortion that would be seen at the jar walls. A simple (though utterly wrong in a physics sense) way to do this is to make the demagnification vary according to the jar image intensity. Load a picture and the jar image, ...

16

================= UPDATE ====================== Due to @halirutan comment I'll add a note on realism. First of all pure water and clouds are not the best subject to simulate reflecations because they have fractal structure - meaning they tend to appear the same on different magnification scales. So it is hard to give impression to a human eye of refraction ...

16

I believe this is a bug in Mathematica. It can be verified that the unreasonable memory usage is due to array unpacking by On["Packing"] ExportString[Image@RandomReal[1, {30, 30}], "BMP"]; So please report it to support@wolfram.com so this can be fixed for the benefit of all of us, and point them to this discussion. Some further playing with Simon ...

15

There is something you can do. I just tried it with a JPEG image that I pasted into a notebook. The original image had 900kB and the notebook with only that image had 11.2 MB! Let's say you have an image in an output cell of your notebook, then select the cell bracket, go to Cell > Convert To... > Bitmap and the resulting notebook will be much ...

15

Basically, you import the image: i = Import["http://upload.wikimedia.org/wikipedia/commons/2/2c/Crow_on_the_sign_of_no_parking.jpg"] Tidy it up: mb = MorphologicalBinarize[i] Isolate the areas of interest: cn = ColorNegate[Closing [mb, 10]] Use component analysis: sc = SelectComponents[ cn, {"Eccentricity", "Circularity"}, #1 < .5 ...

15

Your problem is essentially colour quantization, and to make it look good you need some form of dithering. Floyd-Steinberg dithering is a classic algorithm that also happens to have nice pseudocode in the Wikipedia article. (Rojo's answer appears to do something like random dithering.) Note: This functionality probably exists somewhere inside Mathematica ...

15

Played with some image processing functions, get some rough procedure. Import the test image: img = Import["http://i.stack.imgur.com/H2Ksg.jpg"]; Do some gamma adjust to emphasize the edge: img // ImageAdjust[#, {0, 0, 5}] &; Draw rough edges: GradientFilter[%, 2, "NonMaxSuppression" -> True] // ImageAdjust Binarize and dilate it to form ...

15

First, there is no need to use Module in your sample code above. You could write simply: CCGray[pic_?ImageQ] := ColorConvert[pic,"GrayScale"] Now, if you want to manage the channel mixing manually you can use ImageApply and Dot: customGray[img_?ImageQ, ker_?VectorQ] := ImageApply[ker.# &, img] img = Import["http://i.stack.imgur.com/wtlqF.jpg"]; ...

15

Circular Hough Transform I have had fun implementing a circular Hough transform based solution for this question (in part using some MMA9 Image3D functionality which has become available in between). By this shape-related approach we can overcome the color restrictions of the approaches tried so far. The method starts with an edge detection, followed by a ...

15

image = Import["http://i.stack.imgur.com/UNXEV.jpg"]; n = TotalVariationFilter[image, 0.05] b = LocalAdaptiveBinarize[n, 50] s = DeleteSmallComponents[ColorNegate[DeleteSmallComponents[b, 20^2]], 20^2] (d = DistanceTransform[s]) // ImageAdjust m = MaxDetect[d, 10] (w = WatershedComponents[ColorNegate[d], m]) // Colorize c = ComponentMeasurements[w, ...

14

The technique is mentioned in one of Wolfram CDF virtual conference talks (See the course: Developing Real-World CDF Applications), as well as being used in a lot of CDF examples (for instance, the slideshow at the beginning of this example) but I will repeat it here, with some improvement. Recompressing images with better compression (Note: While writing ...

14

Here's a reorganization of GaussianRandomField[] that works for any valid dimension, without the use of casework: GaussianRandomField[size : (_Integer?Positive) : 256, dim : (_Integer?Positive) : 2, Pk_: Function[k, k^-3]] := Module[{Pkn, fftIndgen, noise, amplitude, s2}, Pkn = Compile[{{vec, _Real, 1}}, With[{nrm = Norm[vec]}, ...

14

Too late and not so general as @Nikie but I will still like to answer in order to highlight a method involving generalized Eigen values! Lets take the image. img = Import["http://i.stack.imgur.com/H63BK.jpg"]; (* Detecting ellipsoidal edges and removing the straight line component *) i = ImageSubtract @@ {EdgeDetect[img, 10],EdgeDetect[img, 10, ...

13

This is a simple way: Show[ Plot[Sin[x], {x, 0, 2 \[Pi]}], Graphics[{PointSize[Large], Red, Point[{3 \[Pi]/2, -1}], Black, Text["Minimum", {3 \[Pi]/2, -.8}]}]] Edit If you have an image created with Colorize you can apply the same method. In the example below img is the image you obtain by taking the first example given in the Help under ...

13

Here's my go: pic = Import["http://www.agrisera.com/dokument/bibliotek/sample_quality1.jpg"]; Framed[pic] Isolate the picture by deleting rows and columns with mostly white, and reorient for convenience. pic2 = pic // ImageData // {#, Transpose@#} & // Count[#, {1., 1., 1.}]/Length[#] & /@ # & /@ # & // Flatten[Position[#, n_ /; n < ...

12

In Mathematica 8, few image files are supported natively--meaning, without calling external MathLink executables, which results in much faster speed (order of magnitude) and great efficiency in memory usage. Currently only TIFF and JPEG work that way. PNG was close but it was cut-off. What I am saying is that you will see much speed up in the future for PNG ...

12

If the power spectrum is always of the form $1/k^p$ there are some optimisations you can make. The first is to compile a function to generate the reciprocal of the spectrum: $k^p$. This can be very fast since you don't need to check for the $k=0$ point (the reciprocal spectrum is well behaved at $k=0\$). We can then use ReplacePart to temporarily set the ...

12

Using pieces from the linked answers, and Heike's code: Text piece: txt1 = Take[ ExampleData[{"Text", "LoremIpsum"}, "Lines"], {1, -1, 2}][[1]] // StringTake[#, 330] &; Image piece: pic = Import["http://dailytechgadgets.files.wordpress.com/2011/02/old-ferrari.jpg"]; And Heike's code for rectangles: rec[ll_, ur_, pic_] := Module[{crop, ...

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