-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
2211 lines (2211 loc) · 152 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>Miscellaneous -- 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/misc/">
</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"> Miscellaneous</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="#interpolate"><img src="../img_www/granitesm_right.gif" border="0" width="15" height="15"> Interpolation</a> <font size="-1">(Inter-pixel Color Lookups)</font>
<ul>
<li>
<a href="#interpolate_simple">Simple Interpolation Methods</a>
</li>
<li><font size="-1"><a href="#bilinear">Bilinear</a>, <a href="#mesh">Mesh</a>, <a href="#catrom">Catrom</a>, <a href="#spline">Spline</a></font></li>
<li>
<a href="#interpolate_bgnd">Interpolate on a Background</a>
</li>
<li>
<a href="#interpolate_line">Interpolate of a Rotated Line</a>
</li>
<li>
<a href="#interpolate_edge">Interpolate of a Rotate Edge</a>
</li>
</ul>
</dd>
<dd>
<a href="#virtual-pixel"><img src="../img_www/granitesm_right.gif" border="0" width="15" height="15"> Virtual Pixels</a> <font size="-1">(Missed-Image Color Lookups)</font>
<ul>
<li><font size="-1"><a href="#edge">Edge</a>, <a href="#tile">Tile</a>, <a href="#mirror">Mirror</a>, <a href="#transparent">Transparent</a>, <a href="#black">Black</a>, <a href="#gray">Gray</a>, <a href="#white">White</a>, <a href="#background">Background</a>, <br>
<a href="#horizontal_tile">HoriziontalTile</a>, <a href="#horizontal_edge">HoriziontalTileEdge</a>, <a href="#vertical_tile">VerticalTile</a>, <a href="#vertical_edge">VerticalTileEdge</a>, <br>
<a href="#checker_tile">CheckerTile</a>, <a href="#random">Random</a>, <a href="#dither">Dither</a></font></li>
<li>
<a href="#virtual_infinities">Virtual Pixel and Infinities</a>
</li>
<li>
<a href="#virtual_colors">Virtual Pixel Colors</a>
</li>
<li>
<a href="#virtual_examples">Virtual Pixel Examples</a>
</li>
<li>
<a href="#virtual_implode">Implosion Effects on Virtual Pixels</a>
</li>
</ul>
</dd>
<dd>
<a href="#spots"><img src="../img_www/granitesm_right.gif" border="0" width="15" height="15"> Random Spots of Solid Color</a>
</dd>
<dd>
<a href="#annotate"><img src="../img_www/granitesm_right.gif" border="0" width="15" height="15"> Annotate Argument Usage</a> <img src="../img_www/space.gif" width="20" height="1">
</dd>
<dd>
<a href="#splice"><img src="../img_www/granitesm_right.gif" border="0" width="15" height="15"> Splice: Creating a New Image Operator</a>
</dd>
<dd>
<a href="#border"><img src="../img_www/granitesm_right.gif" border="0" width="15" height="15"> Border, Frame, and the use of BorderColor</a>
</dd>
<dd>
<a href="#list_test"><img src="../img_www/granitesm_right.gif" border="0" width="15" height="15"> List Operator Testing</a>
</dd>
</dl>This page consists of examples which test various aspects of ImageMagick. But which do not properly fit into the discussions on the other example pages (at least not formally). Also included on this page are some tables demonstrating the results of versions argument with specific IM operators. However other people have also done this, which unless I have something to add, I will not deal with further.
<hr>
<!-- ---------------------------------------------------------------- -->
<a name="interpolate" id="interpolate"></a>
<h2>Pixel Interpolation <font size="-2">or Inter-pixel Color Lookup</font></h2>The "<code><a href="https://imagemagick.org/script/command-line-options.php?#interpolate">-interpolate</a></code>" setting is used when looking up a color in a source image, but that 'lookup point' falls between the pixels of the source image. This is done in various image operations, such as the "<code><a href="https://imagemagick.org/script/command-line-options.php?#fx">-fx</a></code>" (<a href="../transform/#fx">DIY Special Effects Operator</a>), and "<code><a href="https://imagemagick.org/script/command-line-options.php?#distort">-distort</a></code>" (<a href="../distorts/#distort">Generalized Image Distortion Operator</a>), as well as other related operators like the <a href="../warping/#circular">Circular Distortions</a>. Basically 'interpolation' tells IM how to interpret a <a href="../distorts/#lookup">Direct Color Lookup</a> from an image, when the point does not exactly match an actual pixel in an image, but falls in the space between pixels. For example if you look up the color at pixel location <code>3,4</code> you should get the exact pixel color. But what should IM return if you looked up the color of an image at the point <code>3.23,4.75</code>? Should you get the pixel color at <code>3,4</code> or <code>3,5</code>? or perhaps some a mix of the surrounding pixels colors, and if so how should the colors be merged together? <b><i>Pixel Interpolation</i> defines what ImageMagick should do when looking up a single color at a floating point position (in pixel coordinates).</b> Interpolation is in some ways similar to pixel resampling, such as provided by <a href="../filter/#filter">Resampling Filters</a>. The essentual difference is that resampling has a 'scale', 'area' or variable 'window' from which a color that represents all the pixels in the area is returned. Interpolation does not have a 'scale' involved, only a single 'point' of lookup, and only a fixed sized 'area' around that point from which to determine the color to use at that point. Of course most area resampling algorithms tend to devolve to an interpolative method when the area of resampling reaches a minimim working 'window', and this naturally happens when images are being enlarged, or upsampled. This is why <a href="../filter/#interpolated">Interpolated Filters</a> and <a href="filter/#gaussian">Gaussian Blurring Filters</a> tend to work better for enlarging images. Interpolation is basically a lower form of sampling, and is basically used when you want a simple and fast answer to the 'what color' question. <a name="integer" id="integer"></a> <a name="nearest" id="nearest"></a> <a name="nearest-neighbor" id="nearest-neighbor"></a> <a name="blend" id="blend"></a> <a name="average" id="average"></a> <a name="average9" id="average9"></a> <a name="average16" id="average16"></a> <a name="interpolate_simple" id="interpolate_simple"></a>
<h3>Simple Interpolation Methods</h3>These are straight forward, simple methods, that try to do as lettl as posible to return a color to use from a 'point interpolation' The simplest is '<b><code>Nearest</code></b>' and '<b><code>Integer</code></b>', will just pick a single pixel color from the source image, as it without any mixing or other blending effects. This preserves original color values of the image but at a cost of aliasing effects, and typically a less than smooth look to images.
<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>As of IM v6.7.6-2 you can use '<code>Nearest</code>' as a short hand for the '<code>Nearest-Neighbour</code>' interpolation setting.</i></font></td>
</tr>
</table>The two are very similar, only differing in which pixel the lookup coordinate extracts from the source image. Specifically '<code>Integer</code>' will simply round down the lookup point to select the pixel, which results in a general translation half a pixel right and downward. It is typically only used in simplified 'scaling' of the source image. On the other hand '<code>Nearest</code>' will select the closest pixel to the floating point lookup coordinate, and as such produces a more correct result.'<b><code>Blend</code></b>' Will blend together (average) the nearest 1, 2 or 4 pixels, depending on their distance from the sampling point. The result is that the original pixel color is still present, but halved in size, while a checkerboard of blended colors fills space between. (see example below) '<b><code>Average</code></b>', will never actually produce an exact color match, but will always mix the 4 surrounding pixels to produce a local average. This can be useful for color lookup situations. '<code>Average4</code>' can also be used an an alias for this interpolation method. '<b><code>Average9</code></b>' is similar but will average the nearest 9 pixels around the sampling point, producing a blurry result. '<b><code>Average16</code></b>' will average the nearest 16 pixels around the sampling point, producing an extrememly blurry result. Here is a summery of the various simple interpolation methods, when enlarging a small group of colored pixels, or a single white pixel. The original image looks like the "Nearest" result, but much smaller.
<div align="center">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="90%" bgcolor="#F8F8F8">
<tr>
<td>
<pre><code execute="" script="">
for method in integer nearest blend average average9 average16 ; do
magick \( xc:red xc:blue +append \) \
\( xc:yellow xc:cyan +append \) -append \
-bordercolor black -border 1 \
-filter point -interpolate $method \
+distort SRT 20,0 ip_color_${method}.jpg
magick xc: -bordercolor black -border 2 \
-filter point -interpolate $method \
+distort SRT 16,0 ip_pixel_${method}.jpg
done
</code></pre>
</td>
</tr>
</table>
<table cellspacing="10">
<tr>
<td>
<a href="ip_color_integer.jpg"><img src="ip_color_integer.jpg" align="middle" vspace="2" hspace="2" border="1" alt="[IM Output]"></a>
</td>
<td>
<a href="ip_color_nearest.jpg"><img src="ip_color_nearest.jpg" align="middle" vspace="2" hspace="2" border="1" alt="[IM Output]"></a>
</td>
<td>
<a href="ip_color_blend.jpg"><img src="ip_color_blend.jpg" align="middle" vspace="2" hspace="2" border="1" alt="[IM Output]"></a>
</td>
<td>
<a href="ip_color_average.jpg"><img src="ip_color_average.jpg" align="middle" vspace="2" hspace="2" border="1" alt="[IM Output]"></a>
</td>
<td>
<a href="ip_color_average9.jpg"><img src="ip_color_average9.jpg" align="middle" vspace="2" hspace="2" border="1" alt="[IM Output]"></a>
</td>
<td>
<a href="ip_color_average16.jpg"><img src="ip_color_average16.jpg" align="middle" vspace="2" hspace="2" border="1" alt="[IM Output]"></a>
</td>
</tr>
<tr>
<td>
<a href="ip_pixel_integer.jpg"><img src="ip_pixel_integer.jpg" align="middle" vspace="2" hspace="2" border="1" alt="[IM Output]"></a>
</td>
<td>
<a href="ip_pixel_nearest.jpg"><img src="ip_pixel_nearest.jpg" align="middle" vspace="2" hspace="2" border="1" alt="[IM Output]"></a>
</td>
<td>
<a href="ip_pixel_blend.jpg"><img src="ip_pixel_blend.jpg" align="middle" vspace="2" hspace="2" border="1" alt="[IM Output]"></a>
</td>
<td>
<a href="ip_pixel_average.jpg"><img src="ip_pixel_average.jpg" align="middle" vspace="2" hspace="2" border="1" alt="[IM Output]"></a>
</td>
<td>
<a href="ip_pixel_average9.jpg"><img src="ip_pixel_average9.jpg" align="middle" vspace="2" hspace="2" border="1" alt="[IM Output]"></a>
</td>
<td>
<a href="ip_pixel_average16.jpg"><img src="ip_pixel_average16.jpg" align="middle" vspace="2" hspace="2" border="1" alt="[IM Output]"></a>
</td>
</tr>
<tr>
<th>Integer</th>
<th>Nearest</th>
<th>Blend</th>
<th>Average</th>
<th>Average9</th>
<th>Average16</th>
</tr>
</table>
</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>Before IM v6.7.7-6 '<code>Average</code>' was actually equivalent to which is now '<code>Average16</code>'. The other two averging interpolators as well as '<code>Blend</code>', and '<code>Background</code>' was added at this time.</i></font></td>
</tr>
</table><a name="background_ic" id="background_ic"></a> One other simple interpolation method is also provided, '<b><code>Background</code></b>' which simply returns the current background color for any 'sampling' of the source image. In many ways this is rather usless, as typically you will just end up with a blank solid colored image. Its primary use is as a check of more complex resampling functions, such as a <a href="../distorts/#distort_failure">Resampling Failure</a>, where the EWA resampling filter (typically used from the <a href="../distorts/#distort">General Distortion Operator</a>) will fall back to an interpolated lookup when resampling fails to find any pixels in its 'support' or resampling area. By setting interpolation to '<code>Background</code>', and setting a background color to something that stands out (like '<code>red</code>') you can then look for pixels in the resulting image to see where resampling 'failed' or 'missed all source image pixels' for some reason or another. Typically due to too small a support setting, or from playing with expert filter options. <i>FUTURE: Possible future interpolation option of "random" selection over the interpolated area. Could be useful for fancy interpolated effects!</i> <a name="bilinear" id="bilinear"></a>
<h3>Bilinear</h3>'<b><code>Bilinear</code></b>' (or linear interpolation) is the <b>default interpolation method</b>, and probably one of the simplest ways of getting a real interpolated result, from combining colors of the pixels around the lookup or sampling point. Here is a diagram explaining how a bilinear interpolation works.
<div align="center"><img src="../img_diagrams/bilinear_interpolation.jpg" width="370" height="211" align="middle" vspace="5" hspace="5" border="0" alt="[diagram]"></div>That is, to say, it simply connects striaght lines in the orthogonal directions to locate the color of the given sampling point. The result is also equivelent to a <a href="../filter/#triangle">Triangle Resampling Filter</a>, when used with resize.
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<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 \( xc:red xc:blue +append \) \
\( xc:yellow xc:cyan +append \) -append \
-size 100x100 xc: +swap -fx 'v.p{i/(w-1),j/(h-1)}' \
interpolate_bilinear.jpg
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="interpolate_bilinear.jpg"><img src="interpolate_bilinear.jpg" width="100" height="100" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td>
</tr>
</table><!--
#Distort equivelent -- two point affine of pixel centers
# This is a bit more complex and harder to explain!
magick \( xc:red xc:blue +append \) \
\( xc:yellow xc:cyan +append \) -append \
-filter point -interpolate bilinear \
-define distort:viewport=100x100 \
-distort Affine '.5,.5 .5,.5 1.5,1.5 99.5,99.5' \
interpolate_bilinear.jpg
-->
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<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 \( xc:white xc:black +append \) \
\( xc:black xc:white +append \) -append \
-size 100x100 xc: +swap -fx 'v.p{i/(w-1),j/(h-1)}' \
interpolate_saddle.jpg
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="interpolate_saddle.jpg"><img src="interpolate_saddle.jpg" width="100" height="100" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td>
</tr>
</table>This last image shows how a linear gradient is formed along the edges between the four known points, and then a second linear gradient is formed between those edges. That is, the colors between the surrounding pixels is generated using a horizontal and vertical linear gradients. This inturn produces a curved 2 dimensional gradient that is typically known as a 'saddle', in that it is rasied on two oppisite corners and lowered on the other two corners. You can even use this method to more directly generate a 45 degree angled linear gradient, but requires you to specify the middle color for the diagonally opposite corners.
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<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 \( xc:blue xc:navy +append \) \
\( xc:navy xc:black +append \) -append \
-size 100x100 xc: +swap -fx 'v.p{i/(w-1),j/(h-1)}' \
interpolate_45linear.jpg
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="interpolate_45linear.jpg"><img src="interpolate_45linear.jpg" width="100" height="100" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td>
</tr>
</table>The most important aspect of this default interpolation method, is that the very center pixel of the image will always be an average of all four corner colors, with perfect linear gradients at the edges, and exact color matching at the corners. <a name="mesh" id="mesh"></a>
<h3>Mesh</h3>The "<code><a href="https://imagemagick.org/script/command-line-options.php?#interpolate">-interpolate</a></code>" setting of '<code>Mesh</code>' is a variation of the '<code><a href="#bilinear">Bilinear</a></code>' interpolation. Where as '<code>Bilinear</code>' will produce a 3 dimensional curved surface, '<code>Mesh</code>' was designed to split the inter-pixel area into two flat triangular surfaces. The division of the area into two triangles is based on the diagonal with the two 'closest' corner colors.
<table border="0" cellspacing="0" cellpadding="0" width="90%" align="center">
<tr valign="top">
<td><img src="../img_www/expert.gif" width="23" height="26"><img src="../img_www/space.gif" width="17" height="16"></td>
<td align="justify" width="100%"><font size="-1"><i>For details of the '<code>Mesh</code>' algorithm, see the paper <a href="http://www.cs.bath.ac.uk/~pjw/Q3D/forum-ddt.pdf">Image Interpolation by Pixel-Level Data-Dependent Triangulation</a>.</i></font></td>
</tr>
</table>For example lets use the same set of corner colors we used above.
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<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 \( xc:red xc:blue +append \) \
\( xc:yellow xc:cyan +append \) -append \
-size 100x100 xc: +swap -interpolate Mesh \
-fx 'v.p{i/(w-1),j/(h-1)}' interpolate_tri-mesh.jpg
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="interpolate_tri-mesh.jpg"><img src="interpolate_tri-mesh.jpg" width="100" height="100" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td>
</tr>
</table>As you can see the '<code>Mesh</code>' algorithm produced almost exactly the same set of color interpolations as '<code><a href="#bilinear">Bilinear</a></code>'. However if we reverse the yellow and cyan colors..
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<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 \( xc:red xc:blue +append \) \
\( xc:cyan xc:yellow +append \) -append \
-size 100x100 xc: +swap -interpolate Mesh \
-fx 'v.p{i/(w-1),j/(h-1)}' interpolate_tri-mesh2.jpg
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="interpolate_tri-mesh2.jpg"><img src="interpolate_tri-mesh2.jpg" width="100" height="100" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td>
</tr>
</table>This time the '<code>Mesh</code>' algorithm decided that the '<code>blue</code>' and '<code>cyan</code>' colors were the two closest corners, and created a linear gradient diagonally between these two corners. The rest of the colors then form a simple flat triangular gradient from this line to the other two corners. This may seem like an unusual interpolation, but the method ensures that sharp borders, remain quite sharp, when color images are only slightly resized, rotated or sheared. In fact a <a href="../resize/#adaptive-resize">Adaptive Resize</a> operation ("<code><a href="https://imagemagick.org/script/command-line-options.php?#adaptive-resize">-adaptive-resize</a></code>") uses this fact for small image resizes to reduce excessive blurring of the result. For example if we have a single 'white' corner, '<code>mesh</code>' assumes that an edge has been found and adjusts the interpolated colors to highlight this edge.
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<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 \( xc:black xc:black +append \) \
\( xc:white xc:black +append \) -append \
-size 100x100 xc: +swap -interpolate Mesh \
-fx 'v.p{i/(w-1),j/(h-1)}' interpolate_tri-mesh3.jpg
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="interpolate_tri-mesh3.jpg"><img src="interpolate_tri-mesh3.jpg" width="100" height="100" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td>
</tr>
</table>Of course if the colors produce reasonably consistent gradient the 'mesh' interpolation also produces a reasonably consistent gradient.
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<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 \( xc:blue xc:navy +append \) \
\( xc:black xc:black +append \) -append \
-size 100x100 xc: +swap -interpolate Mesh \
-fx 'v.p{i/(w-1),j/(h-1)}' interpolate_tri-mesh4.jpg
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="interpolate_tri-mesh4.jpg"><img src="interpolate_tri-mesh4.jpg" width="100" height="100" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td>
</tr>
</table>As you can see the result quite a reasonable gradient, though if you look hard you can see the diagonal join of the two separate triangles. The change isn't as smooth as bi-linear (which isn't exactly smooth either) but these do not try to preserve the sharp edges in resized or distorted images either. <a name="bicubic" id="bicubic"></a> <a name="catrom" id="catrom"></a>
<h3>Catrom (Catmull-Rom)</h3>The "<code><a href="https://imagemagick.org/script/command-line-options.php?#interpolate">-interpolate</a></code>" setting of '<code>Catrom</code>' (generally imprecisely known as '<code>BiCubic</code>' interpolation), is more complex, in the determination of the colors of a point lookup. Basically it does not just look at the colors in the corners of the inter-pixel area, but goes further to look at the colors beyond those nearest-neighbour pixels. A total of 16 pixels in a 4x4 area around the sampling point. Basically it fits a curve to the whole area involved, so as to determine the best overall color to use. Here is a diagram which probably explains the process better...
<div align="center"><img src="../img_diagrams/bicubic_interpolation.jpg" width="400" height="211" align="middle" vspace="5" hspace="5" border="0" alt="[diagram]"></div>And here is the interpolated colors for our standard four colors.
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<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 \( xc:red xc:blue +append \) \
\( xc:yellow xc:cyan +append \) -append \
-size 100x100 xc: +swap -interpolate Catrom \
-fx 'v.p{i/(w-1),j/(h-1)}' interpolate_catrom.jpg
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="interpolate_catrom.jpg"><img src="interpolate_catrom.jpg" width="100" height="100" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td>
</tr>
</table>The above image may look very similar to a '<code><a href="#bilinear">Bilinear</a></code>' interpolation, however the result has a smoother blending curve rather than straight lines to produce the interpolated color. What this image does not show however is the effect of the other pixels surrounding our four near neighbours. For that we need to look at a slightly larger area. For this specific (very small) example the surrounding pixels are controled by the <a href="#virtual">Virtual Pixel</a> setting.
<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 \( xc:red xc:blue +append \) \
\( xc:yellow xc:cyan +append \) -append \
-size 100x100 xc: +swap -interpolate Catrom -virtual-pixel edge \
-fx 'v.p{3*i/(w-1)-1, 3*j/(h-1)-1}' interpolate_catrom_edge.jpg
magick \( xc:red xc:blue +append \) \
\( xc:yellow xc:cyan +append \) -append \
-size 100x100 xc: +swap -interpolate Catrom -virtual-pixel White \
-fx 'v.p{3*i/(w-1)-1, 3*j/(h-1)-1}' interpolate_catrom_white.jpg
magick \( xc:red xc:blue +append \) \
\( xc:yellow xc:cyan +append \) -append \
-size 100x100 xc: +swap -interpolate Catrom -virtual-pixel Black \
-fx 'v.p{3*i/(w-1)-1, 3*j/(h-1)-1}' interpolate_catrom_black.jpg
</samp></pre>
</td>
</tr>
</table><a href="interpolate_catrom_edge.jpg"><img src="interpolate_catrom_edge.jpg" width="100" height="100" align="middle" vspace="2" hspace="15" border="1" alt="[IM Output]"></a> <a href="interpolate_catrom_white.jpg"><img src="interpolate_catrom_white.jpg" width="100" height="100" align="middle" vspace="2" hspace="15" border="1" alt="[IM Output]"></a> <a href="interpolate_catrom_black.jpg"><img src="interpolate_catrom_black.jpg" width="100" height="100" align="middle" vspace="2" hspace="15" border="1" alt="[IM Output]"></a>
</div>
<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>In a real image the effects of the <a href="#virtual">Virtual Pixels</a> usually only effects results near the very edges of the image. As this image is only 2 pixels wide, the above example is strongly effected. This is not the case in larger more typical images.</i></font></td>
</tr>
</table>As you can see the curve is strongly influenced by the surrounding colors, resulting in either a very tight sharp color change, or a more blended color change as defined by the surrounding colors. However you can also see that strong changes in the surrounding pixel colors, can produce a small areas of that colors inverse or negative. This is a <a href="../filter/#ringing">Ringing Artefact</a> and is typically only seen on extremely sharp edges of complementary colors in a real image.
<table border="0" cellspacing="0" cellpadding="0" width="90%" align="center">
<tr valign="top">
<td><img src="../img_www/expert.gif" width="23" height="26"><img src="../img_www/space.gif" width="17" height="16"></td>
<td align="justify" width="100%"><font size="-1"><i>This ringing effect on very very strong color edges can become clipped resulting in a line of horrible pixels. This problem can be prevented by doing resizes and interpolation in a different colorspace than '<code>RGB</code>', such as '<code>Lab</code>' or '<code>Luv</code>' colorspaces.<br>
<br>
For more information and examples of this problem see <a href="../resize/#resize_lab">Resizing in LAB colorspace</a>.<br>
<br></i></font></td>
</tr>
</table>
<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>Note that '<code>BiCubic</code>' (interpolated <a href="../filter/#cubics">Cubic Filter</a>), refers to a very large family of filters, and as such is very inexact in its meaning. It is however still available, but its use is depreciated, in favor of more exact names.<br>
<br>
After IM v6.7.7-7 '<code>BiCubic</code>' is simply an alias to '<code>Catrom</code>', which is typically regarded as a good 'cubic interpolator' (b=0, c=1/2). You should use the name '<code>Catrom</code>' rather than '<code>BiCubic</code>' so as to be clear what you are using for interpolation.<br>
<br>
Before IM v6.7.7-7 '<code>BiCubic</code>' actually used an extreme 'Cardinal Cubic' filter (b=0, c=1) which has an overly strong negative ringing effect. This have been completely replaced by '<code>Catrom</code>', and is no longer available as an interpolative function.<br>
<br>
Before IM v6.3.5-3 '<code>BiCubic</code>' was implemented as a very blurry '<code>Spline</code>' cubic interpolator. That filter was renamed with this version of ImageMagick. (see next)<br>
<br></i></font></td>
</tr>
</table><a name="spline" id="spline"></a>
<h3>Spline</h3>The '<code>Spline</code>' interpolation method, like '<code><a href="#catrom">Catrom</a></code>' above, also uses the nearest 16 pixels. However this is a very blurry, Gaussian-like, interpolation.
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<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 \( xc:red xc:blue +append \) \
\( xc:yellow xc:cyan +append \) -append \
-size 100x100 xc: +swap -interpolate spline \
-fx 'v.p{i/(w-1),j/(h-1)}' interpolate_spline.jpg
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="interpolate_spline.jpg"><img src="interpolate_spline.jpg" width="100" height="100" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td>
</tr>
</table>As you can see the colors in the very corners of the above '<code>Spline</code>' interpolation are muted, as the interpolated surface does not actually go through the original color of those pixels. Essentially it is overly 'blurred', and is more correctly known as a 'B-Spline' surface. The surface is still a type of <a href="../filter/#cubics">Cubic Filter</a> (b=1, c=0) as it generated using a technique of a piece-wise cubic curves. However this curve only approaches the original pixel colors, especially in areas of strong color changes. That is, an interpolated lookup of an exact integer pixel position, will not return that actual pixels color, but a blurring of the color with the surrounding pixels. This is often thought of as bad, but can be used as a general smoothing function. Like '<code><a href="#catrom">Catrom</a></code>' it is also effected by the surrounding pixels.
<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 \( xc:red xc:blue +append \) \
\( xc:yellow xc:cyan +append \) -append \
-size 100x100 xc: +swap -interpolate Spline -virtual-pixel edge \
-fx 'v.p{3*i/(w-1)-1, 3*j/(h-1)-1}' interpolate_spline_edge.jpg
magick \( xc:red xc:blue +append \) \
\( xc:yellow xc:cyan +append \) -append \
-size 100x100 xc: +swap -interpolate Spline -virtual-pixel White \
-fx 'v.p{3*i/(w-1)-1, 3*j/(h-1)-1}' interpolate_spline_white.jpg
magick \( xc:red xc:blue +append \) \
\( xc:yellow xc:cyan +append \) -append \
-size 100x100 xc: +swap -interpolate Spline -virtual-pixel Black \
-fx 'v.p{3*i/(w-1)-1, 3*j/(h-1)-1}' interpolate_spline_black.jpg
</samp></pre>
</td>
</tr>
</table><a href="interpolate_spline_edge.jpg"><img src="interpolate_spline_edge.jpg" width="100" height="100" align="middle" vspace="2" hspace="15" border="1" alt="[IM Output]"></a> <a href="interpolate_spline_white.jpg"><img src="interpolate_spline_white.jpg" width="100" height="100" align="middle" vspace="2" hspace="15" border="1" alt="[IM Output]"></a> <a href="interpolate_spline_black.jpg"><img src="interpolate_spline_black.jpg" width="100" height="100" align="middle" vspace="2" hspace="15" border="1" alt="[IM Output]"></a>
</div>
<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>In a real image the effects of the <a href="#virtual">Virtual Pixels</a> is only at the edges of the image. With real pixels surrounding the inter-pixel area from which the lookup is being made.</i></font></td>
</tr>
</table>Here you can see the effects of the color muting that results from the badly fitting 'spline' curves to the pixel colors. The results is generally fuzzier edges to colored areas, and thin lines. However they also will never exhibit any negative 'ringing' effect that you may get with a '<code><a href="#catrom">Catrom</a></code>' interpolation. <a name="interpolate_bgnd" id="interpolate_bgnd"></a>
<h3>Interpolation Background</h3>As the effects of interpolation are often over larger areas, here is an enlargement of the four main interpolation methods with white or black surrounding pixels.
<div align="center">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="90%" bgcolor="#F8F8F8">
<tr>
<td>
<pre><code execute="" script="">
for method in bilinear mesh catrom spline ; do
for vpixel in white black ; do
magick \( xc:red xc:blue +append \) \
\( xc:yellow xc:cyan +append \) -append \
-size 100x100 xc: +swap -interpolate $method -virtual-pixel $vpixel \
-fx 'v.p{3*i/(w-1)-1, 3*j/(h-1)-1}' ip_area_${method}_$vpixel.jpg
done
done
</code></pre>
</td>
</tr>
</table>
<table cellspacing="10">
<tr>
<td>
<a href="ip_area_bilinear_white.jpg"><img src="ip_area_bilinear_white.jpg" width="100" height="100" align="middle" vspace="2" hspace="2" border="1" alt="[IM Output]"></a>
</td>
<td>
<a href="ip_area_mesh_white.jpg"><img src="ip_area_mesh_white.jpg" width="100" height="100" align="middle" vspace="2" hspace="2" border="1" alt="[IM Output]"></a>
</td>
<td>
<a href="ip_area_catrom_white.jpg"><img src="ip_area_catrom_white.jpg" width="100" height="100" align="middle" vspace="2" hspace="2" border="1" alt="[IM Output]"></a>
</td>
<td>
<a href="ip_area_spline_white.jpg"><img src="ip_area_spline_white.jpg" width="100" height="100" align="middle" vspace="2" hspace="2" border="1" alt="[IM Output]"></a>
</td>
</tr>
<tr>
<td>
<a href="ip_area_bilinear_black.jpg"><img src="ip_area_bilinear_black.jpg" width="100" height="100" align="middle" vspace="0" hspace="2" border="1" alt="[IM Output]"></a>
</td>
<td>
<a href="ip_area_mesh_black.jpg"><img src="ip_area_mesh_black.jpg" width="100" height="100" align="middle" vspace="0" hspace="2" border="1" alt="[IM Output]"></a>
</td>
<td>
<a href="ip_area_catrom_black.jpg"><img src="ip_area_catrom_black.jpg" width="100" height="100" align="middle" vspace="0" hspace="2" border="1" alt="[IM Output]"></a>
</td>
<td>
<a href="ip_area_spline_black.jpg"><img src="ip_area_spline_black.jpg" width="100" height="100" align="middle" vspace="0" hspace="2" border="1" alt="[IM Output]"></a>
</td>
</tr>
<tr>
<th>Bilinear</th>
<th>Mesh</th>
<th>Catrom</th>
<th>Spline</th>
</tr>
</table>
</div>As you can see the surrounding background color has no real effect for '<code><a href="#bilinear">bilinear</a></code>' interpolated colors. It looks like it is just overlaid onto whatever background color is present. You can however see how '<code><a href="#mesh">mesh</a></code>' generates stronger sharper edges, but can decide to flip the diagonal depending on the surrounding color, when it is involved at the image edges. Look at the join between red and blue, between the white and black backgrounds to see this 'flip'. The interpolated curve for '<code><a href="#catrom">catrom</a></code>' and '<code><a href="#spline">spline</a></code>' is effected by the surrounding pixels. Particularly in the test cases involving absolute colors. And finally '<code><a href="#spline">spline</a></code>' interpolation is really just gussian-like blurring of the image (using a sigma of 0.65). Enough blurring to eliminate any 'ringing' or aliasing effect, though typically it is too blurry for most uses. See <a href="../filter/#gaussian">Gaussian Filters</a>. <a name="interpolate_line" id="interpolate_line"></a>
<h3>Interpolation of a Rotated Line</h3>Here I demonstrate the various interpolation methods by creating an image of a vertical line, and using an affine distortion to rotate the line by 17 degrees, then enlarging the view so you can see the anti-aliasing pixels generated.
<div align="center">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="90%" bgcolor="#F8F8F8">
<tr>
<td>
<pre><code execute="" script="">
magick -size 10x20 xc: -draw 'line 4,0 4,20' \
-scale 50x100 ip_line_none.gif
for method in integer nearest bilinear mesh catrom spline; do
magick -size 10x20 xc: -draw 'line 5,0 5,20' \
-interpolate $method -filter point -distort SRT 17 \
-scale 50x100 ip_line_${method}.gif
done
</code></pre>
</td>
</tr>
</table>
<table cellspacing="10">
<tr valign="top">
<th>
<a href="ip_line_none.gif"><img src="ip_line_none.gif" width="50" height="100" align="middle" vspace="5" hspace="2" border="1" alt="[IM Output]"></a><br>
Un-Rotated
</th>
<th><img src="../img_www/right.gif" width="20" height="20" align="middle" vspace="50" hspace="0" alt="==>"></th>
<th>
<a href="ip_line_integer.gif"><img src="ip_line_integer.gif" width="50" height="100" align="middle" vspace="5" hspace="2" border="1" alt="[IM Output]"></a><br>
Integer
</th>
<th>
<a href="ip_line_nearestneighbor.gif"><img src="ip_line_nearestneighbor.gif" width="50" height="100" align="middle" vspace="5" hspace="2" border="1" alt="[IM Output]"></a><br>
Nearest
</th>
<th>
<a href="ip_line_bilinear.gif"><img src="ip_line_bilinear.gif" width="50" height="100" align="middle" vspace="5" hspace="2" border="1" alt="[IM Output]"></a><br>
Bilinear
</th>
<th>
<a href="ip_line_mesh.gif"><img src="ip_line_mesh.gif" width="50" height="100" align="middle" vspace="5" hspace="2" border="1" alt="[IM Output]"></a><br>
Mesh
</th>
<th>
<a href="ip_line_catrom.gif"><img src="ip_line_catrom.gif" width="50" height="100" align="middle" vspace="5" hspace="2" border="1" alt="[IM Output]"></a><br>
Catrom
</th>
<th>
<a href="ip_line_spline.gif"><img src="ip_line_spline.gif" width="50" height="100" align="middle" vspace="5" hspace="2" border="1" alt="[IM Output]"></a><br>
Spline
</th>
</tr>
</table>
</div>As you can see the direct color lookup methods '<code>Interger</code>' and '<code>NearestNeighbor</code>' produces a highly aliased result, but only use the original colors found in the image. The main difference between the two is that '<code>Interger</code>' tends to push the resulting image down and left by half a pixel. The '<code>Bilinear</code>', '<code>Mesh</code>' and '<code>Catrom</code>' generally produce very good and simular results (more on that later), with the latter producing a very sharp rotated line. Any of these is generally regarded as a good solution. The '<code>Spline</code>' interpolation methods, produces a distinct blurring of thin lines, so as to remove aliasing effects. However '<code>Spline</code>' tends to over blur the results, and really more suited to smoothing gradients, rather than rotated lines.
<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 special setting "<code><a href="#filter">-filter</a> point</code>" is in the above example is used to ensure that <a href="../distorts/#distort">Distort Operator</a> only uses single 'point' interpolation in determining the final pixel color. Without it an <a href="../distorts/#area_resample">Area Resampling</a> be used instead of <a href="../distorts/#lookup">Interpolated Lookup</a>, though that also produces very good results.</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>Note that I did not use the "<code><a href="https://imagemagick.org/script/command-line-options.php?#rotate">-rotate</a></code>" operator for these examples, as that operator uses a Pixel Shearing method to <a href="../warping/#rotate">Rotate</a> Images. As a result pixel interpolation is not used.<br>
<br>
See <a href="../warping/#rotate_line">Rotating a Thin Line</a> for an example of using the <code><a href="https://imagemagick.org/script/command-line-options.php?#rotate">-rotate</a></code>" operator in this way, and the resulting pixel level effects.<br>
<br>
Update: As of IMv6.7.3-4 the rotate operator is now internally using <a href="../distorts/#distort">Distort Operator</a>, so the above many no longer be true.<br>
<br></i></font></td>
</tr>
</table><a name="interpolate_edge" id="interpolate_edge"></a>
<h3>Interpolation of a Rotated Edge</h3>The results have a slight difference when the edge of an area is being distorted, compared to that of a single line of pixels.
<div align="center">
<table class="table table-sm table-hover table-striped" cellspacing="0" cellpadding="5" width="90%" bgcolor="#F8F8F8">
<tr>
<td>
<pre><code execute="" script="">
magick -size 10x20 xc: -draw 'rectangle 0,0 4,19' \
-scale 50x100 ip_edge_none.gif
for method in integer nearest bilinear mesh catrom spline; do
magick -size 10x20 xc: -draw 'rectangle 0,0 4,19' \
-interpolate $method -filter point -distort SRT -17 \
-scale 50x100 ip_edge_${method}.gif
done
</code></pre>
</td>
</tr>
</table>
<table cellspacing="10">
<tr valign="top">
<th>
<a href="ip_edge_none.gif"><img src="ip_edge_none.gif" width="50" height="100" align="middle" vspace="5" hspace="2" border="1" alt="[IM Output]"></a><br>
Un-Rotated
</th>
<th><img src="../img_www/right.gif" width="20" height="20" align="middle" vspace="50" hspace="0" alt="==>"></th>
<th>
<a href="ip_edge_integer.gif"><img src="ip_edge_integer.gif" width="50" height="100" align="middle" vspace="5" hspace="2" border="1" alt="[IM Output]"></a><br>
Integer
</th>
<th>
<a href="ip_edge_nearestneighbor.gif"><img src="ip_edge_nearestneighbor.gif" width="50" height="100" align="middle" vspace="5" hspace="2" border="1" alt="[IM Output]"></a><br>
Nearest
</th>
<th>
<a href="ip_edge_bilinear.gif"><img src="ip_edge_bilinear.gif" width="50" height="100" align="middle" vspace="5" hspace="2" border="1" alt="[IM Output]"></a><br>
Bilinear
</th>
<th>
<a href="ip_edge_mesh.gif"><img src="ip_edge_mesh.gif" width="50" height="100" align="middle" vspace="5" hspace="2" border="1" alt="[IM Output]"></a><br>
Mesh
</th>
<th>
<a href="ip_edge_catrom.gif"><img src="ip_edge_catrom.gif" width="50" height="100" align="middle" vspace="5" hspace="2" border="1" alt="[IM Output]"></a><br>
Catrom
</th>
<th>
<a href="ip_edge_spline.gif"><img src="ip_edge_spline.gif" width="50" height="100" align="middle" vspace="5" hspace="2" border="1" alt="[IM Output]"></a><br>
Spline
</th>
</tr>
</table>
</div>The above generally speaks for itself. '<code>Bilinear</code>' and '<code>Mesh</code>' produce reasonably sharp edges for general rotates, while '<code>Catrom</code>' will produce a sharper edge in the distorted image. '<code>Spline</code>' however will produce fuzzier edges. The difference between '<code>Bilinear</code>' and '<code>Mesh</code>' is extremely minor in the above cases. The two methods only really generate visible differences in cases of extreme enlargement during the distortion operation. Otherwise you will only see slight barely noticeable changes in pixel intensity.<br>
<hr>
<!-- ---------------------------------------------------------------- -->
<a name="virtual-pixel" id="virtual-pixel"></a> <a name="virtual_pixel" id="virtual_pixel"></a> <a name="virtual" id="virtual"></a>
<h2>Virtual Pixels <font size="-2">Missed Image Color Lookup</font></h2>Many operators often need to look-up colors which fall outside the boundaries of the image proper. This includes the operators for <a href="../blur/#blur">Blurring Images</a>, <a href="../distorts/#distort">General Image Distortion</a>, <a href="../morphology/">Morphological and Convolution Operators</a>, the <a href="../distorts/#distort">General Distortion Operator</a>, and even the very old <a href="../warping/#implode">Implosion Operator</a>. So what color should be returned if you ask for a pixel at <code>-22,-3</code>? Such a pixel does not actually exist, but the color value returned can have far reaching effects on the overall effect on your image processing, especially the resulting colors of pixels close to the actual edge of the image. The "<code><a href="https://imagemagick.org/script/command-line-options.php?#virtual-pixel">-virtual-pixel</a></code>" setting defines what IM should return when accessing a pixel outside the normal bounds of the image. <a href="../images/tree.gif"><img src="../images/tree.gif" width="32" height="32" align="right" vspace="0" hspace="5" border="1" alt="[IM Output]"></a> For example, here we use the <a href="../transform/#fx">FX DIY Operator</a> "<code><a href="https://imagemagick.org/script/command-line-options.php?#fx">-fx</a></code>" to 'lookup' and display all the pixels in and surrounding the small image so we can see what the <b>default</b> "<code><a href="https://imagemagick.org/script/command-line-options.php?#virtual-pixel">-virtual-pixel</a></code>" setting returned.
<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: tree.gif \
-fx 'v.p[-19,-19]' virtual_default.gif
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="virtual_default.gif"><img src="virtual_default.gif" width="70" height="70" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td>
</tr>
</table><a name="edge" id="edge"></a> '<b><code>Edge</code></b>' "<code><a href="https://imagemagick.org/script/command-line-options.php?#virtual-pixel">-virtual-pixel</a></code>" setting return the color of the the closest real pixel to the 'virtual' location requested. That is, theneaered 'edge' color. This time I'll use a faster <a href="../distorts/#distort_viewport">Image Distortion with viewport</a> to show the surrounding virtual pixels, instead of the much slower <a href="../transform/#fx">FX Operator</a>. The distort method "SRT 0" does not actually distort the image result, it just looks at what pixels the image operator actual sees, especially the 'virtual' ones surrounding the source image.
<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 tree.gif -set option:distort:viewport 70x70-19-19 \
-virtual-pixel Edge -filter point -distort SRT 0 \
+repage virtual_edge.gif
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="virtual_edge.gif"><img src="virtual_edge.gif" width="70" height="70" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td>
</tr>
</table><!-- <CODE EXECUTE ASSERT>
[ "`compare -metric PAE virtual_{default,edge}.gif null: 2>&1 |
sed 's/ .*//'`" != '0' ] && echo >&2 \
"ASSERTION FAILURE: Default Virtual Pixel setting is NOT 'edge'\!"
</CODE> -->
An '<code>Edge</code>' virtual pixel setting is the default setting, so the above should be the same as the previous example. This setting generally has the most minimal impact (in terms of edge effects) when processing images. Which is also why it was chosen as the default setting. This is especially important when using <a href="../blur/#blur">Blur</a>, or other <a href="../morphology/">Morphological and Convolution</a> operators that use a 'neighbourhood' or pixels for processing. It is important to note how the color of the corner pixel, will end up completely filling the diagonally adjacent areas surrounding the actual image. This can result in the single corner pixel having a large effect on various image transformations. This 'corner' effect is especially noticeable when blurring images. <a name="tile" id="tile"></a> '<b><code>Tile</code></b>' VP setting is very useful for generating and ensuring the image processing edge effects are wrapped around the boundaries of the image.
<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 tree.gif -set option:distort:viewport 70x70-19-19 \
-virtual-pixel Tile -filter point -distort SRT 0 \
+repage virtual_tile.gif
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="virtual_tile.gif"><img src="virtual_tile.gif" width="70" height="70" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td>
</tr>
</table>This lets you ensure that images being worked on remain 'tileable', or become more 'tileable' as the image is modified. For further examples see <a href="../canvas/#tile_mod">Modifying Tile Images</a>. <a name="mirror" id="mirror"></a> '<b><code>Mirror</code></b>' is very similar to '<code><a href="#tile">tile</a></code>' and may be better for some effects that the default '<code><a href="#edge">edge</a></code>'.
<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 tree.gif -set option:distort:viewport 70x70-19-19 \
-virtual-pixel Mirror -filter point -distort SRT 0 \
+repage virtual_mirror.gif
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="virtual_mirror.gif"><img src="virtual_mirror.gif" width="70" height="70" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td>
</tr>
</table>This is particularly useful to reduce the edge and corner effect of images that are being blurred. However it can also generate other effects.
<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>Up until IM v6.5.0-1 only the images directly attached to the original image was mirrored. Other virtual copies, further away from the original remained un-mirrored (normal tile pattern). This was fixed so the whole virtual canvas space is now correctly mirror tiled, not just the neighbouring virtual copies.<br>
<br>
It only becomes important when using mirror tile with <a href="../distorts/#distort">General Distortion Operator</a> to mirror tile a very large area, such as when <a href="../distorts/#horizon">Viewing Distant Horizons</a></i></font></td>
</tr>
</table><a name="transparent" id="transparent"></a> '<b><code>Transparent</code></b>' just returns the transparent color for pixels outside the real image bounds.
<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 tree.gif -alpha set -set option:distort:viewport 70x70-19-19 \
-virtual-pixel Transparent -filter point -distort SRT 0 \
+repage virtual_trans.gif
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="virtual_trans.gif"><img src="virtual_trans.gif" width="70" height="70" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td>
</tr>
</table>The <a href="../basics/#alpha">Alpha 'set' Operator</a> in the above is required to ensure the image has a matte or alpha channel for the transparent color to fill in correctly. Without this setting the above could return a 'black' color instead of transparent, as the color '<code>none</code>' or 'fully-transparent black' is the default transparent color. For example, here I mistakenly turn off transparency...
<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 tree.gif -alpha off -set option:distort:viewport 70x70-19-19 \
-virtual-pixel Transparent -filter point -distort SRT 0 \
+repage virtual_trans2.gif
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="virtual_trans2.gif"><img src="virtual_trans2.gif" width="70" height="70" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td>
</tr>
</table>The '<code>Transparent</code>' setting is particularly useful for image distortions, where the distorted image will later be 'layered' to build up larger images. For example, <a href="../distorts/#cube3d">3d Affine Cubes</a>, and <a href="../distorts/#cube3d">3d Perspective Boxes</a>. <a name="black" id="black"></a> <a name="white" id="white"></a> <a name="gray" id="gray"></a> The '<b><code>white</code></b>', '<b><code>gray</code></b>', and '<b><code>black</code></b>', settings are similar to the previous '<code>Transparent</code>' setting above. They just return that specific color for any pixel that falls out of bounds.
<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 tree.gif -alpha off -set option:distort:viewport 70x70-19-19 \
-virtual-pixel White -filter point -distort SRT 0 \
+repage virtual_white.gif
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="virtual_white.gif"><img src="virtual_white.gif" width="70" height="70" align="middle" vspace="0" hspace="5" border="1" 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 tree.gif -alpha off -set option:distort:viewport 70x70-19-19 \
-virtual-pixel Gray -filter point -distort SRT 0 \
+repage virtual_gray.gif
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="virtual_gray.gif"><img src="virtual_gray.gif" width="70" height="70" align="middle" vspace="0" hspace="5" border="1" 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 tree.gif -alpha off -set option:distort:viewport 70x70-19-19 \
-virtual-pixel Black -filter point -distort SRT 0 \
+repage virtual_black.gif
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="virtual_black.gif"><img src="virtual_black.gif" width="70" height="70" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td>
</tr>
</table><a name="background" id="background"></a> If you want any other simple color , then you must define that color in the "<code><a href="https://imagemagick.org/script/command-line-options.php?#background">-background</a></code>" setting, and use a '<b><code>Background</code></b>' "<code><a href="https://imagemagick.org/script/command-line-options.php?#virtual-pixel">-virtual-pixel</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 tree.gif -set option:distort:viewport 70x70-19-19 \
-virtual-pixel Background -background coral \
-filter point -distort SRT 0 +repage virtual_bgnd.gif
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="virtual_bgnd.gif"><img src="virtual_bgnd.gif" width="70" height="70" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td>
</tr>
</table><br>
<a name="horizontal_tile" id="horizontal_tile"></a> '<b><code>HorizontalTile</code></b>' VP setting was added to IM v6.4.2-6 as a special form of tiling that is useful for full 360 degree "<code><a href="../distorts/#arc">Arc</a></code>" and "<code><a href="../distorts/#polar">Polar</a></code>" distortions. The image is only tiled horizontally, while the virtual pixels above and below the tiles are set from the current "<code><a href="https://imagemagick.org/script/command-line-options.php?#background">-background</a></code>" 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 class="bg-light text-dark mx-4"><samp>
magick tree.gif -set option:distort:viewport 70x70-19-19 \
-virtual-pixel HorizontalTile -background coral \
-filter point -distort SRT 0 +repage virtual_horizontal.gif
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="virtual_horizontal.gif"><img src="virtual_horizontal.gif" width="70" height="70" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td>
</tr>
</table>This lets you ensure that images being transformed remain 'tileable' horizontally. For further examples see <a href="../canvas/#tile_mod">Modifying Tile Images</a>. <a name="horizontal_edge" id="horizontal_edge"></a> The '<b><code>HorizontalTileEdge</code></b>' (added in IM v6.5.0-1) also tiles the image horizontally across the virtual space, but replicates the side edge pixels across the other parts of the virtual canvas space.
<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 tree.gif -set option:distort:viewport 70x70-19-19 \
-virtual-pixel HorizontalTileEdge -background coral \
-filter point -distort SRT 0 +repage virtual_horizontal_edge.gif
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="virtual_horizontal_edge.gif"><img src="virtual_horizontal_edge.gif" width="70" height="70" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td>
</tr>
</table>These two VP methods were added for better handling of full circle '<code><a href="../distorts#arc">Arc</a></code>' and '<code><a href="../distorts#polar">Polar</a></code>' distortions where the en-circled image 'wraps around' and joins together end to end.<br>
<a name="vertical_tile" id="vertical_tile"></a> Simularly the '<b><code>VerticalTile</code></b>' VP setting (also added IM v6.4.2-6, for completeness) as a tiles the image vertially only, with the current "<code><a href="https://imagemagick.org/script/command-line-options.php?#background">-background</a></code>" color used to fill in the sides of the image.
<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 tree.gif -set option:distort:viewport 70x70-19-19 \
-virtual-pixel VerticalTile -background coral \
-filter point -distort SRT 0 +repage virtual_vertical.gif
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="virtual_vertical.gif"><img src="virtual_vertical.gif" width="70" height="70" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td>
</tr>
</table><a name="vertical_edge" id="vertical_edge"></a> The '<b><code>VerticalTileEdge</code></b>' was added in IM v6.5.0-1, and replicates the side edge pixels across the rest of the virtual canvas space.
<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 tree.gif -set option:distort:viewport 70x70-19-19 \
-virtual-pixel VerticalTileEdge -background coral \
-filter point -distort SRT 0 +repage virtual_vertical_edge.gif
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="virtual_vertical_edge.gif"><img src="virtual_vertical_edge.gif" width="70" height="70" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td>
</tr>
</table><a name="checker_tile" id="checker_tile"></a> In IM v6.5.0-1 '<b><code>CheckerTile</code></b>' was added to tile an image as if filling in a checkerboard pattern. The other squares are simply filled with the background color (which may be transparent).
<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 tree.gif -set option:distort:viewport 70x70-19-19 \
-virtual-pixel CheckerTile -background coral \
-filter point -distort SRT 0 +repage virtual_checker.gif
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="virtual_checker.gif"><img src="virtual_checker.gif" width="70" height="70" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td>
</tr>
</table>By making background transparent and overlaying that image over an another fully-tiled image same size you can layer the two tilings to produce an interleaved checkerboard pattern of the two 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 96x96 tile:balloon.gif \
\( tree.gif -alpha set -set option:distort:viewport 96x96 \
-virtual-pixel CheckerTile -background none \
-filter point -distort SRT 0 \) \
-flatten virtual_checker_2.gif
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="virtual_checker_2.gif"><img src="virtual_checker_2.gif" width="96" height="96" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td>
</tr>
</table><br>
There also a couple of more unusual "<code><a href="https://imagemagick.org/script/command-line-options.php?#virtual-pixel">-virtual-pixel</a></code>" settings. <a name="random" id="random"></a> '<b><code>random</code></b>', just picks a random pixel from the image to use.
<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 tree.gif -set option:distort:viewport 70x70-19-19 \
-virtual-pixel Random -filter point -distort SRT 0 \
+repage virtual_random.gif
</samp></pre>
</td>
</tr>
</table>
</td>
<td>
<a href="virtual_random.gif"><img src="virtual_random.gif" width="70" height="70" align="middle" vspace="0" hspace="5" border="1" alt="[IM Output]"></a>
</td>
</tr>
</table>This is often used with "<code><a href="https://imagemagick.org/script/command-line-options.php?#blur">-blur</a></code>" to generate rough mottled average image color in the resulting edge effects it produces. Note that the pixel value is not consistant, and will produce a different effect for each lookup, and even each run of the operation, unless the random number generator is given an initial "<code><a href="https://imagemagick.org/script/command-line-options.php?#seed">-seed</a></code>". This is especially bad when used with <a href="../convolve">Convolution</a> or <a href="../morphology">Morphology</a> image processing, as the each lookup along the edge of the image will contribute a different value even though the same pixel lookup was used. I have however found the random pattern to be very good when generating a <a href="../distorts/#horizon">Perspective Horizion</a> as the pattern shows a more blurred result as you get closer to the horizon. The bluring gives the the resulting random texture a depth that would otherwise not be visible if using a simple solid color.<br>
<a name="dither" id="dither"></a> '<b><code>dither</code></b>' however returns an ordered dithered pattern of colors basied on pixels within 32x32 pixels of the requested position.
<table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">
<tr valign="bottom">
<td width="100%" align="justify">
That means that once you have progressed beyond 32 pixels from the image, the result will be again just the corner pixel color of the image. It is a bit like a merger of '<code><a href="#edge">edge</a></code>' and '<code><a href="#random">random</a></code>'.
<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 tree.gif -set option:distort:viewport 120x120-44-44 \
-virtual-pixel Dither -filter point -distort SRT 0 \
+repage virtual_dither.gif