Is it possible to remove an object from image using IM

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
Don
Posts: 47
Joined: 2013-05-09T14:10:43-07:00
Authentication code: 6789

Is it possible to remove an object from image using IM

Post by Don »

Hello there,

I was wondering if it is possible to remove a certain object from an image, for example a car, or a ball and save that output to an image?

For example, is it possible to extract just the car from this image: https://upload.wikimedia.org/wikipedia/ ... rvette.jpg

Usually people load the image in an image editing program like photoshop to outline the car and extract that way but I was wondering if this was possible with imagemagick.

Thank you in advance! :)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Is it possible to remove an object from image using IM

Post by fmw42 »

You could get most of the red part of the car using

Code: Select all

convert 2014_Chevrolet_Corvette.jpg -fuzz 20% -fill none +opaque "rgb(238,57,53" result.png
And then follow it with -connected-components to remove every red region that is not the largest in area. You could also get the black by similar means, but then you would need to remove the Corvette name and other black areas that are not part of the wheels. With a lot of work, I suppose you could get most of it.

But to get it all, you would most likely need to trace the outline by hand or use PS or GIMP outline tool to try snapping to the closest regions.

I do not know of any simple and reliable automatic means in IM to do that. For simpler, cleaner objects in consistent background color, the above command will typically work. But for complex images with lots of varying colors, this becomes much more difficult, especially since IM is mostly command line driven and has a very simple GUI. So there is no interactive snap-to tool.
Post Reply