# Tag Info

16

EDIT: graphical alignment issue corrected. I think this has promise. The centering is almost perfect, and while the code may not be well tuned or optimized it is quite fast: 0.008736 seconds on my machine. It works by attempting to find the center of each white "blob" and then averaging those positions. img = Import["http://i.stack.imgur.com/i050B.png"]; ...

15

Your image: img = Import["http://i.stack.imgur.com/i050B.png"]; Here is the circle's radius and center: crcl = ComponentMeasurements[RegionBinarize[Dilation[img, 3], {{320, 240}}, 0.3], {"Centroid", "EquivalentDiskRadius"}]; // AbsoluteTiming crcl {0.126007, Null} {1 -> {{284.448, 241.873}, 109.256}} And here how precise it is: ...

13

All the image samples you posted are basically lines pointing towards a common center. We can turn that into a simple mathematical model: Let's say every gradient in the image is normal to a line pointing towards the center. Find the center with the least squared error. So the error term would be: squaredError = ({cx - x, cy - y}.{gx, gy})^2; where cx/cy ...

11

Use the following: ListConvolve[a, b, {1, -1}, 0] (* ==> {1, 3, 6, 10, 10, 10, 9, 7, 4} *) This says: align the first element of b with the 1st element of a, align the last element of b with the -1st (i.e. last) element of a, pad with 0s if necessary. Have you tried searching the docs for "convolution"?

9

I hope I see the essence here. You are interested in the convolution of an interpolated function with a Gauss function Your underlying data has regular spacings in x-direction and the convolution with a Gaussian is extremely fast implemented in GaussianFilter for discrete data. Why are you making it so complicated when the only thing you have to do is ...

9

You could use ListConvolve: ListConvolve[a, b, {1, -1}, 0] concerning the padding: ArrayPad[b, 3, 0] And you could use Partition for the second of your steps: Partition[Range[Length[ArrayPad[b, 3, 0]]], 3, 1]

9

First I want to say, as you mentioned in your comment that your ultimate goal is to to do it for nMax over 100, I suggest you first symbolicly calculate the correlation of the following function, treating $r_n$ ($n=-s,-s+1,\dots,s$, and $s$ is nSteps for short) as variables as $x$: \xi(x,r_{-s},r_{-s+1},\dots,r_{s})=\sum _{n=-s}^{s} r_n\, ...

7

Here are two things you can do to speed up this code. 1. Do the convolution with symbolic y Because you have defined corr using SetDelayed, the table of Convolve expressions will be re-evaluated every time you evaluate corr[number]. The normalisation term with y=0 is causing a particular slow down, though I'm not sure why exactly. If you instead use Set ...

5

Sparse multiplication with a circular matrix corresponds to a convolution; on a trivial example let us compare: matrix = SparseArray[{Band[{1, 1}] -> 2, Band[{1, 2}] -> 1, Band[{2, 1}] -> 1}, {15, 15}]; vec = SparseArray[5 -> x, 15]; matrix.vec // Normal (* ==> {0, 0, 0, x, 2 x, x, 0, 0, 0, 0, 0, 0, 0, 0, 0} *) versus a = SparseArray[5 ...

4

I'm not sure you are handling the top and left edges in the way you really want; they work with the second rather than first elements being treated as "middle" twice, with first elements not treated that way at all. Here is code that does not do that, hence gives different results than yours on top and left edges. It is around two orders of magnitude ...

4

The ideas mentioned in comments and the prior response seem like good ways to go about this. As for the brute force direct method, for a reliable result you can precompute one part symbolically and handle the rest numerically. ii[y_] = Integrate[ PDF[NormalDistribution[0, 8/1000], x - y]*4 *DiracDelta[1 - x], {x, 0, 11/10}]; firstTry[y_?NumberQ] := ...

4

Using convolution theorem http://en.wikipedia.org/wiki/Convolution_theorem that Fourier of the convolution of two functions is the same as multiplications of their Fourier transforms then Use UnitStep to generate the time limited sin function to convolve with, like this Plot[UnitStep[t] UnitStep[Pi - t] Sin[t], {t, -3 Pi, 3 Pi}] and now apply the ...

3

I'd suggest doing something like this Clear[x, y, c, d, exp] x[t_] := Exp[-2*t]*(HeavisideTheta[t + 2] - HeavisideTheta[t]) + (1 - t/2)*(HeavisideTheta[t] - HeavisideTheta[t - 2]) y[t_] := -2*DiracDelta[t + 2] + 2*(HeavisideTheta[t] - HeavisideTheta[t - 2]) c[t_] := (c[t] = Convolve[x[d], y[d], d, t]); kkkk = 4; arr = Array[c, kkkk*8 + 1, {-4, ...

3

Hard to do it analytically. Tried convolution theorem also. ForuierTransform had hard time with it as well as Integrate. So, here is a numerical solution. The support needed is really only from $0$ to $2 \sqrt(2)$ since your function exist over $0$ to $\sqrt(2)$ but I integrated it over little larger range for the plot to look better. Hence ...

2

You can get some speed increase by writing your functions differently. It is almost always faster to act on whole lists in Mathematica than to explicitly loop over the individual elements. A couple of notes: Round is listable and does not have to be mapped over the array. The definition of tmp is just a dot product. The alterations to tmp in your If ...

2

As already pointed out in the comments, compiling to "C" is useless, when you use e.g. functions like GaussianFilter wich cannot be compiled down and which require a call to the evaluating kernel. Regarding your error message: Why don't you investigate in the parameters to stepC when the error occurs? You could do this by wrapping a Check around which stops ...

1

Before I start, I want to acknowledge that Daniel's answer is faster than mine because mine does not take advantage of the specific form of the energy function. However, the solution with Cellular Automaton seems very cool and works for any energy function so I decided to put it up anyway. CellularAutomaton can take a function as an argument to evaluate on ...

1

In line with the OPs request for a comparison of several different methods here's a comparison of four different ways to filter (or convolve) a data set x with a kernel h: convolution, correlation, the frequency domain method, and a direct time domain method. The only difference (other than numerical factors) is in the way edge conditions are handled with ...

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