Page 1 of 1

Getting a perimeter and filling in the rest

Posted: 2019-10-12T06:29:10-07:00
by dcotto
trying to make a mask out of this image. How would one go about creating it

my assumption would be to use a threshold where the white perimeter is solid white.
if i get the perimeter to be continuous solid white, how would i tell IM to close/fill the inside?

if someone knows a better approach please let me know thanks

below is the image
https://ibb.co/QYWHkmC

Re: Getting a perimeter and filling in the rest

Posted: 2019-10-12T06:46:24-07:00
by snibgo
What version of IM, on what platform?

What mask do you want? The central rectangle, or that plus the enclosing black area, or that plus the enclosing white area, or what?

Re: Getting a perimeter and filling in the rest

Posted: 2019-10-12T08:01:06-07:00
by dcotto
i want to mask the whole ipad, starting from the white outer portion. so in the end it should look like in the image below but better (the image still has some black leaking in the white areas

https://ibb.co/M6v2swB

Re: Getting a perimeter and filling in the rest

Posted: 2019-10-12T08:34:44-07:00
by snibgo
Your required output has a wide black margin on the right. I don't know where that has come from. Ignoring that, we can floodfill to isolate the outer black border. That gives a rough edge we can smooth with a blur. The blur has to be large enough to help, but not so large that it damages the curved corners. We do this three times for an almost perfect result. Windows BAT syntax.

Code: Select all

magick ^
  i-Pad-threshold.png ^
  -strip ^
  -fill Red -draw "color 0,0 floodfill" ^
  -fill White +opaque red ^
  -fill Black +opaque White ^
  ( +clone -channel RGB -blur 0x10 -threshold 50%% +channel ) ^
  -compose Lighten -composite ^
  ( +clone -channel RGB -blur 0x10 -threshold 50%% +channel ) ^
  -compose Lighten -composite ^
  ( +clone -channel RGB -blur 0x10 -threshold 50%% +channel ) ^
  -compose Lighten -composite ^
  x.png