Smart Sharpening in Imagemagick

So, I’ve found that the Smart Sharpening workflow described here can give really stellar results. But I’m lazy, and was interested in a way that I could adjust images without having to open them in a graphical environment, and preferably do a bunch at once. I essentially converted the steps described by gimpguru into imagemagick and ended up with something that works. I’m still testing a few different ideas, but I find it’s working reasonably well at the moment (you can judge for yourself on the basis of examples, though the flickr images will give you a better idea). But in the spirit of sharing… you can find it here.

Timings: 10 MP image, about 35 seconds
Note this will avoid name collisions presently, so if you have a 2, 4 or 8 core cpu, and you use (ls *.jpg|xargs -n 1 -P # you can get a 2, 4 or 8x speedup, or 20, 10 or 5 seconds per image. This is really not a lot of time, and trivial compared to the amount of time you could expect to spend in the gimp doing the same thing.

Apparently someone has already tried to implement this in the gimp. This would be a nice way to try a bunch of different parameters, unfortunately it does not have a preview (and that would be very hard to do), and parameters would not be a perfect match from that one to this one, as I use a different edge detection method. And I don’t believe I can use the gimp edge detect method without quite an investment. I’ll investigate though.

Some examples: These are crops from three larger images (full size available here), the images are the original, the final and the mask generated by the script used for sharpening,.


7 Responses to “Smart Sharpening in Imagemagick”

  1. darethehair Says:

    Interesting! However, when I try it myself the images end up much darker than the originals. Has the behavior of this app (or the underlying pieces) changed since this article was written?

    • Joseph Says:

      If I remember right, I did this by blending the original & the sharpened using a mask. Which would mean it shouldn’t affect perceived brightness. Can you throw up an example file somewhere and I’ll see if I can’t take a look.

      • darethehair Says:

        For a good comparison, I used your ‘Orchid’ photo from Flickr to experiment with, and here is where I arbitrarily uploaded the final result:

  2. darethehair Says:

    Any more vibes on this issue? It would be great to have a CLI-based image sharpening utility that I could rely upon :)

    • Joseph Says:

      Well I finally got around to starting to look at this today. Rebuilt the current version of imagemagick, and have started to reconstruct this. I think I’ve found an edge detection that I’m pretty ok with, take a look if you’re interested:

      time convert $1 -blur 0x4 blurred.ppm
      time convert $1 -blur 0x3 -define convolve:scale=’-1!’ -morphology Convolve Laplacian:0 -colorspace Gray -contrast-stretch 3% laplace_edges.ppm
      time convert $1 -unsharp 9×3+1.5+0.0 sharped.ppm

      I should have the whole thing done pretty soon and I’ll post it on github with a link.

    • Joseph Says:

      darethehair, You can take a look at it here:
      I think this is actually simpler than the last one I had. It has lots of free parameters, but it should be possible to find one set which works fairly well for the vast majority of images. Sorry I was so slow in getting around to this.

      • darethehair Says:

        Thanks for doing this! If you have time sometime, it would be interesting to find out more on tweaking those parameters you alluded to :)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: