Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
194 views
in Technique[技术] by (71.8m points)

ImageMagick get image side only - not a edge detection problem

This is not a finding edge problem but I am trying to find the background color of the image, in order to find it, I am trying to get the edge of the image and guess the best color.

In order to do so, I want to remove the center of the image and just get image like a frame with transparent center.

Is it possible through ImageMagick?

For example

enter image description here

If want

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try this tested on Windows with IM V7:

magick "input.png" ( -size 200x200 xc:black ) -gravity center -compose DstOut -composite "output.png"

Takes the original photo, creates a rectangular mask, places it over the middle of the image and "cuts" out the rectangle

If the input is not a png ( for instance a jpg ) you will have to do some work setting the alpha channel

EDIT: This seems to work for both jpg and png images

magick "input.png" -alpha on ( -size 200x200 xc:black ) -gravity center -compose DstOut -composite "output.png"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...