5
$\begingroup$

I would like to "frame" a photo with a rectangular blur or gradient. Here is an example from the web that was not made using Mathematica. (Of course, anything is possible; I suppose that this example from the web may have been made using Mathematica, but I'm guessing that it was not.)

Regular version:

regular

Blurred frame version:

blurred

My question is, given a normal, unframed photo image, how can I accomplish this sort of blurred/gradient photo frame in Mathematica? Are there any relatively straightforward ways of accomplishing this sort of effect? (The result doesn't have to be at all exactly like the example above; I'm just using the above example to illustrate generally what I would like.) It would be preferable if it could be accomplished using Mathematica 8 or 9, but if Mathematica 10 is necessary, that is fine, too.

Suppose that I import the regular image in a variable regular:

regular = Import["regular.jpg"]

regular

I can blur the entire image using Blur:

Blur[regular]

blurFull

I can also introduce a temporarily solid frame (i.e., a solid band of white -- or, here, yellow, so that you can see it against this white page) using ImagePad:

solidFrame = ImagePad[regular, 10, Yellow]

solidFrame

Then I can blur the result with Blur:

Blur[solidFrame]

blurredYellow

Or, with a White ImagePad:

blurredWhite2

But, again, of course, the interior of the image becomes blurred as well. So I need some way to delineate the "frame area" of the image from the "interior" of the image. Is there any way to do this? Thanks so much for your time.

$\endgroup$
  • 6
    $\begingroup$ I don't think what you want is really a blur but a white frame with an alpha gradient. $\endgroup$ – Martin Ender Jan 4 '15 at 18:54
11
$\begingroup$
pic = Import["http://i.stack.imgur.com/TPxVj.png"]

V11.2+

As of V11.2 it is directly supported by ImageEffect:

ImageEffect[pic, "FadedFrame"]

Pre V11.2

alpha = Composition[
   GaussianFilter[#, 10] &,
   Image,
   BoxMatrix[#/2 - 5, #] &,
   Reverse
][
   ImageDimensions@pic
] 

SetAlphaChannel[pic, alpha]

enter image description here

$\endgroup$
  • 1
    $\begingroup$ there is a superfluous comma inside Composition body. the code doesn't work in version 10 because of that comma. please correct it, as noone else can do it: "edit must be at least 6 characters" $\endgroup$ – Dan Oak Apr 19 '16 at 16:32
  • $\begingroup$ @DanyloDubinin Thanks :) Deleted. $\endgroup$ – Kuba Apr 19 '16 at 16:36
4
$\begingroup$

The above is an excellent answer to the specific question posed. Reading the documentation info on ImageApply[] and "Masking" provides another mechanism for performing image processing operations selectively on image regions.

Complex masks for ImageApply[] can be generated offline and Imported as mask images using software such as GIMP or Photoshop, giving some artistic freedom to the design of masks.

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.