Re: blurry ellipse
- To: mathgroup at smc.vnet.net
- Subject: [mg92063] Re: blurry ellipse
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Thu, 18 Sep 2008 07:31:41 -0400 (EDT)
- References: <gat9g4$ec5$1@smc.vnet.net>
Hi, you function are exceptional long winded. Try: makeImage[todraw_] := Rasterize[ Graphics[{White, todraw}, Background -> Black, AspectRatio -> Automatic, PlotRangePadding -> 1], ColorSpace -> GrayLevel] gauss[s_] := Table[N[Exp[-(x^2 + y^2)/(2*s)]/(2 Pi*s)], {x, -10, 10}, {y, -10, 10}] and makeImage[Circle[{0, 0}, 1]] /. Raster[bm_, args___] :> Raster[ ListConvolve[gauss[2], bm, {6, 6}], args] makeImage[Circle[{0, 0}, {1, 0.5}]] /. Raster[bm_, args___] :> Raster[ ListConvolve[gauss[2], bm, {6, 6}], args] Clearly you have to adjust the parameters of the functions above to fit your needs. Regards Jens 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? > >