2

I just read StackExchange blog It’s OK to Ask and Answer Your Own Questions which even encourages it and decided to ask about a problem I now know how to solve. But I found an elegant answer only recently (and will post it now below), much inspired by this very site and answers I'm trying to understand.

Q: I would like to round the corners of an image into circular arcs of some radius before I upload it to a blog.

Test image:

enter image description here

BoLe
  • 5,819
  • 15
  • 33

1 Answers1

1
round[i_, r_] :=
 Module[{w, h},
  {w, h} = ImageDimensions@i;
  With[{
    f = Reverse,
    p = PadRight[DiskMatrix[r][[;; r, ;; r]], {h, w}, 1]},
   i~ImageAdd~ColorNegate@Image[p f /@ p f@p f[f /@ p]]]]

img = Import@"https://i.stack.imgur.com/f1gur.jpg";

img~round~20

finemanround

BoLe
  • 5,819
  • 15
  • 33