Re: blurry ellipse
- To: mathgroup at smc.vnet.net
- Subject: [mg92072] Re: blurry ellipse
- From: dh <dh at metrohm.ch>
- Date: Fri, 19 Sep 2008 05:16:20 -0400 (EDT)
- References: <gat9g4$ec5$1@smc.vnet.net>
Hi Joshua, you can blurry any picture by a convolution with a suitable kernel. Here is an example. We first create a picture of an ellips. Then we increasingly blurry it three times. Note that we must keep the numbers between 0..1 because of "Raster": n=100; pict=Table[0,{n},{n}]; Scan[(pict[[Round[n/2+n/5 Sin[#]],Round[n/2+2 n/5Cos[#]]]]=1)&,Range[0,2Pi,0.01]]; Graphics[Raster[pict]] kernel={{1,1},{1,1}}; pict=ListConvolve[kernel,pict];pict=pict/Max[pict]; Graphics[Raster[pict]] kernel={{1,1,1},{1,1,1},{1,1,1}}; pict=ListConvolve[kernel,pict];pict=pict/Max[pict]; Graphics[Raster[pict]] kernel={{1,1,1,1},{1,1,1,1},{1,1,1,1},{1,1,1,1}}; pict=ListConvolve[kernel,pict];pict=pict/Max[pict]; Graphics[Raster[pict]] Note that you may instead of using a larger kernel, repeat the operation. hope this helps, Daniel Solomon, Joshua wrote: > NB: This is a mathematical problem, not necessarily a Mathematica problem. > > I need a rasterized, blurry ellipse, i.e. an ellipse convolved with a > Gaussian. I already know how to make a blurry circle. You take the Fourier > transform of a circle (i.e. a Bessel function), the Fourier transform of a > Guassian, multiply them, and transform them back. No problem. Since an > ellipse is just a circle that has been squashed in one dimension, I figured > I could make a blurry one the same way as I make blurry circles. I just > needed to squash the Bessel function first. And I was right. The code below > works just fine, *except* the intensity varies as you go around the elipse. > If anyone could tell me how to fix that problem, I'd be very grateful! > > BlurryEllipse[sizePix_, radiusPix_, sigmaPix_,stretchFactors_: {1, 1}] := > > Module[{half = sizePix/2, x, y, f, r, a, pr2}, > > f = 2*Pi*radiusPix/sizePix; > pr2 = -2 (Pi*sigmaPix/sizePix)^2; > > RotateRight[ > > Abs[ > Chop[ > > InverseFourier[ > > RotateRight[ > > Table[r1= > Abs[stretchFactors[[1]]*x+ > stretchFactors[[2]]*I*y]; > r2 = Abs[x + I*y]; > BesselJ[0, f*r1] Exp[pr2 (r2^2)], > {y, -half, half-1} , {x, -half, half-1}], > {half, half}]]]], {half,half}]] > > size = 64; rad = 24; scale = 3; > tmp = BlurryEllipse[size, rad, scale, {1, .5}]; > Show[Graphics[Raster[tmp/Max[Max[tmp]]]], ImageSize -> 400] > > Intensity varies around the elipse. We can compare amplitude (or power) > ratios between major and minor axes: > > In[]:=Max[tmp[[33]]]/Max[Transpose[tmp][[33]]] > > > Out[]=1.93009 > > > In[]:= Sqrt[Total[tmp[[33]]^2]/Total[Transpose[tmp][[33]]^2]] > > Out[]= 1.98887 > > > > I was surprised these numbers weren't closer to 2. How can we make intensity > invariant around the ellipse? > > -- Daniel Huber Metrohm Ltd. Oberdorfstr. 68 CH-9100 Herisau Tel. +41 71 353 8585, Fax +41 71 353 8907 E-Mail:<mailto:dh at metrohm.com> Internet:<http://www.metrohm.com>