# 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"]; ...

16

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: Show[img,...

16

$Version (* "8.0 for Microsoft Windows (64-bit) (October 7, 2011)" *) Direct attack fails: Timing[Convolve[Sinc[x], Exp[-x^2], x, y]] (* Out[218]= {59.296, Convolve[Sinc[x], E^-x^2, x, y]} *) or, equivalently, Timing[Integrate[Sinc[x] Exp[-(x - y)^2], {x, -∞, ∞}] ]$\left\{49.92,\int_{-\infty }^{\infty } e^{-(x-y)^2} \text{Sinc}[x] \, dx\right\}... 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 ... 13 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"? 12 As mentioned in a comment by ciao, blind deconvolution is no easy task. However, here are some pointers for estimating the kernel parameters. These can equally be applied to denoising an image rather than deblurring. I am assuming that the form of the kernel is known here, rather than blind deconvolution (Wikipedia) methods such as Maximum A Posteriori (... 11 While it's tempting to attribute the errors you're observing to floating-point errors due to zeros in the DFT of the window, this is actually not the case here: Window[width_, x_] := UnitStep[x + width/2] UnitStep[width/2 - x]; Test[x_] := UnitStep[x] UnitStep[count - x] Sin[1/10 x]^2; tempWindow = Table[Window[20, x], {x, -count/2, count/2}]; {Min[Abs[... 11 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 ... 11 In line with the OPs request for a comparison of several different methods here's a comparison of six different ways to filter (or convolve) a data set x with a kernel h: convolution, correlation, the frequency domain method, a direct time-domain method such as might be programmed in C or Java, and a vectorized version such as would be common in Matlab or ... 10 I think this should work: ClearAll[r]; r[0, t_] := Exp[-k*t]*Cos[t]; r[n_, t_] := Integrate[r[0, t - td]*r[n - 1, td], {td, 0, t}] eg r[2,t] (* (\[ExponentialE]^(-k t) (2 \[ExponentialE]^(k t) k^2 - k (2 k + t + k^2 t) Cos[t] + (k - k^3 + t + k^2 t) Sin[t]))/(2 (1 + k^2)^2) *) 10 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, treatingr_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\, \text{mod}(x-n\,... 9 The functions do not have a finite area, so they cannot be real distributions as your title claims they are. Let's change them a bit so they have area 1. f[x_] = (1/k) Exp[-x/k] UnitStep[x]; g[x_] = (1/p) Exp[-x/p] UnitStep[x]; Integrate[f[x], {x, -∞, ∞}] ConditionalExpression[1, Re[1/k] > 0] The convolution: Convolve[f[x], g[x], x, y] ... 8 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 ... 8 As already mentioned, this is a convolution. Luckily, there's a more natural function to use for this problem than Integrate[], and that function is called, appropriately enough, Convolve[]. Now, since Convolve[] assumes an infinite integration region, we need a UnitStep[] multiplier in both the functions being convolved to limit the integration region to a ... 7 Here is a way to solve this problem using the convolution theorem: l = Assuming[{\[Gamma] > 0 && \[Sigma] > 0 && \[Mu] > 0 && k \[Element] Reals}, FourierTransform[PDF[CauchyDistribution[\[Mu], \[Gamma]], x], x, k] ]$\frac{\left(\theta (-k) e^{2 \gamma k}+\theta (k)\right) e^{-k (\gamma -i \mu )}}{\sqrt{2 ...

7

We consider h = Exp[g]. The main idea is to calculate the Fourier transform of h, expand it into a series in powers of v, and then transform back Here we go. The normal distribution is explicitly f = 1/(v Sqrt[2 \[Pi]]) Exp[-(x - z)^2/(2 v^2)]; Now the Fourier transformation of h acts only on f, with the result ft = FourierTransform[f, x, t, ...

7

I wasn't sure how to set it up with the standard fit functions, so I just rolled my own least squares. (It probably can be done, but I had an inkling I might want to have greater control over the computation. I hope it helps.) I start by defining m1 and m2 on your data: Clear[m1, m2]; (m1[t_] /; t == First@# = Last@#) & /@ m1data; (m2[t_] /; t == ...

6

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 faster....

6

I think you are trying to do the following: Clear[h]; h[n_] /; n >= 1 := -((I^-n (-1 + I^n)^2)/(n^2 Pi^2)) h[0] = 1/4; Clear[y]; y[m_] := DiscreteConvolve[h[n], DiscreteDelta[n], n, m] y[0] (* ==> 1/4 *) Here corrected your definition of y so it uses m as the function argument, but the important part is to understand why even with this ...

6

(1) Convolution with Plus and Times can be done via FFT. (2) The overall speed complexity cannot be less than the size-of-result complexity. Point (1) might help to explain why the standard ListConvolve is fast under most circumstances. Point (2) on the examples in this post should help to explain why LC2 is likely to be slow. To make this clear we can ...

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 ...

5

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 ...

4

As Nasser has observed numerical integration works. The following plots (f[x],f[y-x] f[x]f[y-x[ and convolution below) for varying y and thus gives insight into convolution). where convolution was obtained: g[y_] := NIntegrate[f[x] f[y - x], {x, -Infinity, Infinity}]

4

I think the problem is that it could not do the symbolic integration. Meanwhile, you could always do the convolve directly, since it is just an integration, using NIntegrate. Unless you are looking for a closed form expression of conv(f,g). It would be more efficient to find the conv(f,g) expression, and then evaluate it for different $y$ values than having ...

4

You have to go line by line to see your errors. You have to do this for each RGB channel separately. img = Import["ExampleData/lena.tif"]; data = ImageData /@ ColorSeparate[img]; {row, col} = Dimensions[data[[1]]]; H[a_, b_, T_] := Function[{x, y}, z = Pi*(a*x + b*y); T*N[Sinc[z]*Exp[-I*z]]] filter = Array[H[0.1, 0.1, 1], {row, col}]; filter // Abs // ...

4

Here is another way that allows you to directly use Convolve: Convolve[TrigToExp@FunctionExpand[Sinc[x]], Exp[-x^2], x, X] (* ==> -(1/2) E^-X^2 Pi Erfc[1/2 - I X] - 1/2 E^-X^2 Pi Erfc[1/2 + I X] *) In order to get a successful evaluation, I just had to break up the Sinc function into its complex exponential terms.

4

To record an answer officially: As noted by Daniel Lichtblau in a comment, it is a bug. Szabolcs comments that it affects versions 10.0.1, 10.0.2, and 10.1.0, but not versions before 10 (and unclear about 10.0.0). As of the time of writing, version 10.1.0 is the most recently released. However, Daniel further adds that it has already been fixed in the ...

4

You can just apply ArrayPad before performing the convolution; it supports all the desired padding forms and more. However, you'll have to adjust the third parameter of ListConvolve to get rid of the extra entries in the result.

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