|
From: Jason G. <jas...@cr...> - 2012-10-04 14:21:36
|
On 10/4/12 4:02 AM, Pierre Haessig wrote: > Hi Fernando, > > Le 04/10/2012 09:16, Fernando Perez a écrit : >> This would make for an awesome couple of examples for the gallery, the >> mathematica solutions look really pretty cool: >> >> http://mathematica.stackexchange.com/questions/11350/xkcd-style-graphs > I've never used Mathematica so that it's pretty difficult for me to > understand the following lines of code which I guess do the main job of > distorting the image > > xkcdDistort[p_] := Module[{r, ix, iy}, > r = ImagePad[Rasterize@p, 10, Padding -> White]; > {ix, iy} = > Table[RandomImage[{-1, 1}, ImageDimensions@r]~ImageConvolve~ > GaussianMatrix[10], {2}]; > ImagePad[ImageTransformation[r, > # + 15 {ImageValue[ix, #], ImageValue[iy, #]} &, DataRange -> > Full], -5]]; > > > Is there somebody there that can describe this algorithm with words > (English or Python ;-)) ? f@r means f(r) a~ImageConvolve~b means ImageConvolve(a,b) (~ treats an operator as infix) Table[..., {2}] means [... for i in range(2)] #+1& is a lambda function lambda x: x+1 So I think it goes something like: def xkcdDistort(p): r = ImagePad(Rasterize(p), 10, Padding='White') (ix, iy) = [ImageConvolve(RandomImage([-1,1], ImageDimensions(r)), GaussianMatrix(10)) for i in range(2)] return ImagePad(ImageTransformation(r, lambda coord: (coord[0]+15*ImageValue(ix, coord), coord[1]+15*ImageValue(iy, coord)), DataRange='Full'), -5) Thanks, Jason |