Message Boards Message Boards

[NEW-11.2] Torn edge paper effect with semi-transparent drop-down shadow

Posted 7 years ago

Some time ago Vitaliy Kaurov asked an interesting question about implementing in Mathematica so called "torn edge" effect in context of conveying a message perfectly formulated by Sjoerd C. de Vries: "There's more of this, but that's not important." As an answer Heike (a Mathematica.StackExchange community member) published an ingenious implementation which deservedly received a huge amount of upvotes. She not only implemented a "torn edge" effect but also provided an option to add a drop-down shadow in order to dramatize the effect. Here is what her function named torn generates from the "Mandrill" example image in Mathematica 8.0.4 (it doesn't work correctly in the recent versions due to an incompatible change in image processing functionality):

img = ExampleData[{"TestImage", "Mandrill"}];

torn[img, {{0, 1}, {1, 0}}, "offset" -> {20, 20}, "gaussianBlur" -> 10]

image

As Vitaliy recently pointed out, with the release of Mathematica 11.2 we've got a "TornFrame" image effect immediately available via ImageEffect function:

ImageEffect[img, {"TornFrame", Scaled[1/15], {Right, Bottom}, .05}]

image

But people at StackExchange quickly noticed that this effect doesn't produce a sufficiently irregular ripped-out edge, what means that the message that the image is truncated and "there is more of this, but that's not important" isn't exactly obvious (as opposed to the implementation provided by Heike). By spelunking the evaluation of ImageEffect with Trace I've found a simple hack allowing to generate a "Heike-style" torn edge effect:

tornEdge = Block[{Accumulate = RandomReal[1, Length[#]] &}, 
  ImageEffect[img, {"TornFrame", Scaled[1/15], {Right, Bottom}, .08}]]

image

Further investigation showed that using new "Frame" effect we can produce even more irregular torn edge using only documented functionality, but at the cost of sufficiently more lengthy code:

tornEdge2 = Module[{step = 10, if, n = 2 Total[ImageDimensions[img]], k = 0},
  if = Interpolation[
    Transpose[{Accumulate[Prepend[RandomInteger[{step, 2 step}, n], 0]], 
      RandomReal[1, n + 1]}],
    InterpolationOrder -> 1];
  ImageEffect[img, {"Frame", if[++k] &, 15, {Right, Bottom}}]]

image

Here is a simple approach allowing to obtain a semi-transparent shadow based on the new functionality. In addition I've added an option to add a darkened one-pixel wide boundary to the torned image:

shadowOffset = 10;
shadowBlur = 5;
shadowTone = .5;
boundaryLigntness = .4;

ImageCompose[
 SetAlphaChannel[ColorNegate@#, #] &@
  Blur[ImageMultiply[
    ImagePad[AlphaChannel[
      tornEdge], {{shadowOffset, shadowBlur/2}, {shadowBlur/2, shadowOffset}}], 
    shadowTone], shadowBlur], 
 ImagePad[ImageMultiply[tornEdge, 
   ColorNegate@
    ImageMultiply[MorphologicalPerimeter@AlphaChannel[tornEdge], boundaryLigntness]], {{0,
     shadowOffset + shadowBlur/2}, {shadowOffset + shadowBlur/2, 0}}]]

image

Any suggestions and comments are welcome!

POSTED BY: Alexey Popkov
6 Replies

Ok, I guess that we are really off-topic, but I yesterday created this function:

determineGender[str_] := 
 If[StringContainsQ[#[[2]], "error"], 
    "Name not found!", 
      {"gender" -> StringSplit[#[[-5 ;; -3]][[1]], {"<gender>", "</gender>"}][[2]],
      "male" -> StringSplit[#[[-5 ;; -3]][[2]], {"<male>", "</male>"}][[2]] , 
     "female" -> StringSplit[#[[-5 ;; -3]][[3]], {"<female>", "</female>"}][[2]]}] & 
      @(URLExecute["http://www.thomas-bayer.com/restnames/name.groovy?name=" <> str, "Data"])

Now

determineGender["Heike"]

gives:

{"gender" -> "unisex name (can be any gender)", "male" -> "true", "female" -> "true"}

and

determineGender["Szabolcs"]

gives

{"gender" -> "male first name", "male" -> "true", "female" -> "false"}

and

determineGender["Felicia"]

gives

{"gender" -> "female first name", "male" -> "false", "female" -> "true"}

Cheers,

Marco

POSTED BY: Marco Thiel

I also tried to use Mathematica for determining the gender of names automatically, and I was quite disappointed ...

enter image description here

Of course, there may be some weird people somewhere (the US is always a prime suspect) who are calling their sons Felicia, but it's quite absurd to return "male" by default. I don't like the WolframAlpha workaround because it does not even guarantee an interpretation as a name, and it is much too slow for practical work (e.g. a list of 100 names).


This is from the IGraph/M documentation:

enter image description here

POSTED BY: Szabolcs Horvát

enter image description here - Congratulations! This post is now a Staff Pick as distinguished by a badge on your profile! Thank you, keep it coming!

POSTED BY: Moderation Team

That put a smile on my face! Nice!

In Dutch it can be both genders, but more likely Female. Though in Frisian I think I've heard it more for men. In German indeed female as far as I know…

Cheers!

POSTED BY: Sander Huisman

Dear Sander,

that is an interesting computational problem that Mathematica can readily solve:

enter image description here

or

enter image description here

depending on your assumptions.

;-)

Unfortunately MMA does not appear to know the naming frequency:

enter image description here

Luckily W|A knows more:

WolframAlpha["heike", {{"CurrentEstimates:GivenNameData", 1}, "Content"}, 
InputAssumptions -> {"*C.heike-_*GivenName-", "*DPClash.GivenNameE.heike-_**Heike.UnitedStates.female--"}]

gives

enter image description here

WolframAlpha["heike", {{"BasicInformation:GivenNameData", 1}, "Content"}, 
 InputAssumptions -> {"*C.heike-_*GivenName-", "*DPClash.GivenNameE.heike-_**Heike.UnitedStates.male--"}]

enter image description here

So in the US it's more likely female.

Sorry, too much time to waste...

Marco

PS: I am aware that this in the US version of the name. In Germany it would also be female though.

POSTED BY: Marco Thiel

Heike is a female? I always read it as a male name, but can also be a female name now that I think about it…

POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract