Page 1 of 1

Trim image based on thick line

Posted: 2015-09-21T14:17:15-07:00
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

Re: Trim image based on thick line

Posted: 2015-09-21T20:54:20-07:00
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.)