Not a complete, or rigorous solution, but an answer that may help you work it out. I choose to use ImageMagick which is installed on most Linux distros and is available for OSX and Windows - for free. There are Java bindings (that I don't use or know) called im4java
at Sourceforge. You can also do it in PHP, Perl, C++, C...
Anyway, at the command line, you can convert the first frame of your manuscript ([0]
) into Hue/Saturation/Lightness colorspace and discard the Saturation and Lightness so you are just left with the Hue, like this:
convert manuscript.gif[0] -colorspace hsl -separate -delete 1,2 -blur 0x3 -contrast-stretch 10% -threshold 50% hue.png
I then contrast stretch that and save it as hue.png
. It looks like this:

I can then take that image (hue.png
) and apply a "Connected Components Analysis" (also known as "Blob Analysis") on it, and discard all the small blobs - a blob is just a contiguous area.
convert hue.png \
-define connected-components:verbose=true \
-define connected-components:area-threshold=10000 \
-connected-components 8 -auto-level output.png
Objects (id: bounding-box centroid area mean-color):
6: 645x1033+50+78 372.4,594.0 663108 gray(0)
0: 851x1231+0+0 595.5,678.2 244279 gray(0)
2: 728x1123+9+36 376.7,604.3 140194 gray(255)
If I draw in the first, black box, in red like this:
convert manuscript.gif[0] -fill none -stroke red -strokewidth 5 -draw "rectangle 50,78 695,1100" result.png
I'll get this:

Or, I could crop it like this:
convert manuscript.gif[0] -crop 645x1033+50+78 result.png
and get this:

You may have to fiddle around a bit with the numbers and values but the general idea should be fairly applicable to your problem.