1
$\begingroup$

I'm trying to recreate in Javascript a piece of code that appeared here on Mathematica, specifically in this answer.

The user Simon Woods suggested an amazingly efficient way of drawing lines over the picture that seem to follow a natural brushing style.

I'm very new to Mathematica and I'm trying to figure out exactly what is happening here:

lines = MapIndexed[{GrayLevel@RandomReal[], 
     Line[{#2 - 2 {Cos[#1], Sin[#1]}, #2 + 2 {Cos[#1], Sin[#1]}}]} &, 
   Reverse /@ Transpose@ImageData@gof, {2}];

I've put together a function that should cover the GradientOrientationFilter, outputting the vector directions in radiants and magnitudes. If you want, you can see it here.

I hope someone can help me understand how he is using the outputs of GradientOrientationFilter.


This is the complete code:

img = Import["http://i.stack.imgur.com/XwYg7.jpg"];

im = img ~ImageResize~ 200 ~ColorConvert~ "Grayscale";

gof = im ~GradientOrientationFilter~ 5;

lines = MapIndexed[{GrayLevel@RandomReal[], 
     Line[{#2 - 2 {Cos[#1], Sin[#1]}, #2 + 2 {Cos[#1], Sin[#1]}}]} &, 
   Reverse /@ Transpose@ImageData@gof, {2}];

brush = Image[
   Graphics[lines, 
    PlotRange -> {{1, #1}, {1, #2}} & @@ ImageDimensions[im], 
    Background -> GrayLevel[0.5], ImageSize -> ImageDimensions[img]], 
   ColorSpace -> "Grayscale"];
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.