Sketch Takes a long time to render

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?".
Post Reply
capncrunch9834
Posts: 13
Joined: 2012-06-11T07:39:40-07:00
Authentication code: 13

Sketch Takes a long time to render

Post by capncrunch9834 »

I wanted to post this here for discussion before considering this a bug.

I'm using version 6.7.7-6 2012-06-03 Q16 on WinXP SP3 w/4GB ram

When I use -sketch it takes quite a while to complete and it eats enormous amounts of CPU. I'm not doing anything special in the command line...

convert inputfile.jpg -colorspace gray -sketch 0x20+120 outputfile.jpg

...basically the same as the example in the docs. The input image is only 630x850 in size and not really all that special, but it takes around 1 full minute to complete! And Significantly Longer if I tweak the values of the sketch parameter.

Start: 6:12:15 PM
Stop: 6:13:17 PM :shock:

I use PaintShop Pro 9 and it's pencil sketch filter renders instantaneously.

Is this expected behavior of Imagemagick's convert?
Is this a bug?
Is this some sort of anomaly on my system?
Does anyone else have the same results?

...............................................................

* ALSO...

What do the parameter values of -sketch represent?

0x20+120
(Val1?)x(Val2?)+(Angle)

I realize that val1 = radius and val2 = sigma, but what I'm wondering is what would those equate to in human terms? (e.g.., Thickness? Stroke? etc.)

Thank you! :)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Sketch Takes a long time to render

Post by fmw42 »

radiusxsigma are the arguments. normally one just leaves radius=0 and sets the sigma so that the guassian rolls off to near zero automatically. that is the radius is set automatically from the sigma and is approx radius=3xsigma.

The radius is the half-width of the gaussian window, the sigma is how fast or slow it rolls off, the larger it is the slower it rolls off so that the radius needs to be bigger. you do not want a window that does not let the gaussian roll off to near zero, normally.

A 20 pixel sigma will mean a gaussian window of 120x120 for the convolution and thus can be slow.

On my Mac OSX IM 6.7.8.2 Q16 with the 640x480 logo: image

time convert logo: -colorspace gray -sketch 0x20+120 null:

real 0m23.568s
user 0m22.602s
sys 0m0.052s
capncrunch9834
Posts: 13
Joined: 2012-06-11T07:39:40-07:00
Authentication code: 13

Re: Sketch Takes a long time to render

Post by capncrunch9834 »

Thanks Fred,

Hey... are you tellin' me that executed in 40 milliseconds??? Well then What On Earth would cause it to take so long on my system? (Oh, I can just hear the Mac vs. PC retort on it's way. LOL) Seriously though... There are a couple convert commands I've seen do this while others complete instantly, relatively speaking. It's common sense that some processes would take longer than others due to the computations taking place for a given rendering.... but a whole minute or longer?!? Why? Has anyone else encountered this?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Sketch Takes a long time to render

Post by fmw42 »

capncrunch9834 wrote:Thanks Fred,

Hey... are you tellin' me that executed in 40 milliseconds??? Well then What On Earth would cause it to take so long on my system? (Oh, I can just hear the Mac vs. PC retort on it's way. LOL) Seriously though... There are a couple convert commands I've seen do this while others complete instantly, relatively speaking. It's common sense that some processes would take longer than others due to the computations taking place for a given rendering.... but a whole minute or longer?!? Why? Has anyone else encountered this?
24 seconds not millisec
capncrunch9834
Posts: 13
Joined: 2012-06-11T07:39:40-07:00
Authentication code: 13

Re: Sketch Takes a long time to render

Post by capncrunch9834 »

Oh... My bad. I totally read it wrong. Sorry.

That makes more sense. I know my system is somewhat antiquated so that would account for the 40-something second difference. But still, why would it take 24 seconds on even your system (which is undoubtedly faster).

I'd be interested to hear from other users -- what's your experience with -sketch? How long does it take on your system?

And still the unanswered question: Is this a bug? Or is this the expected behavior of convert's sketch?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Sketch Takes a long time to render

Post by fmw42 »

As I explained above, I think IM cannot process it faster as it is not optimized for speed but more for flexibility. You are dealing with a very large convolution window

A 20 pixel sigma will mean a gaussian window of 120x120 for the convolution and thus can be slow, especially if it is doing a 2D gaussian blur (via -gaussian-blur) rather than a pair of 1D separable convolutions (via -blur).

see
http://www.imagemagick.org/script/comma ... ssian-blur
http://www.imagemagick.org/script/comma ... s.php#blur

I think speed will depend upon your processor and RAM size.

My opinion, only. Hope you get confirmation one way or the other from other users.
capncrunch9834
Posts: 13
Joined: 2012-06-11T07:39:40-07:00
Authentication code: 13

Re: Sketch Takes a long time to render

Post by capncrunch9834 »

fmw42 wrote:As I explained above, I think IM cannot process it faster as it is not optimized for speed but more for flexibility.
As told, PaintShop Pro, (Photoshop, etc.,) performs it's pencil drawing effect instantly ... and it's pretty flexible. It would seem that a dedicated sketch command (and a couple of the others that are just as slow) could perform the task "just a bit" faster.
fmw42 wrote:Hope you get confirmation one way or the other from other users.
Yeah, that's what I'm hoping for. Opinions & discussion. ...anyone? ...anyone at all??
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Sketch Takes a long time to render

Post by Bonzo »

I converted a jpg using your code capncrunch9834 and it took 22 seconds on a Vista PC quad core - image 533x800.
Post Reply