Blurring edges of images to match white background

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
tbayle
Posts: 5
Joined: 2016-11-21T13:18:09-07:00
Authentication code: 1151

Blurring edges of images to match white background

Post by tbayle »

I have thousands of furniture renderings of various sizes and JPG's, all shot on a white floor with shadows. I want to post these images on my web site which has a white page background. The problem is the edges of the images are not truly white because of the shadows. What I'm looking to do is feather the edges so the shadows fade to match the white background. I can add additional size to the images to accomplish this if necessary. I'm new to IM and not sure what commands to research to accomplish this goal. Any advice would be welcomed. Running on Windows platform, can script in DOS or Perl. Running 6.7.2-9 IM.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Blurring edges of images to match white background

Post by snibgo »

Your inputs are JPG, which have no transparency. I suppose you want the same for your outputs?

So, you have an object surrounded by roughly white. You want to change the background, so it fades to exactly white at the edges of the image. Is that correct?

There are many ways of doing this. For example, if you know there are always at least 20 pixels around the image, you could fade over that distance. Or you could find the boundary of the object, and gradually fade from there to the edges of the image.

Perhaps you can put a sample at somewhere like dropbox.com and paste the URL here.
snibgo's IM pages: im.snibgo.com
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Blurring edges of images to match white background

Post by GeeMack »

tbayle wrote:What I'm looking to do is feather the edges so the shadows fade to match the white background. I can add additional size to the images to accomplish this if necessary.
One way to accomplish this is to make a clone of your input image, clear it to transparent, add a thick white border, blur the border, then composite that clone with blurry border back onto the input image. Something like this will give the result you describe for a single input image...

Code: Select all

convert input.jpg -alpha on ^
   ( +clone -virtual-pixel none -distort affine "0,0 %[w],0" ^
   -virtual-pixel tile -bordercolor white -shave 30x30 -border 50x50 -blur 0x10 ) ^
   -gravity center -composite output.jpg
Maybe run something like that in a "for" loop to process a whole directory of JPGs. If used in a Windows BAT script, any single percent sign "%" will have to be made into a double "%%" of course.
tbayle
Posts: 5
Joined: 2016-11-21T13:18:09-07:00
Authentication code: 1151

Re: Blurring edges of images to match white background

Post by tbayle »

snibgo - thank you for the quick reply. Yes JPG as output is desired. Yes I want it to fade exactly to white at the edges of the image. We control the crop of the image so we can insure there's always sufficient space between the edge and actual object. Or additional border can be added if that is better/easier.

Here's a link to a dropbox folder with an example image.

https://www.dropbox.com/sh/4mibp578dd4s ... V9Nia?dl=0
Post Reply