-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
1274 lines (1236 loc) · 97.6 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="generator" content="HTML Tidy for HTML5 for Linux version 5.8.0">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../assets/usage.css">
<title>Bluring and Sharpening -- ImageMagick Examples</title>
<link rel="icon" href="../img_www/favicon.ico" type="image/x-icon">
<link rel="shortcut" href="../img_www/favicon.ico" type="image/x-icon">
<link rel="canonical" href="https://imagemagick.org/Usage/blur/">
</head>
<body>
<main class="container">
<div class="magick-template">
<div class="magick-header">
<h1>ImageMagick Examples --<br>
<img src="../img_www/space.gif" width="50" height="1"> Blurring and Sharpening Images</h1>
<div>
<dl>
<dt><b>Index</b></dt>
<dt>
<a href="../"><img src="../img_www/granitesm_left.gif" border="0" width="15" height="15"> ImageMagick Examples Preface and Index</a>
</dt>
<dd>
<a href="#blur"><img src="../img_www/granitesm_right.gif" border="0" width="15" height="15"> Blurring Images</a>
<ul>
<li>
<a href="#blur_args">Blur/Gaussian Arguments</a>
</li>
<li>
<a href="#blur_channel">Blur uses the Channel Setting</a>
</li>
<li>
<a href="#blur_internals">Blur Internals</a>
</li>
<li>
<a href="#blur_gaussian">Blur vs Gaussian Blur Operators</a>
</li>
<li>
<a href="#blur_resize">Large Blurs using resize</a>
</li>
</ul>
</dd>
<dd>
<a href="#sharpen"><img src="../img_www/granitesm_right.gif" border="0" width="15" height="15"> Sharpening Images</a> (Under Construction)
</dd>
<dd>
<a href="#shadow"><img src="../img_www/granitesm_right.gif" border="0" width="15" height="15"> Generating Shadows</a>
<ul>
<li>
<a href="#shadow_shape">Shaped Shadows</a>
</li>
<li>
<a href="#shadow_offset">Shadow Offset Problem</a>
</li>
<li>
<a href="#shadow_composite">Shadow and Composite</a>
</li>
<li>
<a href="#shadow_outline">Shadow Outlines</a>
</li>
<li>
<a href="#shadow_montage">Shadow in the Montage Command</a>
</li>
<li>
<a href="#shadow_internals">Shadow Internals</a>
</li>
</ul>
</dd>
<dd>
<a href="#special_blurs"><img src="../img_www/granitesm_right.gif" border="0" width="15" height="15"> Specialised Blurs</a>
<ul>
<li>
<a href="#radial-blur">Radial Blur</a>
</li>
<li>
<a href="#motion-blur">Motion Blur</a>
</li>
</ul>
</dd>
<dd>
<a href="#feathering"><img src="../img_www/granitesm_right.gif" border="0" width="15" height="15"> Feathering Shapes using Blur</a> (under construction)
</dd>
<dd>
<a href="#related"><img src="../img_www/granitesm_right.gif" border="0" width="15" height="15"> Related Operators</a> (under construction)
</dd>
</dl>Blurring, and its opposite, sharpening of images is a very important aspect of image processing. In this section we will look at both.
<hr>
<!-- ---------------------------------------------------------------- -->
<a name="blur" id="blur"></a>
<h2>Blurring Images</h2>Blurring images so they become fuzzy may not seem like an useful operation, but actually is very useful for generating background effects and shadows. It is also very useful for smoothing the effects of the 'jaggies' to <a href="../antialiasing/">anti-alias</a> the edges of images, and to round out features to produce highlighting effects. Blurring is so important it is an integral part of <a href="../resize/">Image Resizing</a>, though a different method of blurring, which is restricted to within the boundaries of a single pixel of the original image. Their are two general image blurring operators in ImageMagick. The "<code><a href="https://imagemagick.org/script/command-line-options.php?#gaussian-blur">-gaussian-blur</a></code>" spread and "<code><a href="https://imagemagick.org/script/command-line-options.php?#blur">-blur</a></code>". The results of the two as very close, but as "<code><a href="https://imagemagick.org/script/command-line-options.php?#blur">-blur</a></code>" is a faster algorithm, it is generally preferred to the former even though the former is more mathematically correct. (See <a href="#blur_gaussian">Blur vs the Gaussian Blur Operator</a>.) <a name="blur_args" id="blur_args"></a>
<h3>Blur/Gaussian Arguments</h3>The arguments for "<code><a href="https://imagemagick.org/script/command-line-options.php?#blur">-blur</a></code>" and "<code><a href="https://imagemagick.org/script/command-line-options.php?#gaussian-blur">-gaussian-blur</a></code>" are the same, but to someone new to image processing, the argument values can be confusing.
<pre><b> -blur {<i>radius</i>}x{<i>sigma</i>} </b></pre>The important setting in the above is the second <i>sigma</i> value. It can be thought of as an approximation of just how much your want the image to 'spread' or blur, in pixels. Think of it as the size of the brush used to blur the image. The numbers are floating point values, so you can use a very small value like '<code>0.5</code>'. The first value <i>radius</i>, is also important as it controls how big an area the operator should look at when spreading pixels. This value should typically be either '<code>0</code>' or at a minimum double that of the <i>sigma</i>. To show you the effects of the options lets take this simple image, with a lot of surrounding space (blur operators need lots of room to work), and create a table of the results for various operator settings. I also purposely used a font that contains both thick and thin lines see the fuzzing of small line details and large areas of color.
<table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">
<tr>
<td width="100%" align="justify">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="100%" bgcolor="#F8F8F8">
<tr>
<td>
<pre><code execute="" no_png2jpg="">
magick -font Gecko -pointsize 48 label:A \
-bordercolor white -border 20x10 blur_source.png
</code></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="blur_source.png"><img src="blur_source.png" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td>
</tr>
</table>
<div align="center">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="0">
<tr>
<td>
<a href="blur_montage.jpg"><img src="blur_montage.jpg" align="middle" vspace="2" hspace="2" border="0" alt="[IM Output]"></a>
</td>
</tr>
</table>
</div>A small <i>radius</i> limits any effect of the blur to pixels that are within that many pixels of the one being blurred (a square radius). As such using a very small <i>radius</i> such as '<code>1</code>' effectively limited the blurring to within the immediate neighbours of each pixel. Note that while <i>sigma</i> is a floating point, <i>radius</i> is not. If a floating point value is given (or internally calculated) it is rounded up to the nearest integer, to determine the 'neighbourhood' of the blur. How much each neighbour contributes to the final result is still controlled by the <i>sigma</i>. A very small <i>sigma</i> (less than '<code>1</code>' ) limits their contribution to a small amount, while a larger <i>sigma</i> contributes more equal amounts from all the neighbours. The largest <i>sigma</i> of '<code>65355</code>' will produce a simple averaging of all the pixels in the square neighbourhood. Also notice that for smallish <i>radius</i> but a large <i>sigma</i> you see artifacts appear in the blurred result. This is especially visible in the output for "<code>-blur 5x8</code>". This is caused by the small square neighbourhood 'cutting off' the area blurred, producing sudden stops in the smooth Gaussian curve of the blur, and thus producing <a href="../filter/#ringing">Ringing Artefacts</a> along sharp edges. So...
<div align="center">
<b>Never use a <i>radius</i> smaller than the <i>sigma</i> for blurs</b>
</div>The ideal solution is to simply set <i>radius</i> to '<code>0x</code>' as shown by the last line of the above table. In that case the operator will try to automatically determine the best <i>radius</i> for the <i>sigma</i> given. The smallest radius IM would use is 3, and is typically 3 * <i>sigma</i> for a Q16 version of IM (a smaller radius is used for IM Q8, as it has less precision). The only time I would use a non-zero <i>radius</i> was for a very small <i>sigma</i> or for specialized blurs. So..
<div align="center">
<b>When possible use a <i>radius</i> of zero for blurring operations</b>
</div>Small values for the <i>sigma</i> are typically only used to fuzz lines and smooth edges on images for which no anti-aliasing was used (see <a href="../antialiasing/">Anti-Aliasing</a> for more info). In that situation I find a blur of '<code>1x0.3</code>' an useful value to remove most of the 'jaggies' from images. Large values however are useful for producing fuzzy images, for backgrounds or shadow effects (see <a href="../fonts/">Compound Fonts</a>), or even image highlighting effects (as shown thought the <a href="../advanced/">Advanced Examples</a> page). Due to the way IM handles '<code>x</code>' style of arguments, the <i>sigma</i> in the above is optional. However it is the more important value, so it should be <i>radius</i> that is optional, as <i>radius</i> can be automatically determined. As such a single value argument to these type of convolution operators is useless. This is unlikely to change as it has been this way for a very long time, and would break too many things. <a name="blur_channel" id="blur_channel">
<h3>Blur uses the Channel Setting</h3></a> To demonstrate blur, lets start simply by generating a fuzzy black circle on a light blue background...
<table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">
<tr>
<td width="100%" align="justify">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="100%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick -size 70x70 xc:lightblue \
-fill black -draw 'circle 35,35 20,25' circle_on_blue.png
magick circle_on_blue.png -blur 0x8 circle_on_blue_blur.png
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="circle_on_blue.png"><img src="circle_on_blue.png" width="70" height="70" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a> <a href="circle_on_blue_blur.png"><img src="circle_on_blue_blur.png" width="70" height="70" align="middle" vspace="0" hspace="2" border="1" alt="[IM Output]"></a>
</td>
</tr>
</table>As you can see a blurring a plain image like this has no problems. It just works, as you would expect. But if we try this again with an image containing a transparent background...
<table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">
<tr>
<td width="100%" align="justify">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="100%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick -size 70x70 xc:none \
-fill black -draw 'circle 35,35 20,25' black_circle.png
magick black_circle.png -blur 0x8 black_blurred.png
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="black_circle.png"><img src="black_circle.png" width="70" height="70" align="middle" vspace="0" hspace="5" border="0" alt="[IM Output]"></a> <a href="black_blurred.png"><img src="black_blurred.png" width="70" height="70" align="middle" vspace="0" hspace="0" border="0" alt="[IM Output]"></a>
</td>
</tr>
</table>Hang on, what happened! The image didn't change! Well in actual fact the operator did work. But "<code><a href="https://imagemagick.org/script/command-line-options.php?#blur">-blur</a></code>" as a grey-scale channel operator, is limited by the "<code><a href="https://imagemagick.org/script/command-line-options.php?#channel">-channel</a></code>" setting, to just the three colour channels. That means only the three color channels of the image were blurred, leaving the transparency or alpha channel of the image as is. In the above however, the image is a fully opaque circle on a background canvas of the color '<code>none</code>', which IM defines as fully-transparent black! That which means we have a black circle, on a transparent black background. In other words an image in which all the colors are black, with some parts opaque, and other parts transparent. Consequently when we blurred the image we only blurred black with black, which as you can probably guess, produced, black! Thus the result had no change in color. Also we never touched the alpha or transparency channel of the image, so we just ended up with the transparency of the image being unchanged. That is, a black circle! What we really wanted to do, is blur all four image channels, particularly the alpha channel. To do this we set the "<code><a href="https://imagemagick.org/script/command-line-options.php?#channel">-channel</a></code>" setting to all four channels of the image (EG: using a value of '<code>RGBA</code>').
<table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">
<tr valign="top">
<td width="100%" align="justify">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="100%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick black_circle.png -channel RGBA -blur 0x8 black_blurred_RGBA.png
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="black_blurred_RGBA.png"><img src="black_blurred_RGBA.png" width="70" height="70" align="middle" vspace="0" hspace="5" border="0" alt="[IM Output]"></a>
</td>
</tr>
</table>Just to summarize...
<div align="center">
<b>Always use a "<code>-channel RGBA</code>" setting when blurring images with transparency.</b>
</div>
<table border="0" cellspacing="0" cellpadding="0" width="90%" align="center">
<tr valign="top">
<td><img src="../img_www/warning.gif" width="28" height="28"><img src="../img_www/space.gif" width="12" height="16"></td>
<td align="justify" width="100%"><font size="-1"><i>IM version 5.5.7 would have blurred all four color channels automatically but the operator has other, buggy effects for images with transparency. See <a href="../bugs/blur_trans/">Blur with Transparency Bug</a> for more details.</i></font></td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="90%" align="center">
<tr valign="top">
<td><img src="../img_www/reminder.gif" width="20" height="16"><img src="../img_www/space.gif" width="20" height="16"></td>
<td align="justify" width="100%"><font size="-1"><i>Some image formats such as GIF and JPEG do not handle semi-transparent pixels. As such I suggest you use PNG format for any images with some form of semi-transparent colors, if possible.</i></font></td>
</tr>
</table>As you can see from the above, the "<code><a href="https://imagemagick.org/script/command-line-options.php?#channel">-channel</a></code>" setting is very important for a grey-scale operator such as "<code><a href="https://imagemagick.org/script/command-line-options.php?#blur">-blur</a></code>". But is not the only thing that can be important when using such an operator. For example lets try that last 'forgot the "<code><a href="https://imagemagick.org/script/command-line-options.php?#channel">-channel</a></code>" setting' example again, but this time with a yellow circle.
<table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">
<tr>
<td width="100%" align="justify">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="100%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick -size 70x70 xc:none \
-fill yellow -draw 'circle 35,35 20,25' yellow_circle.png
magick yellow_circle.png -blur 0x8 yellow_blurred.png
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="yellow_circle.png"><img src="yellow_circle.png" width="70" height="70" align="middle" vspace="0" hspace="5" border="0" alt="[IM Output]"></a> <a href="yellow_blurred.png"><img src="yellow_blurred.png" width="70" height="70" align="middle" vspace="0" hspace="0" border="0" alt="[IM Output]"></a>
</td>
</tr>
</table>Notice that instead of getting unchanged image as we did with a black circle, we instead produces a horrible looking yellow circle with black creeping in around the edges. Yuck! This problem is caused by a fact that few new IM users realise.
<div align="center">
<b>Transparent pixels has Color, even if you can't see it.</b>
</div>In the above case that transparent color was black, which leaked into the yellow circle. Of course we can fix this by setting the "<code><a href="https://imagemagick.org/script/command-line-options.php?#channel">-channel</a></code>" setting correctly for a transparent image, things do work as expected.
<table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">
<tr>
<td width="100%" align="justify">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="100%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick yellow_circle.png -channel RGBA -blur 0x8 yellow_blurred_RGBA.png
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="yellow_blurred_RGBA.png"><img src="yellow_blurred_RGBA.png" width="70" height="70" align="middle" vspace="0" hspace="0" border="0" alt="[IM Output]"></a>
</td>
</tr>
</table><a name="blur_internals" id="blur_internals"></a>
<h3>Blur Internals</h3>Lets take this step further with a more complicated example, which will let use explore exactly what "<code><a href="https://imagemagick.org/script/command-line-options.php?#blur">-blur</a></code>" is doing internally. Here we create a very special image of a yellow circle, which has been drawn on a fully-transparent red background. This will let us see the effect of a transparent color has when blurring images.
<table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">
<tr>
<td width="100%" align="justify">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="100%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick -size 70x70 xc:'#F000' \
-fill yellow -draw 'circle 35,35 20,25' yellow_on_red.png
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="yellow_on_red.png"><img src="yellow_on_red.png" width="70" height="70" align="middle" vspace="0" hspace="3" border="0" alt="[IM Output]"></a>
</td>
</tr>
</table>Note the color "#F000" is a fully-transparent red. It that is the background areas of the image is actually an invisible red in color, instead of the more typical fully-transpaent black. This is important for later tests. We can see the color of the transparent parts of the image by effectively deleting the alpha channel of the image using the "<code><a href="https://imagemagick.org/script/command-line-options.php?#alpha">-alpha off</a></code>" operator.
<table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">
<tr>
<td width="100%" align="justify">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="100%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick yellow_on_red.png -alpha off yellow_on_red_matte.png
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="yellow_on_red_matte.png"><img src="yellow_on_red_matte.png" width="70" height="70" align="middle" vspace="0" hspace="5" border="0" alt="[IM Output]"></a>
</td>
</tr>
</table>Now lets try blurring just the colors of the image again, using the default '<code>RGB</code>', "<code><a href="https://imagemagick.org/script/command-line-options.php?#channel">-channel</a></code>" setting.
<table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">
<tr>
<td width="100%" align="justify">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="100%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick yellow_on_red.png -blur 0x8 yellow_on_red_RGB.png
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="yellow_on_red_RGB.png"><img src="yellow_on_red_RGB.png" width="70" height="70" align="middle" vspace="0" hspace="5" border="0" alt="[IM Output]"></a>
</td>
</tr>
</table>As you can see the fully-transparent red background of the image has now crept into the visible yellow circle, giving it an interesting orange edge, as as it did previously. You may like this effect, but their are better ways of generating it, than to rely on invisible fully-transparent colors. Just prove you can blur this image correctly, lets do it properly...
<table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">
<tr>
<td width="100%" align="justify">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="100%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick yellow_on_red.png -channel RGBA -blur 0x8 yellow_on_red_RGBA.png
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="yellow_on_red_RGBA.png"><img src="yellow_on_red_RGBA.png" width="70" height="70" align="middle" vspace="0" hspace="5" border="0" alt="[IM Output]"></a>
</td>
</tr>
</table>The reason that blurring with the alpha channel produces no orange colors as it did previously, is that when the "<code><a href="https://imagemagick.org/script/command-line-options.php?#blur">-blur</a></code>" operator sees that the alpha channel is involved (according to the current "<code><a href="https://imagemagick.org/script/command-line-options.php?#channel">-channel</a></code>" setting), it will only blur using the pixels which are <i>visible</i> according to that alpha channel. If the alpha channel is not involved, it will completely ignore it, and the fully-transparent red will blur with the yellow to produce various shades of orange.Basically the blur algorithm has been modified to ignore all the fully-transparent pixels in the image, no matter what color they may have. Any semi-transparent pixels are still involved, but their effect on the result is also moderated by just how visible they are. The result is that the circle has become a fuzzy semi-transparent yellow spot. Just what the user probably was trying to achieve. If you really like you can blur both the colors and the alpha channel separately, thus effectually disconnecting the algorithms 'visibility adjustment' on the color channels. The result is more like a sun shining through a dirty brown haze.
<table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">
<tr>
<td width="100%" align="justify">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="100%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick yellow_on_red.png -channel A -blur 0x8 \
-channel RGB -blur 0x8 yellow_on_red_GS.png
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="yellow_on_red_GS.png"><img src="yellow_on_red_GS.png" width="70" height="70" align="middle" vspace="0" hspace="5" border="0" alt="[IM Output]"></a>
</td>
</tr>
</table>This last example produced what a pure grey-scale operator would have produced if there was absolutely no interaction between the alpha channel and the colors within the image (transparent or otherwise). That is, each of the red, green, blue, and alpha channels are blurred completely separately to each other as if they were each a separate grey-scale image. Just remember, as the default "<code><a href="https://imagemagick.org/script/command-line-options.php?#channel">-channel</a></code>" setting is '<code>RGB</code>', the default action is not to blur the alpha channel, <i>and</i> to blur invisible colors with the visible color within the image. Aren't you glad that "<code><a href="https://imagemagick.org/script/command-line-options.php?#blur">-blur</a></code>" is no longer always a pure grey-scale operator. Though you can use it in that way if you really want. You didn't always have this choice however...
<table border="0" cellspacing="0" cellpadding="0" width="90%" align="center">
<tr valign="top">
<td><img src="../img_www/warning.gif" width="28" height="28"><img src="../img_www/space.gif" width="12" height="16"></td>
<td align="justify" width="100%"><font size="-1"><i>Before IM version 6.2.4-4, the "<code><a href="https://imagemagick.org/script/command-line-options.php?#blur">-blur</a></code>", and "<code><a href="https://imagemagick.org/script/command-line-options.php?#gaussian-blur">-gaussian-blur</a></code>" operators were applied as pure grey-scale operation, and as such did not adjust color weighting according to their alpha channel 'visibility'. The result was that any form of blurring with transparency, almost always produced horrible 'black halo' effects, such as purposefully generated in the previous example.<br>
<br>
This was classed as a major long term bug within the IM distribution, and one that was very hard to workaround. For more details of this problem, see the <a href="../bugs/blur_trans/">Blur with Transparency Bug</a> page.</i></font></td>
</tr>
</table>
<pre>FUTURE: Blur and Trimming Images. </pre><a name="blur_gaussian" id="blur_gaussian"></a>
<h3>Blur vs Gaussian Blur Operators</h3>There has been some confusion as to which operator, "<code><a href="https://imagemagick.org/script/command-line-options.php?#blur">-blur</a></code>" or the "<code><a href="https://imagemagick.org/script/command-line-options.php?#gaussian-blur">-gaussian-blur</a></code>" is better for blurring images. First of all "<code><a href="https://imagemagick.org/script/command-line-options.php?#blur">-blur</a></code>" is faster, but it does this using two stage technique. First in one axis, then in the other. The "<code><a href="https://imagemagick.org/script/command-line-options.php?#gaussian-blur">-gaussian-blur</a></code>" operator on the other hand is more mathematically correct as it blurs in all directions simultaneously. The speed cost between the two can be enormous, by a factor of 10 or more, depending on the amount of bluring involved. In a more technical context, "<code><a href="https://imagemagick.org/script/command-line-options.php?#blur">-blur</a></code>" is a 2 pass, 1 dimensional orthogonal convolution filter, while "<code><a href="https://imagemagick.org/script/command-line-options.php?#gaussian-blur">-gaussian-blur</a></code>" is a 2 dimensional cylindrical convolution filter. See <a href="../morphology/#convolve">Convolution</a> for more details. The results of the two method should be the same, unlike the use of other 'filtered' convolution operations. However the two pass system means that there is an intermediate stage in which rounding, or quantum effects, can occur. Cristy also bears this out when he reported... You should always use "<code><a href="https://imagemagick.org/script/command-line-options.php?#blur">-blur</a></code>" instead of "<code><a href="https://imagemagick.org/script/command-line-options.php?#gaussian-blur">-gaussian-blur</a></code>" because its faster. Some pixels will be different on the interior due to rounding, and the edge pixels may be different because of loss of <a href="../misc/#virtual">Virtual Pixel</a> edge effects, again in the intermediate stage. In summary, the two operators are slightly different, but only minimally. As "<code><a href="https://imagemagick.org/script/command-line-options.php?#blur">-blur</a></code>" is much faster, use it. I do in just about all the examples involving blurring. <a name="blur_resize" id="blur_resize"></a>
<h3>Large Blur using Resize</h3>Using large sigma values for image bluring is very slow. But onw technique can be used to speed up this process. This however is only a rough method and could use some mathematicaly rigor to improve results. Essentually the reason large blurs are slow is because you need a large window or 'kernel' to merge lots of pixels together, for each and every pixel in the image. However resize (making image smaller) does the same thing but generates fewer pixels in the process. The technique is basically shrink the image, then enlarge it again to generate the heavilly blured result. The <a href="../filters/#gaussian">Gaussian Filter</a> is especially useful for this as you can directly specify a <a href="../filters/#sigma">Gaussian Sigma</a> define.For example, here I blue the small rose image by a sigma value of 5 using the two methods.
<div align="center">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="90%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick rose: -blur 0x5 rose_blur_5.png
magick rose: -filter Gaussian -resize 50% \
-define filter:sigma=2.5 -resize 200% rose_resize_5.png
</samp></pre>
</td>
</tr>
</table><a href="../images/rose.png"><img src="../images/rose.png" width="70" height="46" align="middle" vspace="5" hspace="15" border="1" alt="[IM Output]"></a> <img src="../img_www/right.gif" width="20" height="20" align="middle" alt="==>"> <a href="rose_blur_5.png"><img src="rose_blur_5.png" width="70" height="46" align="middle" vspace="5" hspace="15" border="1" alt="[IM Output]"></a> <a href="rose_resize_5.png"><img src="rose_resize_5.png" width="70" height="46" align="middle" vspace="5" hspace="5" border="1" alt="[IM Output]"></a>
</div>Note the sigma setting (used only on the enlargement step) is only half that actually desired as you are also doubling the image size. You can make overall resulting blur larger by adjusting both the downsize ratio and the given sigma value. The downsizing step is the one that produces the speedup but you should have at least soem bluring in upsize step as a quality control. This is just an example of the technique. It is really meant to be used for very very large sigma values on very very large images. For example in blurs using a sigma of 10 or more on modern digital photos. This technique is also used to generate multi-level blur of a single image in a <a href="../canvas/#sparse_blur">Sparse Color Shepards, Alternative</a>.<br>
<hr>
<!-- ---------------------------------------------------------------- -->
<a name="sharpen" id="sharpen"></a>
<h2>Sharpening Images</h2>
<div align="center">
<font size="+2"><b><img src="../img_www/const_barrier.gif" width="39" height="35"> Under Construction <img src="../img_www/const_hole.gif" width="144" height="50"></b></font>
</div>Sharpening is a the computer graphics algorithm that is most often see on TV shows and movies. Picture the police force 'cleaning up' a 'zoomed in' photo of a licence plate of a bank robbers car, or the face of a man on a fuzzy shop camera video, and you see what I mean. Basically what they are doing is attempting to recover the fine detail of an image which was lost due to an image natural blurring from camera lens or low scale resolution images. Sharpen Arguments? (expand)
<pre>
The most important factor is the sigma. As it is the real control of the
sharpening operation. It is only due to historical accident it is the second
term in the above.
It can be any floating point value from .1 for practically no sharpening to
3 or more for sever sharpening. 0.5 to 1.0 is rather good.
Radius is just a limit of the effect as is the threshold.
Radius is only in integer units as that is the way the algorithm works, the
larger it is the slower it is. But it should be at a minimum 1 or better
still 2 times the sigma.
</pre>First forget the first number, just use 0 which will then use the best number for the 'sigma' factor you give. The larger the sigma the more it sharpens.
<table cellpadding="0" cellspacing="0" width="60%" align="center">
<tr>
<td>-sharpen 0x.4</td>
<td>very small</td>
</tr>
<tr>
<td>-sharpen 0x1.0</td>
<td>about one pixel size sharpen</td>
</tr>
<tr>
<td>-sharpen 0x3.0</td>
<td>probably getting too large</td>
</tr>
</table>The "<code><a href="https://imagemagick.org/script/command-line-options.php?#sharpen">-sharpen</a></code>" operator is sort of an inverted blur. In fact it works in just about the same way. For examples which show how this is related to blur see, <a href="http://netpbm.sourceforge.net/doc/extendedopacity.html">Image Processing By Interpolation and Extrapolation</a>. For example lets blur a simple image then attempt to sharpen it again to remove the blur.
<div align="center">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="90%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick -font Gecko -pointsize 72 label:A A_original.jpg
magick A_original.jpg -blur 0x3 A_blur.jpg
magick A_blur.jpg -sharpen 0x3 A_blur_sharp.jpg
magick A_blur_sharp.jpg -sharpen 0x3 A_blur_sharp_x2.jpg
</samp></pre>
</td>
</tr>
</table><a href="A_original.jpg"><img src="A_original.jpg" align="middle" vspace="1" hspace="15" border="1" alt="[IM Output]"></a> <img src="../img_www/right.gif" width="20" height="20" align="middle" alt="==>"> <a href="A_blur.jpg"><img src="A_blur.jpg" align="middle" vspace="1" hspace="15" border="1" alt="[IM Output]"></a> <img src="../img_www/right.gif" width="20" height="20" align="middle" alt="==>"> <a href="A_blur_sharp.jpg"><img src="A_blur_sharp.jpg" align="middle" vspace="1" hspace="15" border="1" alt="[IM Output]"></a> <img src="../img_www/right.gif" width="20" height="20" align="middle" alt="==>"> <a href="A_blur_sharp_x2.jpg"><img src="A_blur_sharp_x2.jpg" align="middle" vspace="1" hspace="15" border="1" alt="[IM Output]"></a>
</div>As you can see the result is not perfect, as spreading the pixels out will make the sharp corners of the image less distinct. Particularly notice the extra thickening that resulted at the corner of the two lines at the very top of the image, as well and the near disappearance of the thin lines. Even repeating the operation or increasing the size of the area of the sharpen will not help return the image back to the exact original as you have basically lost the finer detail from the image blurring. However the macro detail can be recovered quite well. It is sharpening algorithms which can recover of finer detail in a blurred, or heavily zoomed image, that makes big money in software packages used by police forces, astronomers, and government spy agencies. <a name="unsharp" id="unsharp"></a>
<h3>Unsharp Images</h3>
<div align="center">
<font size="+2"><b><img src="../img_www/const_barrier.gif" width="39" height="35"> Under Construction <img src="../img_www/const_hole.gif" width="144" height="50"></b></font>
</div>Both the "<code><a href="https://imagemagick.org/script/command-line-options.php?#sharpen">-sharpen</a></code>", and "<code><a href="https://imagemagick.org/script/command-line-options.php?#unsharp">-unsharp</a></code>" operators, work using the exact same technique of subtracting a blur from the original image. For the internal details of how both "<code><a href="https://imagemagick.org/script/command-line-options.php?#sharpen">-sharpen</a></code>", and "<code><a href="https://imagemagick.org/script/command-line-options.php?#sharpen">-unsharp</a></code>" actually work see <a href="../convolve/#unsharpen">Unsharpen Convolution</a>.
<div align="center">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="90%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick A_blur.jpg -unsharp 0x5 A_blur_unsharp.jpg
</samp></pre>
</td>
</tr>
</table><a href="A_blur.jpg"><img src="A_blur.jpg" align="middle" vspace="1" hspace="15" border="1" alt="[IM Output]"></a> <img src="../img_www/right.gif" width="20" height="20" align="middle" alt="==>"> <a href="A_blur_unsharp.jpg"><img src="A_blur_unsharp.jpg" align="middle" vspace="1" hspace="15" border="1" alt="[IM Output]"></a>
</div>
<pre>
From comments on <a href="http://redskiesatnight.com/2005/04/06/sharpening-using-image-magick/">Sharpening with ImageMagick</a> from Alex Beels
Matching GIMP unsharp
Take gimp radius and add 1 => IM sigma
Threshold divide by 255 => IM Threshold
So GIMP radius=2 amount=1.5 threshold=5 results in
-unsharp 0×3+1.5+0.0196
Another suggested that im_sigma = sqrt(gimp_radius)
<b>Raw notes from Fred Weinhaus</b>
Blur Image for test.
A_original.jpg
magick A_original.jpg -blur 0x3 A_original_blur3.jpg
sharpen is just a gaussian type blurred image subtracted from the image to
make an edge image (high pass filter), then equally blends that back with the
original, so one has a high pass enhanced image.
magick A_original_blur3.jpg -sharpen 0x3 A_original_blur3_sharp3.jpg
unsharp is more complex. It is similar. It takes the difference (edge result)
as above, i.e. like sharpen BUT only blends some fraction or multiple of that
with the original image, AND only if the difference is above a threshold. Thus
unsharp 0x3+1+0 is basically the same as sharpen 0x3
magick A_original_blur3.jpg -unsharp 0x3+1+0
A_original_blur3_unsharp3_1_0.jpg
compare -metric rmse A_original_blur3_sharp3.jpg
A_original_blur3_unsharp3_1_0.jpg null:
164.661 (0.00251256)
The difference may be due to whether one uses a separable (gaussian) blur
filter or not in one or the other but not both. Or it could be just some
slight differences elsewhere in the IM implementation.
If one blends less with the original, one gets less sharpening.
magick A_original_blur3.jpg -unsharp 0x3+0.5+0
A_original_blur3_unsharp3_0p5_0.jpg
If one blends more with the original, one gets more sharpening.
magick A_original_blur3.jpg -unsharp 0x3+2+0
A_original_blur3_unsharp3_2_0.jpg
If one increases the threshold, then one gets less sharpening again.
magick A_original_blur3.jpg -unsharp 0x3+2+0.2
A_original_blur3_unsharp3_2_0p2.jpg
Several of my (Fred's) scripts, binomialedge, gaussianedge, sharpedge use this
blending concept (between the high pass filtered result and the original
image) and a description is there with the scripts. The thresholding in my
scripts is done differently and for a different purpose.
<b>Sharpen using de-convolution</b>
There is a technique of using de-convolution (division in a Fast-Fourier
generated frequency form of images), This works best when the exact 'blur'
that was applied to the original image is known, or calculated in some way.
At the moment only raw 'DIY' methods are as yet available in IM
and a number of such methods are demonstrated (trialed) in the sub-section
<a href="../fourier/fft_math/">Fourier Multiply/Divide</a>.
</pre>
<hr>
<!-- ---------------------------------------------------------------- -->
<a name="shadow" id="shadow"></a>
<h2>Generating Shadows</h2>The "<code><a href="https://imagemagick.org/script/command-line-options.php?#shadow">-shadow</a></code>" operator is an advanced operator that was developed with the IM example pages. Basically it represents a very complex blur and re-coloring of transparency shape of the given image. This is an operation that IM users performed all the time, but required a good deal of knowledge to figure how to achieve correctly. The operator will take an image (usually a clone, and may already have some transparency) and magick it into a shadow image that can then be positioned under the original image at given offset, (generally by using the special <a href="../layers/#merge">Layer Merge</a> operator. Here for example is a standard method of shadowing an existing image, using a navy shadow color to match this web page.
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td width="100%" align="justify">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="100%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick rose: \( +clone -background navy -shadow 80x3+5+5 \) +swap \
-background none -layers merge +repage shadow.png
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="shadow.png"><img src="shadow.png" align="middle" vspace="1" hspace="5" border="0" alt="[IM Output]"></a>
</td>
</tr>
</table>Note how the shadow image is correctly offset from the image. You can even zero the blur '<i>sigma</i>' value and create a hard shadow, but semi-transparent shadow.
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td width="100%" align="justify">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="100%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick rose: \( +clone -background navy -shadow 60x0+4+4 \) +swap \
-background none -layers merge +repage shadow_hard.png
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="shadow_hard.png"><img src="shadow_hard.png" align="middle" vspace="1" hspace="5" border="0" alt="[IM Output]"></a>
</td>
</tr>
</table>The use of "<code><a href="https://imagemagick.org/script/command-line-options.php?#layers">-layers</a> merge</code>" to layer shadow images with the original image makes it easy to generate shadows from a light source from any direction, not just the upper left side.
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td width="100%" align="justify">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="100%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick rose: \( +clone -background navy -shadow 80x3-5+5 \) +swap \
-background none -layers merge +repage shadow_other.png
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="shadow_other.png"><img src="shadow_other.png" align="middle" vspace="1" hspace="5" border="0" alt="[IM Output]"></a>
</td>
</tr>
</table>While it is easiest to just use a <a href="../layers/#merge">Layers Merge</a>, it will tend to shift the overall offset of the resulting image. The shift however is not caused by the layering method, but due to "<code><a href="https://imagemagick.org/script/command-line-options.php?#repage">+repage</a></code>" removing any negative or positive offset that may be present in the resulting 'layer' image. See <a href="#shadow_offset">Shadows and the Offset Problem</a> for alternative techniques.
<table border="0" cellspacing="0" cellpadding="0" width="90%" align="center">
<tr valign="top">
<td><img src="../img_www/warning.gif" width="28" height="28"><img src="../img_www/space.gif" width="12" height="16"></td>
<td align="justify" width="100%"><font size="-1"><i>The <a href="../layers/#merge">Layers Merge</a> method was added to IM v6.3.6-2. Before this you would need to use the similar layer flattening operator "<code><a href="https://imagemagick.org/script/command-line-options.php?#mosaic">-mosaic</a></code>" instead. However this operator has problems (see next).</i></font></td>
</tr>
</table><a name="shadow_shape" id="shadow_shape"></a>
<h3>Shaped Shadows</h3>Now "<code><a href="https://imagemagick.org/script/command-line-options.php?#shadow">-shadow</a></code>" was designed with shaped images in mind, (and this is the reason for its complexity). For example, here is a typical shadowed font.
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td width="100%" align="justify">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="100%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick -background none -stroke black -fill white \
-font Candice -pointsize 48 label:A -trim \
\( +clone -background navy -shadow 80x3+3+3 \) +swap \
-background none -layers merge +repage shadow_a.png
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="shadow_a.png"><img src="shadow_a.png" align="middle" vspace="1" hspace="5" border="0" alt="[IM Output]"></a>
</td>
</tr>
</table>If there is enough space for the shadow to be included without clipping, in the original image, you can use this command. It uses a special '<code><a href="../compose/#dst_over">DstOver</a></code>' composition method so as to avoid the need to swap the order of the two images.
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td width="100%" align="justify">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="100%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick -background none -stroke black -fill white \
-font Candice -pointsize 48 label:'A ' \
\( +clone -background navy -shadow 80x3+3+3 \) \
-background none -compose DstOver -flatten shadow_a_size.png
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="shadow_a_size.png"><img src="shadow_a_size.png" align="middle" vspace="1" hspace="5" border="0" alt="[IM Output]"></a>
</td>
</tr>
</table>You can probably see a small amount of clipping in this as the original image did not have quite enough extra space for the requested shadow. <a name="shadow_offset" id="shadow_offset"></a>
<h3>Shadows and the Offset Problem</h3>The problem with shadow is that a blurry shadow extends in all directions. To compensate the "<code><a href="https://imagemagick.org/script/command-line-options.php?#shadow">-shadow</a></code>" operator enlarges the actual original image by adding a border 2 times the size of the blur '<i>sigma</i>' value given. That is, if you blur a shadow using '<code>x3</code>', it will enlarge the image by 12 pixels (2 times 3 pixels on every side). To compensate for this enlargement, a shadow image is also given an appropriate negative <a href="../basics/#page">Virtual Canvas Offset</a> so that it will be positioned correctly relative to the image being shadowed. For a normal image that means the shadow image generated will have a negative offset. This however generates a problem when your IM does not have a the "<code><a href="https://imagemagick.org/script/command-line-options.php?#layers">-layers</a></code>" method '<code>merge</code>' available. For example, here we try to add a shadow on the left side, of the image as if a light shone from the upper right.
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td width="100%" align="justify">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="100%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick rose: \( +clone -background navy -shadow 60x3-5+5 \) +swap \
-background none -mosaic shadow_left_clipped.png
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="shadow_left_clipped.png"><img src="shadow_left_clipped.png" align="middle" vspace="1" hspace="5" border="0" alt="[IM Output]"></a>
</td>
</tr>
</table>As you can see as the shadow, was clipped by the "<code><a href="https://imagemagick.org/script/command-line-options.php?#mosaic">-mosaic</a></code>" operator, because of the negative offset. Not good! One solution is to add an initial offset to the original image so the resulting shadow images offset will not be negative.
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td width="100%" align="justify">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="100%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick rose: -repage +11+0\
\( +clone -background navy -shadow 80x3-5+5 \) +swap \
-background none -mosaic shadow_left.png
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="shadow_left.png"><img src="shadow_left.png" align="middle" vspace="1" hspace="5" border="0" alt="[IM Output]"></a>
</td>
</tr>
</table>Another method is offset both images by an appropriate amount after the shadow has been generated. This removes any negative offsets before you "<code><a href="https://imagemagick.org/script/command-line-options.php?#mosaic">-mosaic</a></code>" them together. Note the use of a '<code>!</code>' flag with "<code><a href="https://imagemagick.org/script/command-line-options.php?#repage">-repage</a></code>" to add the given offset to both images.
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td width="100%" align="justify">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="100%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick rose: \( +clone -background navy -shadow 80x3-5-5 \) +swap \
-repage +11+11\! -background none -mosaic shadow_tl.png
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="shadow_tl.png"><img src="shadow_tl.png" align="middle" vspace="1" hspace="5" border="0" alt="[IM Output]"></a>
</td>
</tr>
</table>The amount of space need should be at least 2×'<i>sigma</i>'-'<i>offset</i>', or in this case 2×3--5 ⇒ 11 pixels, or you risk clipping the shadow. However space of about '<i>sigma</i>'-'<i>offset</i>' usually produces an acceptable level of clipping. Another alternative is to expand the original image so as to make enough room for the final shadow. This is the BEST way of handling shadows, while preserving the images original location on the virtual canvas. For example, here I pad out the original image with some extra space for the shadow, and then underlay the shadow image directly. I included a border in the displayed image result so that you can see that the final image remains centered in the 'padded' image.
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td width="100%" align="justify">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="100%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick rose: -bordercolor None -border 11x11 \
\( +clone -background navy -shadow 80x3+5+5 \) \
-background none -compose DstOver -flatten \
-compose Over shadow_space.png
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="shadow_space.png"><img src="shadow_space.png" align="middle" vspace="1" hspace="5" border="1" alt="[IM Output]"></a>
</td>
</tr>
</table>The amount of padding needed should be at least '<i>sigma</i>'+abs('<i>offset</i>') or better still 2×'<i>sigma</i>'+abs('<i>offset</i>'), to ensure the shadow is not clipped. Padding can be asymmetrical to reduce space, but typically a symmetrical padding (like the above) is used for convenience.
<table border="0" cellspacing="0" cellpadding="0" width="90%" align="center">
<tr valign="top">
<td><img src="../img_www/reminder.gif" width="20" height="16"><img src="../img_www/space.gif" width="20" height="16"></td>
<td align="justify" width="100%"><font size="-1"><i>Note that while the "<code>-compose Over</code>" setting is not actually needed in the above, it is recommended. Otherwise later operations (even in other "<code>magick</code>" commands) could be effected, with unexpected results. That is, a non-standard compose setting can effect other operations, including: image layering, adding borders, or frames, or simply other compositions.</i></font></td>
</tr>
</table><a name="shadow_composite" id="shadow_composite"></a>
<h3>Shadows and Composite</h3>Many people on the forums generate a shadow image and then try to use the lower-level "<code><a href="https://imagemagick.org/script/command-line-options.php?#composite">-composite</a></code>" to merge the images. For example directly overlay the original image onto a generated (larger) shadow image.
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td width="100%" align="justify">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="100%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick rose: \( +clone -background navy -shadow 60x3 \) \
+swap -composite +repage shadow_composite.png
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="shadow_composite.png"><img src="shadow_composite.png" align="middle" vspace="1" hspace="5" border="0" alt="[IM Output]"></a>
</td>
</tr>
</table>The first point to remember is that the <a href="../compose/#compose">Composition Operators</a> are very low level and do not read any layer or virtual canvas offset either original image, or the <a href="#shadow">Shadow Operator</a> may have. In fact we still need to remove or adjust the possibly negative (bad) offset shadow added using the <a href="../basics/#page">Repage Setting</a>. This means that the offset you see on the above example is being generated simply because of the way shadow enlarged the input image to give the shadow some space. The shadow is where it is solely due to the expansion of the shadow image by 2 times sigma. Further, if you use a 'hard shadow' (zero sigma) you would also end up with no offset to the shadow at all, and thus the shadow will be hidden by the original image, other than a possible dark halo edge effect. You have essentially give up the built-in offset calculation that the <a href="#shadow">Shadow Operator</a> provides. Of course you can calculate and set the appropriate <a href="../compose/#geometry">Composite Geometry/Gravity</a> settings instead, and the easiest way is to use a "<code><a href="https://imagemagick.org/script/command-line-options.php?#gravity">-gravity</a> Center</code>" setting, as the enlarged shadow image is expanded equally on all sides.
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td width="100%" align="justify">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="100%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick rose: \( +clone -background navy -shadow 60x3 \) +repage \
+swap -gravity center -geometry -3-5 -composite shadow_geometry.png
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="shadow_geometry.png"><img src="shadow_geometry.png" align="middle" vspace="1" hspace="5" border="0" alt="[IM Output]"></a>
</td>
</tr>
</table>Note that the centered geometry offset is negative as the image order was swapped. <a name="shadow_outline" id="shadow_outline"></a>
<h3>Shadow Outlines</h3>You can also use "<code><a href="https://imagemagick.org/script/command-line-options.php?#shadow">-shadow</a></code>" to generate a fuzzy outlines of shapes, such as text. By using <a href="../layers/#merge">Layers Merge</a> IM will automatically add the extra space needed for the semi-transparent blur.
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td width="100%" align="justify">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="100%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick -background none -fill white \
-font Candice -pointsize 48 label:A -trim \
\( +clone -background black -shadow 100x3+0+0 \) +swap \
-background none -layers merge +repage shadow_outline.png
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="shadow_outline.png"><img src="shadow_outline.png" align="middle" vspace="1" hspace="5" border="0" alt="[IM Output]"></a>
</td>
</tr>
</table>Here you can see one problem with using a blurred shape for outlining. The edge of the shape will always be at least 50% transparent, by the very nature of how blurring works. To compensate you can either enlarge the shape of the image that will be shadowed, (for an example see <a href="../fonts/#denser_soft_outline">Denser Soft Outline Font</a>). Better still you can adjust the transparency of the shadow image, using a <a href="../color_mods/#level">Level Adjustment</a> so that a 50% transparency along the edges of the shape becomes fully opaque.
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td width="100%" align="justify">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="100%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick -background none -fill white \
-font Candice -pointsize 48 label:A -trim \
\( +clone -background black -shadow 100x3+0+0 \
-channel A -level 0,50% +channel \) +swap \
+repage -gravity center -composite shadow_outline_darker.png
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="shadow_outline_darker.png"><img src="shadow_outline_darker.png" align="middle" vspace="1" hspace="5" border="0" alt="[IM Output]"></a>
</td>
</tr>
</table><!-- This does not work yet!
An alternative is to over-do the transparency adjustment (using
'<CODE>200x</CODE>' instead of '<CODE>100x</CODE>') fix the problem.
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 width="100%">
<TR><TD width="100%" ALIGN=justify>
<table class="table table-sm table-hover table-striped" CELLSPACING=0 CELLPADDING=5 width="100%" bgcolor="#f8f8f8">
<TR><TD><pre class="bg-light text-dark mx-4"><samp>
magick -background none -fill white \
-font Candice -pointsize 48 label:A -trim \
\( +clone -background black -shadow 200x3+0+0 \) +swap \
+repage -gravity center -composite shadow_outline_fixed.png
</code></PRE></TD></TR></TABLE></TD><TD>
<A HREF="shadow_outline_fixed.png"
><IMG SRC="shadow_outline_fixed.png"
ALIGN=middle VSPACE=1 HSPACE=5 BORDER=0 ALT="[IM Output]"></A>
</TD></TR></TABLE></P>
-->
Another method of handling the shadow positioning and offset, is to basically junk all the "<code><a href="https://imagemagick.org/script/command-line-options.php?#shadow">-shadow</a></code>" generated offsets (using "<code><a href="https://imagemagick.org/script/command-line-options.php?#repage">+repage</a></code>"), and center overlaid the original image on the larger shadow image. By adding a "<code><a href="https://imagemagick.org/script/command-line-options.php?#geometry">-geometry</a></code>" composition offset you can then offset the shadow as a separate action.
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td width="100%" align="justify">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="100%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick -background none -fill white -stroke black \
-font Candice -pointsize 48 label:A -trim \
\( +clone -background navy -shadow 80x3 \) +swap \
+repage -gravity center -geometry -3-3 -composite \
shadow_geometry_offset.png
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="shadow_geometry_offset.png"><img src="shadow_geometry_offset.png" align="middle" vspace="1" hspace="5" border="0" alt="[IM Output]"></a>
</td>
</tr>
</table>However notice how the offset is a negative to what you would normally use for positioning the shadow. This is because you are really offsetting the text shape and not the shadow, so it is in the opposite direction. This method will however clip the original source image, rather than the shadow image if the offset becomes larger that twice the blur 'sigma'. As such it can not be used for 'hard shadows' (using a '<code>x0</code>' blur 'sigma'), unless you include some padding space to the shadow image for the original image to be overlaid. With a soft fuzzy shadow however that is rarely a problem. For some practical examples of shadowing see <a href="../thumbnails/#shadow">Thumbnail shadowing</a> and <a href="../advanced/#3d-logos-2">Better 3-D Logo Generation</a>. <a name="shadow_montage" id="shadow_montage"></a>
<h3>Shadow in the Montage Command</h3>As of IM v6.3.1 the "<code>magick montage</code>" "<code><a href="https://imagemagick.org/script/command-line-options.php?#shadow">-shadow</a></code>" setting, started to make use of the soft 'shaped' shadows this operator provides.
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td width="100%" align="justify">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="100%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
montage -label Rose rose: \
-background none -geometry +5+5 -shadow shadow_montage.png
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="shadow_montage.png"><img src="shadow_montage.png" align="middle" vspace="0" hspace="5" border="0" alt="[IM Output]"></a>
</td>
</tr>
</table>However no controls for setting the color, fuzziness and offset of that shadow is provided, as "<code>magick montage</code>" never did provide such controls, beyond a simple on/off option. <a name="shadow_internals" id="shadow_internals"></a>
<h3>Shadow Internals</h3>Internally "<code><a href="https://imagemagick.org/script/command-line-options.php?#shadow">-shadow</a></code>" is extremely complex. Basically not only does it need to enlarge an image to accommodate a 'soft blurry shadow', but it also needs to blur the existing shape of the image, set its color appropriately, and finally adjust virtual page/canvas offsets; all to the users specifications. For example given the following "<code><a href="https://imagemagick.org/script/command-line-options.php?#shadow">-shadow</a></code>" command...
<div align="center">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="90%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick image_clone.png -shadow 60x4+5+5 image_shadow.png
</samp></pre>
</td>
</tr>
</table>
</div>The equivalent IM operation would be...
<div align="center">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="90%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick image_clone.png -alpha set \
-bordercolor none -border 8 -repage -8-8\! \
-channel A -virtual-pixel transparent \
-blur 8x4 -evaluate multiply .60 +channel
-fill {background_color} -colorize 100% \
-repage +5+5\! image_shadow.png
</samp></pre>
</td>
</tr>
</table>
</div>Note that the value 8 in the above is two times the blur sigma, so as to provide enough space for the blurred shadow. However this means the final image will be 4 times sigma pixels larger. To compensate an equal amount of negative offset is also added. Now as a 2 times sigma negative offset will be added to the generated image, care should be taken to avoid the shadow being clipped, or incorrectly positioned relative to the original image. That can be done by either giving the original image an initial positive offset (such as 8-5 or +3+3 pixels), or using <a href="../layers/#merge">Layers Merge</a> which understands negative offsets without clipping the final image. Basically use the previous techniques to correctly handle posible negative offsets involved with shadow images.
<table border="0" cellspacing="0" cellpadding="0" width="90%" align="center">
<tr valign="top">
<td><img src="../img_www/reminder.gif" width="20" height="16"><img src="../img_www/space.gif" width="20" height="16"></td>
<td align="justify" width="100%"><font size="-1"><i>The PNG, and MIFF formats are the only image formats I know that can handle a negative offset, as well as semi-transparent pixels. I recommended PNG be used if saving shadow images, for future use.</i></font></td>
</tr>
</table>As I said "<code><a href="https://imagemagick.org/script/command-line-options.php?#shadow">-shadow</a></code>" is a very complex operation. Of course while the above example is close to what "<code><a href="https://imagemagick.org/script/command-line-options.php?#shadow">-shadow</a></code>" does internally, it is not exactly the same. The actual "<code><a href="https://imagemagick.org/script/command-line-options.php?#shadow">-shadow</a></code>" operator, does not change any of the global settings, such as border/background/fill colors, or the current virtual-pixel setting. Also it will short circuit the use of the "<code><a href="https://imagemagick.org/script/command-line-options.php?#blur">-blur</a></code>" operator if the blur sigma is set to 0, to prevent the blur function from giving a warning for a zero sigma or radius.
<pre>
FUTURE: overlaying multiple shadows
Overlaying two images with shadows, produces an unrealistic darkening of the
shadow where the shadow overlaps. This darkening would be correct if each
object was lit by separate light sources, but more commonly the objects are
lit by the same light source.
The solution is to overlay the one image over the other, applying the shadow
effects to the opaque parts of each layer image in turn. That is, the
background shadow should be generated separately into each layer. Remember
the shadow cast by the top most layer should become fuzzier than the shadow
contribution of the bottom most layer.
This complexity gets worse when you have three objects shadowing each other.
Also the offset and blurring from the shadow of each object should technically
be separate. To generate that level of complexity, probably a 3-d ray-tracing
program should be used instead (sigh).
</pre>
<hr>
<!-- ---------------------------------------------------------------- -->
<a name="special_blurs" id="special_blurs"></a>
<h2>Specialized Blurs</h2>There are a few other sorts of blurs that have been added to IM version 6, which have very special uses. These operate in specific ways, and not in all directions as most other 'convolve'-style operations do. They also may not work as well as other methods of generating specialized blurs, such as distorting images before and after an more normal blur. For example see <a href="../distorts/#polar_tricks">Polar Cycle Tricks</a>, and <a href="../compose/#blur_ellipse">Elliptical (mapped) Blurring</a>.
<div align="center">
<font size="+1"><b>WARNING: All these blurs are experimental, and syntax may change!</b></font>
</div><a name="radial-blur" id="radial-blur"></a>
<h3>Radial Blur</h3>You can blur the image around in a circle using a "<code><a href="https://imagemagick.org/script/command-line-options.php?#radial-blur">-radial-blur</a></code>", as if it was spinning around and around. Though technically this is a rotational or angular blur, rather than a radial blur. <b>NOTE:</b>You can achieve a much higher quality result (though at a much slower speed) using a <a href="../distorts/#rotation_blur">Depolar-Polar - Rotational Blur</a> technique.Note however that like a normal "<code><a href="https://imagemagick.org/script/command-line-options.php?#blur">-blur</a></code>" operator, "<code><a href="https://imagemagick.org/script/command-line-options.php?#radial-blur">-radial-blur</a></code>" is affected by the "<code><a href="https://imagemagick.org/script/command-line-options.php?#channel">-channel</a></code>" setting.
<table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">
<tr>
<td width="100%" align="justify">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="100%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick -size 70x70 xc:none \
-stroke red -strokewidth 15 -draw 'line 35,5 35,65' \
-stroke yellow -strokewidth 9 -draw 'line 35,5 35,65' \
-channel RGBA -radial-blur 30 radial_blur.png
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="radial_blur.png"><img src="radial_blur.png" width="70" height="70" align="middle" vspace="0" hspace="5" border="0" alt="[IM Output]"></a>
</td>
</tr>
</table>You can place the object off center (by adding some space to an image) for more interesting "<code><a href="https://imagemagick.org/script/command-line-options.php?#radial-blur">-radial-blur</a></code>" effects.
<table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">
<tr>
<td width="100%" align="justify">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="100%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick -size 70x70 xc:none \
-stroke red -strokewidth 15 -draw 'line 5,50 65,50' \
-stroke yellow -strokewidth 9 -draw 'line 5,50 65,50' \
-channel RGBA -radial-blur 90 radial_blur_90.png
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="radial_blur_90.png"><img src="radial_blur_90.png" width="70" height="70" align="middle" vspace="0" hspace="5" border="0" alt="[IM Output]"></a>
</td>
</tr>
</table>The blur argument is the angle the radial-blur covers. That is, half that angle in each direction from the original image. So an angle of 180 is over a half circle, while 360 degrees will blur the image in a full circle.
<table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">
<tr>
<td width="100%" align="justify">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="100%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick -size 70x70 xc:none \
-stroke red -strokewidth 15 -draw 'line 5,50 65,50' \
-stroke yellow -strokewidth 9 -draw 'line 5,50 65,50' \
-channel RGBA -radial-blur 180 radial_blur_180.png
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="radial_blur_180.png"><img src="radial_blur_180.png" width="70" height="70" align="middle" vspace="0" hspace="5" border="0" alt="[IM Output]"></a>
</td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">
<tr>
<td width="100%" align="justify">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="100%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick -size 70x70 xc:none \
-stroke red -strokewidth 15 -draw 'line 5,50 65,50' \
-stroke yellow -strokewidth 9 -draw 'line 5,50 65,50' \
-channel RGBA -radial-blur 360 radial_blur_360.png
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="radial_blur_360.png"><img src="radial_blur_360.png" width="70" height="70" align="middle" vspace="0" hspace="5" border="0" alt="[IM Output]"></a>
</td>
</tr>
</table>You can even add a little <a href="../warping/">Image Warping</a> to make the effect more interesting...
<table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">
<tr>
<td width="100%" align="justify">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="100%" bgcolor="#F8F8F8">
<tr>
<td>
<pre class="bg-light text-dark mx-4"><samp>
magick -size 70x70 xc:none \
-stroke red -strokewidth 15 -draw 'line 5,50 65,50' \
-stroke yellow -strokewidth 9 -draw 'line 5,50 65,50' \
-channel RGBA -radial-blur 180 -swirl 180 radial_swirl.png
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="radial_swirl.png"><img src="radial_swirl.png" width="70" height="70" align="middle" vspace="0" hspace="5" border="0" alt="[IM Output]"></a>
</td>