I hope that someone can help me understand how to perform the following algorithm in Mathematica, I am taking as reference the next page reference page in your section planar version
, the problem is that I still have no idea how to start, I hope someone is So kind to help me. I have tried several hours to implement something but without success. thank you very much for your help
Asked
Active
Viewed 259 times
4
J. M.'s missing motivation
- 124,525
- 11
- 401
- 574
vicente
- 41
- 1
-
Show us what you have tried so far; it may be a good starting point for a solution. – MarcoB Jan 29 '17 at 05:12
-
Raise or lowered by how much? – Michael E2 Jan 30 '17 at 00:01
1 Answers
6
We can use this answer on math.SE to determine on which side of a line a point lies. Based on this formula, we have that the new gray level is given by
f[{{x1_, y1_}, {x2_, y2_}}][gl_, {x_, y_}] := gl + 0.1 Sign[(x - x1) (y2 - y1) - (y - y1) (x2 - x1)]
We can apply this to all pixels recursively in the following manner:
iterate[img_] := Module[{dimx, dimy, pts},
{dimx, dimy} = ImageDimensions[img];
pts = Transpose[{RandomInteger[dimx, 2], RandomInteger[dimy, 2]}];
ImageApplyIndexed[f[pts], img]
]
img = ConstantImage[0.5, {300, 300}];
Nest[iterate, img, 50]

Below is another test run with more iterations, and I also changed the constant 0.1 in front of Sign to 0.02. This constant determines how much each side is raised or lowered, and it has a big influence on the visual effect.
Nest[iterate, img, 100]

I'm not sure how to prove correctness for this algorithm, so if anyone spots an error please tell me.
-
Your
ptsarray is {{x,x},{y,y}} rather than {{x,y},{x,y}} likefis expecting. Maybe throw aTransposein there so it will work when the image isn't square. – wxffles Jan 30 '17 at 00:52 -