How to extract-rotate-place image?
Posted: 2019-01-24T13:17:58-07:00
Hi folks, I have what "should" be straightforward -- extract an image from a mostly-grey background, and place it in a new background, and over the past couple days everything I've tried (from snippets on the interwebz) has failed for various reasons. Help, pls!
In the interim I'm reading through https://www.imagemagick.org/Usage/masking/#bg_remove, but know I need more thorough and systematic education than reading sections piecemeal. Likewise, http://www.fmwconcepts.com/imagemagick/ ... /index.php should help, but again my education lags.
(This is a progression of https://imagemagick.org/discourse-serve ... =1&t=35370, which direction I've abandoned for it not producing good-enough results)
ImageMagic version: 7.07 32-bit on Windows 7
All input images are jpg: mostly-grey background, w/ some lighting variation, w/ a mostly-circular disc in the approximate center of the image (disc may not be perfectly circular due to camera angle, etc). The background for each image is very similar; the disc size/position are also similar, but color and contents vary.
My goal is to extract the disc from each image, rotate it by some angle, and place it into a new background w/ -gravity center
Input and output samples are below.
In each case I created the output sample, using Affinity Photo 1.6.5 (the same steps work in Photoshop 5.5, and Gimp 2.10 though selection-tool settings differ); steps are as follows:
-- open input image
-- "flood select" the grey background by using the magic-wand tool and clicking on a spot approx 1/2 the distance from the edge of the disc to the top-left corner; magic-wand settings are "tolerance (aka -fuzz) 20%, contiguous"
-- invert the selection; this selects the disc
-- "copy" (CTRL-C) the selection (i.e. disc)
-- open background image
-- paste (CTRL-V) disc into background image
-- rotate disc by X degrees
-- save output image
Sample images:
input: b1 https://pasteboard.co/HXYryuw.jpg; output b1o https://pasteboard.co/HXYrJss.jpg
input: g1 https://pasteboard.co/HXYrSyr.jpg; output g1o https://pasteboard.co/HXYrZYT.jpg
input: r1 https://pasteboard.co/HXYs7Ni.jpg; output r1o https://pasteboard.co/HXYshJ4.jpg
background: bg https://pasteboard.co/HXYspHC3.jpg
All steps performed in 1 commandline would be great, but multi-step + temp images is OK.
And while a run-able solution would be wonderful, even just guidance/references on examples I could modify/study would be much appreciated.
Many thanks!
In the interim I'm reading through https://www.imagemagick.org/Usage/masking/#bg_remove, but know I need more thorough and systematic education than reading sections piecemeal. Likewise, http://www.fmwconcepts.com/imagemagick/ ... /index.php should help, but again my education lags.
(This is a progression of https://imagemagick.org/discourse-serve ... =1&t=35370, which direction I've abandoned for it not producing good-enough results)
ImageMagic version: 7.07 32-bit on Windows 7
All input images are jpg: mostly-grey background, w/ some lighting variation, w/ a mostly-circular disc in the approximate center of the image (disc may not be perfectly circular due to camera angle, etc). The background for each image is very similar; the disc size/position are also similar, but color and contents vary.
My goal is to extract the disc from each image, rotate it by some angle, and place it into a new background w/ -gravity center
Input and output samples are below.
In each case I created the output sample, using Affinity Photo 1.6.5 (the same steps work in Photoshop 5.5, and Gimp 2.10 though selection-tool settings differ); steps are as follows:
-- open input image
-- "flood select" the grey background by using the magic-wand tool and clicking on a spot approx 1/2 the distance from the edge of the disc to the top-left corner; magic-wand settings are "tolerance (aka -fuzz) 20%, contiguous"
-- invert the selection; this selects the disc
-- "copy" (CTRL-C) the selection (i.e. disc)
-- open background image
-- paste (CTRL-V) disc into background image
-- rotate disc by X degrees
-- save output image
Sample images:
input: b1 https://pasteboard.co/HXYryuw.jpg; output b1o https://pasteboard.co/HXYrJss.jpg
input: g1 https://pasteboard.co/HXYrSyr.jpg; output g1o https://pasteboard.co/HXYrZYT.jpg
input: r1 https://pasteboard.co/HXYs7Ni.jpg; output r1o https://pasteboard.co/HXYshJ4.jpg
background: bg https://pasteboard.co/HXYspHC3.jpg
All steps performed in 1 commandline would be great, but multi-step + temp images is OK.
And while a run-able solution would be wonderful, even just guidance/references on examples I could modify/study would be much appreciated.
Many thanks!