Remove background using special markers

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
vesa
Posts: 4
Joined: 2019-02-15T14:45:12-07:00
Authentication code: 1152

Remove background using special markers

Post by vesa »

Greetings,

I would like to remove the background automatically from photos. The object is a table that can move and can have some random objects on it. The background is a wooden floor that can have some random objects. I was wondering if I can mark the corners of the table with some special markers like QR codes or color dots and then remove everything outside the quadrilateral formed by the markers.

Cheers,
Vesa
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Remove background using special markers

Post by fmw42 »

Measure the top left corner x,y and width and height of the region you want to keep and then use -crop WxH+X+Y +repage. See https://imagemagick.org/Usage/crop/#crop

_____________________

Please, always provide your IM version and platform when asking questions, since syntax may differ.

Also provide your exact command line and your images, if possible.

See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at http://www.imagemagick.org/discourse-se ... f=1&t=9620

If using Imagemagick 7, then see http://imagemagick.org/script/porting.php#cli


For novices, see

http://www.imagemagick.org/discourse-se ... f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
https://github.com/ImageMagick/usage-markdown
https://imagemagick.org/script/porting.php#cli
vesa
Posts: 4
Joined: 2019-02-15T14:45:12-07:00
Authentication code: 1152

Re: Remove background using special markers

Post by vesa »

That doesn't really help since there shouldn't be any manual interaction. Also the area is not a rectangle.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Remove background using special markers

Post by fmw42 »

You mentioned putting dots on the image. That means you have manual interaction. Please clarify or show an example image.

With 4 points, you can draw a polygon (quadrilateral) from the coordinates and then mask out the image.

If the dots are uniquely colored, then one could extract, in principle, the coordinates of the centers of the dots.
vesa
Posts: 4
Joined: 2019-02-15T14:45:12-07:00
Authentication code: 1152

Re: Remove background using special markers

Post by vesa »

The dots would be physical dots, not marked afterwards to the image. The idea is that with some physical markers a software could automatically determine these positions and crop accordingly without any human interaction.
vesa
Posts: 4
Joined: 2019-02-15T14:45:12-07:00
Authentication code: 1152

Re: Remove background using special markers

Post by vesa »

I think I got it. I'll put for example green dots on red background and use compare + maxima to determine the coordinates. Let's see how it works.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Remove background using special markers

Post by snibgo »

This is like motion capture in the movies: targets are stuck to actors, the camera captures the actions, and computers replace the actors with animated figures.

The targets can be something like these (Windows syntax):

Code: Select all

magick ^
  -size 100x100 ^
  xc:Black xc:White +append ^
  ( +clone -flop ) ^
  -append +repage ^
  mcTarget1.png
Image

Code: Select all

magick ^
  -size 200x200 xc:Black ^
  -fill White -draw "circle 100,100 100,200" ^
  -fill Black -draw "circle 100,100 100,180" ^
  -fill White -draw "circle 100,100 100,160" ^
  -fill Black -draw "circle 100,100 100,140" ^
  -fill White -draw "circle 100,100 100,120" ^
  mcTarget2.png
Image
The circular target is better when you don't care about the orientation.
snibgo's IM pages: im.snibgo.com
Post Reply