Trim image based on thick line

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
gvandyk
Posts: 15
Joined: 2015-09-08T12:40:32-07:00
Authentication code: 1151

Trim image based on thick line

Post by gvandyk »

HI

I have the following image with a thick black shadow line running through the image near the top. I would like to trim the top part of the image off including the dark shadow line. I need to be able to do this automatically.

https://www.dropbox.com/s/ow0ntk3is4vwf ... 2.JPG?dl=0
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Trim image based on thick line

Post by snibgo »

I would do it like this. Windows BAT syntax:

Code: Select all

set SRC=IMG_0102.JPG

convert ^
  %SRC% ^
  -threshold 7%% ^
  -scale "1x^!" ^
  -auto-level ^
  -fuzz 90%% ^
  -fill Black ^
  -draw "color 0,0 floodfill" ^
  -fuzz 0 ^
  -process onewhite ^
  NULL:

convert ^
  %SRC% ^
  -crop +0+393 +repage ^
  r.png
The output from "-process onewhite" is "onewhite: 0,393". A script would grab the second number (393), and use that in the crop.

(If you don't have onewhite, a sub-image search would be fast, as the image is only 1 pixel wide.)
snibgo's IM pages: im.snibgo.com
Post Reply