Invert region

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
figgis
Posts: 4
Joined: 2013-11-16T13:42:17-07:00
Authentication code: 6789

Invert region

Post by figgis »

I'm trying to blur a picture except a region in the middle. Something like this:

Image

I only see options to do the opposite, i.e. blur a region and I need the inverse.
Can it be done?

Right now I'm trying to solve this by croping out the region in the middle, blurring the complete image and then merging the cropped region on top of the blurred image; quite messy!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Invert region

Post by snibgo »

The obvious way would be to use "+region", which would be like "-region" but allow changes outside the rectangle. Sadly, there is no "+region".

Instead, we can compose a blurred version over a non-blurred version, using a mask that is a black rectangle on a white background. In this Windows script, b.png is a test image.

Code: Select all

%IM%convert -size 600x400 label:snibgo b.png

%IM%convert ^
  b.png ^
  ( +clone -blur 0x5 ) ^
  ( +clone -fill White -colorize 100 -fill Black -draw "rectangle 100,100,499,149" ) ^
  -composite ^
  bz.png
snibgo's IM pages: im.snibgo.com
figgis
Posts: 4
Joined: 2013-11-16T13:42:17-07:00
Authentication code: 6789

Re: Invert region

Post by figgis »

Haven't used windows for a decade but I'll try this tonight when my kids have fallen asleep :-)

Thanks!
Post Reply