Page 1 of 1

Is it possible to remove an object from image using IM

Posted: 2015-09-15T15:58:47-07:00
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! :)

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

Posted: 2015-09-15T19:54:09-07:00
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.