I have implemented the last major feature missing in my
content-aware image resizer based on seam carving/insertion,
image enlargement via seam insertion. It took a whole 50 lines of OCaml code
which you can find below. My program now does everything the Gimp
LiquidRescale plug-in does, so a direct comparison can be done.
Looking at the rendering part only, I have needed under 500 lines of OCaml code
*1.
LiquidRescale's render.{c,h} comprise over 2100 lines of code. On my box,
seam carving and insertion in OCaml are both over 5 times faster than LiquidRescale's (remember I'm not comparing my code to a Python script; LiquidRescale is written in C).
Here's a tiny sample of what seam insertion is about. Given this image
if you just rescale it, it will look like this
The image can be enlarged while preserving the aspect ratios of the salient
objects using seam insertion:
Seam insertion is very easy once you have seam carving,
since it can be trivially built atop it as reflected also by the code, where
seam insertion is performed by a functor which abstracts over the seam carving
module:
module Make(Carving: Seamcarving.S) = struct ... end