How to "Smart Sharpen," adaptive-sharpen not working

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?".
Maxwell

How to "Smart Sharpen," adaptive-sharpen not working

Postby Maxwell » 2007-12-08T03:41:01-07:00

Hello,

adaptive-sharpen is not working so...

Can someone help me with using ImageMagick to follow the Smart Sharpening workflow. http://www.gimpguru.org/Tutorials/SmartSharpening2/

I'd like to be able to batch sharpen my photos, then just work on the ones that need more attention.

thanks,
Max

ps. Yes, I asked about adaptive-sharpen in bugs. I thought more people might see it here.

Bonzo
Posts: 2256
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England
Contact:

Re: How to "Smart Sharpen," adaptive-sharpen not working

Postby Bonzo » 2007-12-08T05:00:58-07:00

Is there anything on Freds site that whould do what you want ?
http://www.fmwconcepts.com/imagemagick/index.php

Bonzo
Posts: 2256
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England
Contact:

Re: How to "Smart Sharpen," adaptive-sharpen not working

Postby Bonzo » 2007-12-08T10:42:06-07:00

Just had a very quick go at this; the output looks better but that may just be the unsharp. Needs quite a bit of work still !!!

Code: Select all

exec("convert image-original.jpg ( +clone -edge .09 -colorspace gray +dither -colors 2 -normalize -negate -gaussian-blur .5 -fuzz 30% -transparent white ) -composite -unsharp 1x2 final2.png");

Maxwell

Re: How to "Smart Sharpen," adaptive-sharpen not working

Postby Maxwell » 2007-12-08T13:13:04-07:00

Thanks for the tips.

I tried sharp from here:
Bonzo wrote:Is there anything on Freds site that whould do what you want ?
http://www.fmwconcepts.com/imagemagick/index.php

but it took almost 20 minutes for an 800x600 image! and my computer's not that old (dual Opteron, 1.5Gb ram)!

Then I tried your command, but it erred out with

Code: Select all

bash: syntax error near unexpected token `"convert N775-02028.JPG ( +clone -edge .09 -colorspace gray +dither -colors 2 -normalize -negate -gaussian-blur .5 -fuzz 30% -transparent white ) -composite -unsharp 1x2 N775-02028-sharp.JPG"'

I tried csh, just in case, but it gave me "Badly placed ()'s."

Any ideas? I'm trying to work it out, but I haven't tried any complex ImageMagick commands yet.

Bonzo
Posts: 2256
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England
Contact:

Re: How to "Smart Sharpen," adaptive-sharpen not working

Postby Bonzo » 2007-12-09T02:10:33-07:00

I have only tried small images with Freds code so I didn't know they can take that long.

I am not sure about your error, I tried it on my localhost on a windows machine. You could try replacing the ( ) with \( \)

You could also split up the code and create a tempory image; this is how I did it at first so I could see what effect some of the comands were having.

Code: Select all

convert N775-02028.JPG -edge .09 -colorspace gray +dither -colors 2 -normalize -negate -gaussian-blur .5 -fuzz 30% -transparent white temp.png

composite temp.png N775-02028.JPG  -unsharp 1x2 output.jpg

User avatar
anthony
Posts: 8736
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia
Contact:

Re: How to "Smart Sharpen," adaptive-sharpen not working

Postby anthony » 2007-12-11T18:22:32-07:00

Note that 'gray' is not the same as luminosity. You can extract the luminosity of an image by changing the images colorspace and separating the channels.

Actually just changing the images colorspace and restricting operations to just one channel will also work!

See IM Examples, Channels page

Actually the sub-page where they use the same edge mask to both despeckle/blur non edges and sharpen edges, may work a lot better in IM. Especially now that the three image masked composition works with grayscale (fixed IM v6.3.4-11)
http://imagemagick.org/Usage/compose/#mask

Remember unsharp is in actual fact a extrapolated blend of a blured image with the original http://imagemagick.org/Usage/compose/#blend_use
It may be that rather than a simple single value blend, we could make a extroplated blend that can both blur and unshapr an image on a pixel by pixel bases under the control of the pre-prepared edge mask.

It may turn out simpler than expected or not, and a proof of concept may be posible using -fx or pixel iterated PerlMagick, or just as described above using a masked composition. Publish your findings here!!!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/

Maxwell

Re: How to "Smart Sharpen," adaptive-sharpen not working

Postby Maxwell » 2007-12-16T08:08:08-07:00

Thanks for the suggestions.

I've started by creating a softened edge mask then using it to composite an Unsharp'd version of the photo over the original. I haven't tried to use just the luminosity channel yet.

Code: Select all

#!/bin/bash

for x in "${@}"
do

NAME=${x}
NEWNAME=`basename "${NAME%.tif}_sharp.tif"`
     echo -e "Sharpening ${x} into $NEWNAME\n\nEdge detect:"
convert -monitor -edge 2 $NAME orig_edge.png
     echo -e "\nUnsharp original:"
convert -monitor -unsharp 3x1+2+.02 $NAME temp_sharp.png
     echo -e "\nSoftening edge:"
convert -monitor -threshold 40% -blur 2 -threshold 30% -blur 2 orig_edge.png soft_edge.png
     echo -e "\nCompositing:"
composite -monitor temp_sharp.png $NAME soft_edge.png $NEWNAME

done

rm orig_edge.png
rm soft_edge.png
rm temp_sharp.png


-Max

User avatar
fmw42
Posts: 15127
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA
Contact:

Re: How to "Smart Sharpen," adaptive-sharpen not working

Postby fmw42 » 2007-12-17T17:59:36-07:00

I played with -adaptive-sharpen and found that it does nothing if you specify radiusxsigma as 0xanyvalue (e.g. 0x4), it does little if one specifies radius alone (e.g. 4), but does work if one specifies radiusxsigma as radius=3*sigma and a value for sigma (e.g. 12x4). With the other radiusxsigma functions (blur and gaussian-blur), if one specifies radius=0, it supporsedly computes the radius from the sigma (typically 3*sigma for radius), but this does not seem to be working for adaptive-sharpen (or not well?). Use Anthony's flicker_cmp script to alternately display two or more images in rapid succession to compare the changes.

Maxwell

Re: How to "Smart Sharpen," adaptive-sharpen not working

Postby Maxwell » 2007-12-17T18:53:51-07:00

fmw42,

Even with large values, -adaptive-sharpen does not work for me. I tried 12x4, 10x2 and 10x5. After each one I visually checked them and then ran compare on them... but, no differences.

I am currently running 6.3.5.10. I have not tried the newest version yet--I am trying to stay with RPMs for ease of upgrading. I posted this in Bugs, but no replies, and no mention of it being fixed in the change logs.

User avatar
magick
Site Admin
Posts: 9706
Joined: 2003-05-31T11:32:55-07:00
Contact:

Re: How to "Smart Sharpen," adaptive-sharpen not working

Postby magick » 2007-12-17T20:28:47-07:00

Investigating this problem is on our TO-DO list, however, so is 300 other problems. Be patient. We'll get to it and report back here when we have a solution.

User avatar
fmw42
Posts: 15127
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA
Contact:

Re: How to "Smart Sharpen," adaptive-sharpen not working

Postby fmw42 » 2007-12-18T12:09:02-07:00

Maxwell,

My testing was on IM 6.3.6.4. I have not checked on 6.3.7.x.

If you want to post me your test image somewhere and link it here, I will run it on my system and post the results.

Fred

ccreekin
Posts: 5
Joined: 2010-01-01T15:44:53-07:00
Authentication code: 8675309

Re: How to "Smart Sharpen," adaptive-sharpen not working

Postby ccreekin » 2010-01-01T16:14:05-07:00

Adaptive sharpening does seem to work in version 6.3.7 (build 06/04/09).
Although many other numbers have an effect, I like 2x3 for 25% thumbnails:

convert -filter Lanczos -resize 25% -adaptive-sharpen 2x3 -quality 95 -sampling-factor 2x1 ...

A radius(?) higher than 2 looks oversharpened to me, and a sigma(?) higher than 3
has little if any visible effect and takes longer to process. I had been using USM:

convert -filter Lanczos -resize 25% -unsharp 1x3+1+.09 -quality 95 -sampling-factor 2x1

The -adaptive-sharpen option takes less time to process, creates smaller thumbnails,
and has a slightly milder effect with much less haloing.

User avatar
anthony
Posts: 8736
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia
Contact:

Re: How to "Smart Sharpen," adaptive-sharpen not working

Postby anthony » 2010-01-02T01:39:56-07:00

Radius is only a limiter argument. It rerally should have no effect. Just use 0 normally.

Sigma is the sharphing control, and number should be in the range from 0.1 (weak sharpen)to 2.0 (strong sharpen) The other numbers are suposed to control what gets sharpened. EG edges, not wrinkles. But I do now know what are good numbers. I think a percentage should be used to remove the effect of your comnpilation 'quality'.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/

ccreekin
Posts: 5
Joined: 2010-01-01T15:44:53-07:00
Authentication code: 8675309

Re: How to "Smart Sharpen," adaptive-sharpen not working

Postby ccreekin » 2010-01-03T19:57:43-07:00

Anthony, thanks for your reply and (previously online) command examples! You are right that radius=0 works better than what I was using before. I experimented with all the one-place decimal numbers 0x1 and below. With 25% downsampling, -adaptive-sharpen 0x.6 seems to strike a nice balance between sharpness and small file size. But even 0x.2 is better than 2x3 that I posted about before.

I didn't understand your comment about quality. That is a JPEG encoding option. Also radius does have an effect, although not the effect that I expected. I should take a look at the source code.

User avatar
fmw42
Posts: 15127
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA
Contact:

Re: How to "Smart Sharpen," adaptive-sharpen not working

Postby fmw42 » 2010-01-03T20:12:47-07:00

Have you tried my gaussedge or sharpedge scripts? Curious how they compare to adaptive-sharpen!


Return to “Users”

Who is online

Users browsing this forum: Yahoo [Bot] and 6 guests