-
Notifications
You must be signed in to change notification settings - Fork 0
/
gmic_scripts
1651 lines (1485 loc) · 60.4 KB
/
gmic_scripts
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
#@gmic
#
# File : proudot.gmic
# ( G'MIC commands file )
#
# Description : Define a set of gmic commands (mostly useful for bioimage analysis)
#
# Copyright : Philippe Roudot (forked from Jerome Boulanger gmic file)
#
# License : CeCILL v2.0
# ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html )
#
# This software is governed by the CeCILL license under French law and
# abiding by the rules of distribution of free software. You can use,
# modify and/ or redistribute the software under the terms of the CeCILL
# license as circulated by CEA, CNRS and INRIA at the following URL
# "http://www.cecill.info".
#
# As a counterpart to the access to the source code and rights to copy,
# modify and redistribute granted by the license, users are provided only
# with a limited warranty and the software's author, the holder of the
# economic rights, and the successive licensors have only limited
# liability.
#
# In this respect, the user's attention is drawn to the risks associated
# with loading, using, modifying and/or developing or reproducing the
# software by the user in light of its specific status of free software,
# that may mean that it is complicated to manipulate, and that also
# therefore means that it is reserved for developers and experienced
# professionals having in-depth computer knowledge. Users are therefore
# encouraged to load and test the software's suitability as regards their
# requirements in conditions enabling the security of their systems and/or
# data to be ensured and, more generally, to use and operate it in the
# same conditions as regards security.
#
# The fact that you are presently reading this means that you have had
# knowledge of the CeCILL license and that you accept its terms.
#
#---------------------------------
#
#@gmic :: Input/Output
#
#---------------------------------
#@gmic tiff3d
#@gmic : Input a 3D tif as a 3D image
#@gmic : Note: This is useful for loading several 3D image stack
tiff3d : -e[^-1] "Load the file $1 as a 3D image"
-v - n=$!
-i $1 -a[{$n}--1] z
-v +
#@gmic toff3d
#@gmic : Output a 3D tif as a 3D image
toff3d : -e[^-1] "Save the 3D image as a tiff file"
-v -
-repeat $!
-o[$>] @{"-filename \"$1\","$>}
-done
-v +
#---------------------------------
#
#@gmic :: 3D Rendering
#
#---------------------------------
#@gmic boundingbox3d : _separation
#@gmic : Bounding box of a 3D volume
#@gmic : $ 100,100,100 -boundingbox3d
boundingbox3d : -skip ${1=10}
-e[^-1] "3D Bounding box"
-repeat $! -l[$>]
-box3d @{0,w},@{0,h},@{0,d} -primitives3d[-1] 1 -opacity3d[-1] .25
-if {$1>0}
-plane3d @{0,w},@{0,h},$1,{round(@{0,h}/@{0,w}*$1)} -primitives3d[-1] 1 -opacity3d[-1] .1
-endif
-rm[0]
-+3d
-endl -done
#@gmic rendervolume : _size,_quality,_opacity
#@gmic : Pseudo volumic rendering
#@gmic : $ 100,100,100 -noise 1 -blur 10,0 -max 0 -resize 100%,100%,100%,3,0 -n 0,100 -f 'if(c==0,z*i(x,y,z,0),if(c==1,i(x,y,z,0)*(100-z),0))' -rendervolume
rendervolume: -skip ${1=8},${2=5},${3=.1}
-e[^-1] "Pseudo volumic rendering of image with size $1 quality $2 and opactiy $3"
-v - -repeat $! -l[$>]
-mirror x
-repeat $2 --l[0]
--threshold2 {($>+1)/($2+1)*(iM-im)+im},{($>+2)/($2+1)*(iM-im)+im+1}
-*[-2,-1]
-if {im!=iM} -pointcloud3d -gaussians3d $1,{$3*($<+1)/$2} -else -rm -endif
-endl -done -rm[0] -+3d -md3d -1 -+3d {.5},{.5},{.5}
-endl -done -v +
rendervolume2: -skip ${1=8},${2=5},${3=.1}
-v - -repeat $! -l[$>]
-mirror x
--tones {$2+1} -rm[1,2] -r[1--1] 100%,100%,100%,@{0,s} -*[1--1] [0] -rm[0]
-reverse
-repeat $! i=$< -l[$<]
-if {im!=iM}
-pointcloud3d -gaussians3d $1,{$3*($i+1)/$2}
-else
-rm
-endif
-endl -done
-+3d -md3d -1 -+3d {.5},{.5},{.5}
-endl -done -v +
freq3d: -split_details 5 -rm[-1] -isosurface3d 50% -repeat $! -l[$>] -color3d {255/$>},100,{$>*70},{($>+1)*0.1} -endl -done -add3d -moded3d 4 -mode3d 4 800,600 -d3d[-2] [-1]
tone3d: -resize 50%,50%,200%,100%,3 -n 1,256 --tones 5 -*[1--1] [0] -rm[0,1] -pointcloud3d -gaussians3d[0] 10,0.1 -gaussians3d[1] 10,0.1 -gaussians3d[2] 10,0.2 -gaussians3d[3] 10,0.5 -+3d -md3d 4 800,600 -d3d[-2] [-1]
otsusurface: -- ${--otsu} -rm[-1] -isosurface3d 0
scalesurface: -split_details 3 -rm[-1] -repeat $! -l[$>] -otsusurface -opacity3d {($>+1)*0.2} -endl -done -color3d[-1] 255,0,0 -add3d -moded3d 4
#@gmic displayvolume : _size,_quality,_opacity
#@gmic : Display the volume with black background, a bounding box and a volumic rendering of the data
#@gmic : $ 100,100,100 -noise 1 -blur 10,0 -max 0 -resize 100%,100%,100%,3,0 -n 0,100 -f 'if(c==0,z*i(x,y,z,0),if(c==1,i(x,y,z,0)*(100-z),0))' -displayvolume 8,5,.1
displayvolume: -skip ${1=8},${2=5},${3=.1}
-e[^-1] "display_volume with size $1 quality $2 and opactiy $3"
-v -
--boundingbox3d 20
-rendervolume2[0] $1,$2,$3
-+3d
-background3d 0,0,0
-v +
#@gmic view3d : _angle1,_angle2
#@gmic : Apply a 3D view
#@gmic : $ 50,50,50,3 -noise 10 -blur 5 -max 0 -n 0,255 -displayvolume 32,5,1 -view3d
view3d : -skip ${1=25},${2=-120}
-e[^-1] "Apply 3D view"
-v - -repeat $! -l[$>]
-rotate3d 0,0,1,$1 -rotate3d 1,0,0,$2
-endl -done -v +
#@gmic colordepth
#@gmic : Color depth coding
#@gmic : $ 100,100,100 -noise 1 -blur 10,0 -max 0 -colordepth 5
colordepth: -skip ${1=5}
-e "colordepth coding with lut $1"
-v - -repeat $! -l[$>]
-_colordepth_volume $1 -s z -+
-endl -done -v +
#@gmic colordepth_volume
_colordepth_volume: -skip ${1=5}
-v - -repeat $! -l[$>]
# make a 3D volume of the same size, color it, resize orignal in color and multiply
-i [0] -f[-1] 'z/(d-1)*255' -map[-1] $1 -resize[0] 100%,100%,100%,3 -*
-endl -done -v +
colordepth_scale: -skip ${1=5}
10,@{0,h-10} -f[-1] '(h-y)/(h-1)*255' -map[-1] $1 -frame[-1] 5,5,0,0,0
#@gmic make_axis: _xmin,_xmax,_ymin,_ymax
#@gmic : Display an axis around an image
#@gmic : $ image.jpg -make_axis 0,1,0,1
make_axis:
-v - -repeat $! -l[$>]
-frame 1,1,0
100%,24,1,3,255 -axes[-1] $1,$2,{-1},{-1}
24,@{0,h},1,3,255 -axes[-1] {w},{w},$4,$3 24,24,1,3,255 -a[-1,-2] y
-a[0,1] y -reverse -a[0,1] x
-frame 12,12,255 100%,5,1,3,255,255,255 -reverse -a y
-endl -done -v +
#@gmic xlabel: _label
#@gmic : Add a label to the x-axis (see make_axis)
#@gmic : $ image.jpg -make_axis 0,1,0,1 -xlabel "hello"
xlabel:
-e[^-1] "Add a x label"
-v - -repeat $! -l[$>]
0 -text[-1] "$1",0,0,18,1,255,255,255 -negative[-1] --lt[-1] 90%
-image[0] [-2],{@{0,w}/2-@{1,w}/2},{@{0,h}-@{1,h}},0,0,1,[-1] -k[0]
-endl -done -v +
#@gmic ylabel: _label
#@gmic : Add a label to the y-axis (see make_axis)
#@gmic : $ image.jpg -make_axis 0,1,0,1 -ylabel "hello"
ylabel:
-e[^-1] "Add a y label"
-v - -repeat $! -l[$>]
0 -text[-1] "$1",0,0,18,1,255,255,255 -negative[-1] -rotate[-1] -90 --lt[-1] 90% -image[0] [-2],0,{@{0,h}/2-@{1,h/2}},0,0,1,[-1] -k[0]
-endl -done -v +
#@gmic title: _label
#@gmic : Add a title (see make_axis)
#@gmic : $ image.jpg -make_axis 0,1,0,1 -ylabel "hello" -title "title"
title:
-e[^-1] "Add a title"
-v - -repeat $! -l[$>]
0 -text[-1] "$1",0,0,18,1,255,255,255 -negative[-1] --lt[-1] 90%
-image[0] [-2],{@{0,w}/2-@{1,w}/2},0,0,0,1,[-1] -k[0]
-endl -done -v +
mip : -s z -max
orthoMIP : -e "orthoMIP" -v -
-repeat $! -l[$>]
--l[0] s x max permute zyxc -endl --l[0] s y max permute xzyc endl -l[0] s z max -endl -montage VH0:1:2,0
-endl -done -v +
orthoMIPn:
-repeat $! -l[$>]
ff={0,f} fb={0,b} orthoMIP text $ff$fb,5%,5%,23,1,{iM}
-endl -done
liveMIP:
-w -apply_files $1,"-a z orthoMIPn -n 0,255"
#---------------------------------
#
#@gmic :: Feature detections
#
#---------------------------------
cellMaskOtsu : -b 5 -otsu 256
cellMaskOtsu2 : -b 10 -otsu 256 -area 0 -threshold {iM} -not inpaint_holes 10
fakeNucleusMask : -b 10 -otsu 256 -area 0 -threshold {iM} -distance 1 -threshold {iM-10}
debugMaskFunctionSpy: -e "debug function $1"
-repeat $! -l[$>]
--$1 --distance[-1] 0 --orthoMIP -adjust_colors[-2] 10,10,50 -normalize [0] -a[-2,-1] x
-endl -done
debugMaskFunction: -e "debug function $1"
-repeat $! -l[$>]
--$1 --distance[-1] 0 -orthoMIP -adjust_colors[0] 10,10,50 -normalize [0] -a x
-endl -done
#@gmic quiver2d
#@gmic : Display a sequence 2D vector field on a 2D image sequence
#@gmic : both being represented az a 3D stack
quiver2d:
-e[^-1] "Cumulative sum along z-axis"
-s z -repeat {$!/2} -l[$>,{$>+$!/2}] -quiver[0] [1] -endl -done -rm[{$!/2}--1] -a z
#@gmic zcumsum
#@gmic : Cumulative sum along z-axis
#@gmic : $ 20,20,20 -noise 10 -zcumsum
zcumsum:
-e[^-1] "Cumulative sum along z-axis"
-v - -repeat $! -l[$>]
-s z -repeat {$!-1} -+[{$>+1}] [$>] -done -a z
-v + -endl -done
#@gmic warp2d :
#@gmic : Warp a 2D image stack using a vector field
#@gmic : $ movie.cimg -a z -resize 50%,50% --l[0] --lucas_kanade 5,1 -zcumsum[-1] -frame 30,30,0 -warp2d -endl -frame[0] 30,30,0 -a x
warp2d:
-s z -repeat {$!/2} -l[$>,{$>+$!/2}] -warp[0] [1],1,1,2 -endl -done -rm[{$!/2}--1] -a z
#@gmic lucas_kanade: _scale
#@gmic : Motion estimation using lucas and kanade approach
#@gmic : Works on 2D+t image stacks/ has side effect
#@gmic : [vx vy] = [Ixx Ixy; Ixy Iyy]^-1 [Ixt Iyt]
#@gmic : $ image.jpg -repeat 20 --shift[-1] 1,0,0,0,2 -done -a z --lucas_kanade 2 -n 0,255 -frame 2 -a x
#@gmic : $ image.jpg -repeat 20 --shift[-1] 1,1,0,0,2 -done -a z --lucas_kanade 2 -s z -repeat {$!/2} -l[$>,{$>+$!/2}] -quiver[0] [1] -endl -done -rm[{$!/2}--1] -a z
lucas_kanade: -skip ${1=2},${2=1}
-e[^-1] "Motion estimation with Lucas et Kanade algorithm"
-v - -repeat $! -l[$>]
-blur_xy $2 -structuretensors 0 -blur_xy $1 # abcdef
--l -s c -rm[0,-1] -*[1,2] -*[0,2] -reverse -- -endl # dc-be
--l[0] -s c -rm[3,5] -*[0,3] -*[1,2] -- -endl # ae-bc
-l[0] -s c -rm[2,4,5] -*[0,2] -sqr[1] -- -endl # ad-b2
-/[1,2] [0] -rm[0] -a c
-endl -done -v +
#@gmic estimate_shift
#@gmic : Estimate a translation between two images with sub-pixel accuray
#@gmic : image.jpg -luminance --shift {?},{?},0,0,2 -estimate_shift
estimate_shift:
-e[^-1] "Translation estimation with Lucas et Kanade algorithm"
-v - -repeat {$!-1} -l[$>,{$>+1}]
-blur_xy 1 --gradient[0] xy,0 --[0,1] --sqr[1,2] --*[1,2] [0] -*[1,2] -rm[0]
Ixy=@{0,ia} Ixx=@{1,ia} Iyy=@{2,ia} Ixt=@{3,ia} Iyt=@{4,ia}
vx={($Iyy*$Ixt-$Ixy*$Iyt)/($Ixx*$Iyy-$Ixy*$Ixy)}
vy={($Ixx*$Iyt-$Ixy*$Ixt)/($Ixx*$Iyy-$Ixy*$Ixy)}
#-echo_stdout $vx,$vy
-rm 1,2 -f $vx,$vy
-endl -done -v +
#@gmic multi_resolution_pyramide : _number_of_scales
#@gmic : Build a multi-resolution pyramid
multi_resolution_pyramide:
-v - -repeat $! -l[$<]
-repeat {$1-1} --resize[-1] 50%,50% -done -reverse
-endl -done -v +
#@gmic estimate_shift_mr
#@gmic : Estimate a translations between two images with sub-pixel accuray
#@gmic : using a multi-resolution scheme
#@gmic : $ image.jpg -luminance --shift 2,3 -crop 5%,5%,95%,95% -estimate_shift_mr 3
estimate_shift_mr: -skip ${1=2}
-multi_resolution_pyramide $1
1,2
-repeat {$1-1}
--estimate_shift[$>,{$1+$>}] -*[-1,-2] -2 -+[-1,-2]
@{{$>+1},w},@{{$>+1},h},1,2 -f[-1] 'if(c==0,@{-2,i(0)},@{-2,i(0,1)})'
-warp[{$1+$>+1}] [-1],1,1,1 -rm[-1] -*[-1] -1
-done
-k[-1]
#@gmic unshift : _iterations
#@gmic : Correct drift along Z in a 3D volume (video stabilization)
#@gmic : Use the linearized optical flow constraint iteratively
#@gmic : $ image.jpg -luminance -repeat 10 --shift[-1] {2*?},{2*?},0,0,2 -done -a z --unshift 20 -a x
unshift: -skip ${1=10}
-e[^-1] "unshift image stack"
-repeat $! -l[$>]
-repeat $1
-s z -repeat {$!-1} -l[$>,{$>+1}]
--estimate_shift_mr 5 -*[-1] -1 vx=@{2,i(0)} vy=@{2,i(0,1)}
#-echo_stdout $vx,$vy
@{0,w},@{0,h} -f[-1] $vx --f[-1] $vy -a[-1,-2] c
-warp[1] [-1],1,2,1 -rm[-1,-2]
-endl -done -a z
-done
-endl -done
#@gmic register_lucas_kanade : _iterations, _scale
#@gmic : Register images using lucas kanade motion estimation
#@gmic : $ movie.cimg -luminance -resize 50%,50% -a z -register_lucas_kanade 5,10
register_lucas_kanade : -skip ${1=10},${2=10}
--lucas_kanade $2 -zcumsum[-1] --warp2d
-repeat $1
-lucas_kanade[-1] $2 -zcumsum[-1] -+[-1,-2] --warp2d
-done
#@gmic detect_events : _scale_xy,_scale_t,_threshold
#@gmic : Detect space time events using space time interest points
#@gmic : $ 100,100,100 -noise 1 -blur 2 --detectevents , -pointscoordinates[-1] -resize[0] 100%,100%,100%,3,1 -n[0] 0,255 -circles 5,.5,128,128,32 -k[0]
detectevents : -skip ${1=1},${2=1},${3=9}
-e[^-1] "detect events with scale_xy $1 scale_z $2 and threshold $3"
-v - -repeat $! -l[$>]
-blur_xy $1 -blur_z $2 -structuretensors -blur_xy $1 -blur_z $2
-s z -repeat $! -l[$>] -eigen -k[0] -s c -k[2] -endl -done -a z
thres={@{0,ia}+$3*sqrt(@{0,iv})}
--max_patch[0] 8 -threshold[0] $thres -*
-endl -done -v +
#@gmic detect_spots : _scale,_threshold
#@gmic : Detect spots in the image
#@gmic : $ 100,100 -noise .2,2 -blur 1 -n 0,255 -noise 5 --detect_spots , -pointscoordinates[-1] -resize[0] 100%,100%,1,3,1 -circles 5,.5,128,128,32 -k[0]
detect_spots : -skip ${1=1},${2=4}
-e[^-1] "detect events with scale $1 and threshold $2"
-v - -repeat $! -l[$>]
-blur $1 --blur $1 --
thres={$2*${-mad[0]}}
-d --max_patch[0] 3 --threshold[0] $thres -d -*
-endl -done -v +
#@gmic local_moments : _scale
#@gmic : Compute local moments tensor
#@gmic : $ 512,512 -circle 50%,50%,25%,1,0xF,255 --local_moments 1
local_moments : -skip ${1=1}
-v - -repeat $! -l[$>]
-norm
-if {d==1}
--mul[0] 'x' --mul[0] 'y' --mul[0] 'x*x'
--mul[0] 'x*y' --mul[0] 'y*y' -blur $1
--sqr[1] -/[-1] [0] --[3,-1] -/[3] [0]
--*[1,2] -/[-1] [0] --[4,-1] -/[4] [0]
--sqr[2] -/[-1] [0] --[5,-1] -/[5] [0]
-k[3-5] -a c
-else
--mul[0] 'x' --mul[0] 'y' --mul[0] 'z' --mul[0] 'x*x'
--mul[0] 'x*y' --mul[0] 'x*z' --mul[0] 'y*y' --mul[0] 'y*z'
--mul[0] 'z*z' -blur $1
--sqr[1] -/[-1] [0] --[4,-1] -/[4] [0]
--*[1,2] -/[-1] [0] --[5,-1] -/[5] [0]
--*[1,3] -/[-1] [0] --[6,-1] -/[6] [0]
--sqr[2] -/[-1] [0] --[7,-1] -/[7] [0]
--*[2,3] -/[-1] [0] --[8,-1] -/[8] [0]
--sqr[3] -/[-1] [0] --[9,-1] -/[9] [0]
-k[4-9] -a c
-endif
-endl -done -v +
#@gmic smooth_moments : _scale,_iterations,_dt
#@gmic : Anisotropic diffusion using local moment tensors
#@gmic : $ image.jpg --noise 10 --smooth_moments[-1] 1,10,1 -print_psnr
smooth_moments: -check "${1=1}>0&${2=100}>0&${3=1}>0"
-v - -repeat $! -l[$>]
--local_moments[-1] $1 -smooth[0] [1],$2,$3,0 -k[0]
-endl -done -v +
#@gmic pointscoordinates
#@gmic : Return the list of points in the image as 3*N columns vector
#@gmic : $ 100,100 -noise .1,2 --pointscoordinates
pointscoordinates :
-e[^-1] "return the list of points in the image"
-v - -repeat $! -l[$>]
-pointcloud3d -s3d -k[2] -split y,{h/3} -a x
-endl -done -v +
pair_distance:
-repeat $! -l[$>] -s y -a c -endl -done
-repeat @{1,w}
--l[0,1]
-shift[1] $>,0,0,0,2
-- -norm
-endl
-done
-rm[0,1]
-a y
-s x -repeat $! -shift[$>] 0,$>,0,0,2 -done -a x
#@gmic circles : _size,_opacity,_color
#@gmic : plot circles on image [0] at coordinates given by image [1]
#@gmic : $ 256,256 -noise .1,2 --pointscoordinates --circles 5 -rm[-1]
#@gmic : $ image.jpg --l[0] -blur 3 -structuretensors -blur 3 -eigen -k[0] -channels 1 --gt {9*@{-mad}} --max_patch[0] 8 -* -pointscoordinates -endl -circles 5 -rm[-1]
circles : -skip ${1=10},${2=1},${3=255},${4=255},${5=255}
-e[^-1] "draw @{1,w} circles on image [0]"
-v -
-repeat {@{1,w}}
-if {@{0,d}>1}
x={@{1,i($>,0)}} y={@{1,i($>,1)}} z={@{1,i($>,2)}}
-repeat @{0,s} -sh[0] $z,$z,$> -ellipse[-1] $x,$y,$1,$1,0,$2,0xFFFFFF,$3 -rm[-1] -done
-else
x=@{1,i($>,0)} y=@{1,i($>,1)}
-ellipse[0] $x,$y,$1,$1,0,$2,0xFFFFFF,$3,$4,$5
-endif
-done
#@gmic addtext : _size,_color,_opacity
#@gmic : Add labels on image [0] at coordinates given by image [1]
#@gmic : $ 256,256 -noise .1,2 --pointscoordinates -addtext 5 -rm[-1]
addtext : -skip ${1=21},${2=128},${3=1}
-e[^-1] "add text labels from @{1,w} points"
-v -
-repeat {@{1,w}}
-if {@{0,d}>1}
x={@{1,i($>,0)}} y={@{1,i($>,1)}} z={@{1,i($>,2)}} id={$>+1}
-repeat @{0,s} -sh[0] $z,$z,$> -text[-1] $id,$x,$y,21,$3,$2,$2,$2 -rm[-1] -done
-else
x=@{1,i($>,0)} y=@{1,i($>,1)} id={$>+1}
-text[0] $id,$x,$y,21,$3,$2,$2,$2
-endif
-done
#@gmic croparound : _size_xy,_size_z
#@gmic : Crop image [0] around coordinates given by image [1]
#@gmic : $ image.jpg 100%,100% -f[-1] 0 -noise[-1] .1,2 --pointscoordinates[-1] --croparound[0,-1] 5 -append_tiles[3--1] , -rm[-2] -dilate[1] 5 -*[1] 128 -blend[0,1] add
croparound : -skip ${1=10},${2=10}
-e[^-1] "crop image [0] around "@{1,w}" coordinates given by image [1]"
-v -
-repeat {@{1,w}}
-if {@{0,d}>1}
x=@{1,i($>,0)} y=@{1,i($>,1)} z=@{1,i($>,2)}
--crop[0] {$x-$1},{$y-$1},{$z-$2},{$x+$1},{$y+$1},{$z+$2}
-else
x=@{1,i($>,0)} y=@{1,i($>,1)}
--crop[0] {$x-$1},{$y-$1},{$x+$1},{$y+$1}
-endif
-done -rm[0,1] -v +
#@gmic random_walks : width,height,length,number,speed
#@gmic : Generate random walks tracks (list of coordinates x,y,t as a Nx3 image.)
#@gmic : $ 100,100,20 -random_walks 100,100,20,5,1 -circles 1 -k[0] -blur_xy 1 -s z -max
#@gmic : $ 100,100,20 -random_walks 100,100,20,10,1 -circles 1 -k[0] -blur 1 -n 0,255 -displayvolume 8,10,1 -rotate3d 0,0,1,25 -rotate3d 1,0,0,-120 -snapshot3d 600,1,0,0,0 -autocrop
random_walks :
number=$4 width=$1 height=$2 length=$3 speed=$5
$number,3
-l[-1]
-noise 1,1
-sh 0,0,0,0 -n[-1] 1,{$width-1} -rm[-1]
-sh 1,1,0,0 -n[-1] 1,{$height-1} -rm[-1]
-sh 2,2,0,0 -f[-1] 0 -rm[-1]
-repeat {$length-1} --l[-1]
-noise 1
-sh 0,0,0,0 -c[-1] 1,{$width-2} -rm[-1]
-sh 1,1,0,0 -c[-1] 1,{$height-2} -rm[-1]
-sh 2,2,0,0 -f[-1] '$>+1' -rm[-1]
-endl -done -a x
-endl
#---------------------------------
#
#@gmic :: Filtering and deconvolution
#
#---------------------------------
#@gmic movavg : _size>=1
#@gmic : moving average of image list with a box filter of size _size
#@gmic : $ 11 -f 'x>w/2' --l[-1] -s x -movavg 9 -a x -endl --blur[0] 1.2 -a c -display_graph
movavg : -check "$1>=1"
-e[^-1] "moving average with size "$1 -v -
n={$1-1}
-repeat $n
-repeat {{$!}-1} --+[{$>},{$>+1}] -*[-1] .5 -rm[$>] -mv[-1] $> -done
-reverse
-done
-if {$n%2!=0} -reverse -endif
-v +
#@gmic zmean
#@gmic : average along z-axis
zmean :
-v - -repeat $! -l[$>]
n=@{0,d} -s z -+ -/ $n
-endl -done -v +
#@gmic zstd
#@gmic : standard deviation along z-axis
zstd :
-v - -repeat $! -l[$>]
--zmean -sqr[-1]
-l[0] -sqr -zmean -endl
-- -sqrt
-endl -done -v +
#@gmic zmax
#@gmic : maximum along z-axis
zmax :
-v - -repeat $! -l[$>]
-s z -max
-endl -done -v +
#@gmic kymoline:
#@gmic : interactively select a line and extract a line profile
kymoline:
--select 1
x1=@{-1,i(0,0)} y1=@{-1,i(0,1)} x2=@{-1,i(0,3)} y2=@{-1,i(0,4)}
d={sqrt(($x2-$x1)^2+($y2-$y1)^2)}
u={($x2-$x1)/$d} v={($y2-$y1)/$d}
-rm[-1]
-f 'if(x<=$d&&y==0,i($x1+x*$u,$y1+x*$v,z,c,1),5)'
-crop 0,0,{int($d-1)},0
#@gmic fftshift
#@gmic : Shift a image so that the fft has it center in the middle
#@gmic : $ image.jpg -fftshift
fftshift :
-v - -repeat $! -l[$>]
-shift {-int(w/2)},{-int(h/2)},{-int(d/2)},0,2
-endl -done -v +
#@gmic whiten_frequency : _alpha
#@gmic : Whitening filter (equalize the frequency of the image; nothing todo with color)
#@gmic : $ image.jpg -whiten_frequency
whiten_frequency : -check "${1=.25}>=0"
-e[^-1] "Whiten the frequency with parameter "$1
-v - -repeat $! -l[$>]
#E=@{0,sqrt(iv)}
-fft --a c -norm[-1] -pow[-1] $1 -max[-1] 1e-12 -/[-1] {ia} -/[0-1] [2] -rm[2] -ifft -k[0]
#-* {$E/sqrt(iv)}
-endl -done -v +
#@gmic deblur_goldmeinel2 : sigma>=0, _nb_iter>=0, _acceleration>=0, _kernel_type={ 0=quasi-gaussian (faster) | 1=gaussian }.
#@gmic : Deblur and zoom selected images using Gold-Meinel algorithm
#@gmic : Default values: 'nb_iter=8', 'acceleration=1' and 'kernel_type=1'.
#@gmic : $ image.jpg --blur 1 --deblur_goldmeinel[-1] 1
###### : (contribution from Jérôme Boulanger).
deblur_goldmeinel2 : -check "$1>=0 && ${2=8}>=0 && ${3=1}>=0" -skip ${4=1} -skip ${5=1}
-e[^-1] "Deblur image$? using Gold-Meinel algorithm, with sigma $1, $2 iterations, acceleration $3 and "@{-arg\ 1+!$4,"",quasi-}"gaussian kernel."
-v - -repeat $! -l[$>]
[0] -r[-1] 200%,200%,200%,100%,5 -repeat $2
--b[-1] $1,1,$4 -r[-1] 50%,50%,50% --/[0,-1] -rm[-2] -^[-1] $3 -r[-1] 200%,200%,200%,100%,5 -*[-1,-2] # u *= f / Hu
-done -rm[0]
-endl -done -v +
#@gmic deblur_richardsonlucy2 : sigma>=0, nb_iter>=0, _kernel_type={ 0=quasi-gaussian (faster) | 1=gaussian }.
#@gmic : Deblur and zoom selected images using Richardson-Lucy algorithm.
#@gmic : Default values: 'nb_iter=50' and 'kernel_type=1'.
#@gmic : $ image.jpg --blur 1 --deblur_richardsonlucy[-1] 1
###### : (contribution from Jérôme Boulanger).
deblur_richardsonlucy2 : -check "$1>=0 && ${2=50}>=0" -skip ${3=1} -skip ${4=1}
-e[^-1] "Deblur image$? using Richardson-Lucy algorithm, with sigma $1, $2 iterations and "@{-arg\ 1+!$3,"",quasi-}"gaussian kernel."
-v - -repeat $! -l[$>]
[0] -r[-1] 200%,200%,200%,100%,5 -repeat $2
--b[-1] $1,1,{$3!=0} -r[-1] 50%,50%,50%,100%,5 --/[0,-1] -rm[-2] -r[-1] 200%,200%,200%,100%,5 -b[-1] $1,1,{$3!=0} -*[-1,-2] # u *= H ( f / Hu )
-done -rm[0]
-endl -done -v +
#@gmic correlate_fft
#@gmic : Convolve selected images two-by-two through fourier transforms.
#@gmic : $ image.jpg 100%,100% -gaussian[-1] 20,1,45 --convolve_fft
correlate_fft :
-e[^-1] "Correlate image$? two-by-two through fourier transforms."
-v - -repeat {int($!/2)} -l[$>,{$>+1}]
w2={int(@{0,w}/2)} h2={int(@{0,h}/2)} d2={int(@{0,d}/2)}
-r[1] [0],[0],[0],1,0,0,0.5,0.5,0.5,0.5 -shift[1] -$w2,-$h2,-$d2,0,2
-fft[0] -fft[2] -*[1] -1
--*[-4] [-1] --*[-4] [-3] -+[-2,-1]
-*[-5,-3] -*[-3,-2] --[-3,-2]
-ifft -rm[-1]
-endl -done -v +
#@gmic deconvolve_richardsonlucy : nb_iter>=0,
#@gmic : deconvolve images using the first one as a blur operator (PSF)
#@gmic : $ image.jpg 100%,100% -gaussian[-1] 3,1,45 -normalize_sum[-1] --convolve_fft --deconvolve_richardsonlucy[1,2] 10 -print_psnr[0,2,3]
deconvolve_richardsonlucy : -check "${1=5}>=1"
-e[^-1] "Deblur image$? using Richardson-Lucy algorithm with a custom filter."
-v -
-repeat {$!-1} -l[0,{$>+1}]
-r[0] @{1,w},@{1,h},@{1,d},100%,0,0,.5,.5,.5 -normalize_sum[0]
[1] -repeat $1
--convolve_fft[0,-1] --/[1,-1] -rm[-2] --correlate_fft[0,-1] -rm[-2] -*[-1,-2]
-done -rm[0,1]
-endl -done -v +
#@gmic deconvolve_goldmeinel : _nb_iter>=0, _acceleration>=0
#@gmic : Deblur and zoom selected images using Gold-Meinel algorithm
#@gmic : Default values: 'nb_iter=8', 'acceleration=1' and 'kernel_type=1'.
#@gmic : $ image.jpg 100%,100% -gaussian[-1] 5,1,45 -normalize_sum[-1] --convolve_fft --deconvolve_goldmeinel[1,2] 5 -print_psnr[0,2,3]
deconvolve_goldmeinel : -check "${1=5}>=1&&${2=1}>=1"
-e[^-1] "Deblur image$? using Gold-Meinel algorithm, with $1 iterations, acceleration $2."
-v - -repeat {$!-1} -l[0,{$>+1}]
-r[0] @{1,w},@{1,h},@{1,d},100%,0,0,.5,.5,.5 -normalize_sum[0]
[1] -repeat $2
--convolve_fft[0,-1] --/[1,-1] -rm[-2] -^[-1] $2 -*[-1,-2] # u *= (f / Hu)^$3
-done -rm[0,1]
-endl -done -v +
#@gmic normalize_sum
#@gmic : Normalize the image so that the sum of the values is 1
#@gmic : $ image.jpg --normalize_sum
normalize_sum :
-e[^-1] "Normalize the image so that its sum is equal to 1."
-v - -repeat $! -l[$>]
-* {1/(ia*w*h*d*s)}
-endl -done -v +
#@gmic local_variance : _radius
#@gmic : Local variance filter
#@gmic : $ image.jpg --local_variance
local_variance: -skip ${1=2}
-e[^-1] "Local Variance filter with scale "$1
-v - -repeat $! -l[$>]
--blur $1,1,1 -- -sqr -blur $1,1,1
-endl -done -v +
#@gmic normalize_local_variance : _amplitude,_radius,_threshold,_repeat
#@gmic : Local variance normalization
#@gmic : $ image.jpg --normalize_local_variance
normalize_local_variance: -skip ${1=50},${2=2},${3=25},${4=1}
-e[^-1] "Normalize local variance with amplitude $1, scale $2, threshold $3 (x$4 times)."
-v -
-repeat $4
--local_variance $2 -sqrt[-1] -max[-1] $3 # compute local standard deviation
--blur[0] $2,1,1 ---[0,-1] -/[-1] [1] -*[-1] $1 -+[-2,-1] -k[-1] # x = <x> + alpha * (x-<x>)/<x'x>
-done -v +
#@gmic local_wiener : _radius
#@gmic : Local Wiener filtering
#@gmic : X = <X> + ((<X-<X>>)'(<X-<X>>) - <N'N>)/(<X-<X>>)'(<X-<X>>) (X-<X>)
#@gmic : $ image.jpg --noise 10 --local_wiener[-1] 1 -print_psnr
local_wiener : -skip ${1=2}
-e[^-1] "Local Wiener filtering"
-v - -repeat $! -l[$>]
sigma=@{-noise_std}
--blur $1 # mean
--local_variance[0] {2*$1} ---[-1] {$sigma*$sigma} -reverse[-1,-2] -/[-1,-2] # variance
---[0,1] # img-mean
-*[-1,-2] -+[-1,-2] -k[-1]
-endl -done -v +
#@gmic periodize
#@gmic : Periodization of the image
#@gmic : $ image.jpg -periodize
periodize :
-e[^-1] "periodize"
-v - -repeat $! -l[$>]
-if {w>1} --mirror x -a x -endif
-if {h>1} --mirror y -a y -endif
-if {d>1} --mirror z -a z -endif
-endl -done -v +
#@gmic tape
#@gmic : apply a Hann window
#@gmic : $ image.jpg -tape
tape :
-e[^-1] "apply a Hann tapering window"
-v - -repeat $! -l[$>]
-if {w>1} -f 'i*sin(pi*x/(w-1))^2' -endif
-if {h>1} -f 'i*sin(pi*y/(h-1))^2' -endif
-if {d>1} -f 'i*sin(pi*z/(d-1))^2' -endif
-endl -done -v +
#@gmic powerspectrum :
#@gmic : Compute power spectrum
#@gmic : $ image.jpg -powerspectrum
powerspectrum :
-e[^-1] "Compute power spectrum"
-v - -repeat $! -l[$>]
-display_fft -k[0]
-endl -done -v +
#@gmic fouriermix : _cut_of_frequency
#@gmic : Mix two images using their respectives low and high frequencies
#@gmic : $ image1.jpg image2.jpg --fouriermix .5
fouriermix : -skip ${1=50%}
-e[^-1] "fourier mix images."
-fft[0] -fft[2] -fftshift
# make a mask
100%,100% -circle[-1] 50%,50%,$1,1,1 -blur[-1] 1,1,1 -n[-1] 0,1 -d
-*[0,1] [-1] -negative[-1] -*[2,3] [-1] -rm[-1] -+[0,2] -+[1,2] -fftshift
-ifft -k[0]
#@gmic fouriercut : _threshold
#@gmic : Illustrate the thresholding of Fourier coefficients
#@gmic : $ image.jpg --noise 10 --fouriercut[-1] 1 -print_psnr
fouriercut : -skip ${1=1}
-e[^-1] "Threshold Fourier coefficients with threshold "$1"."
-v - -repeat $! -l[$>]
--l[-1] -powerspectrum -threshold $1 -fftshift -endl
-fft[0] -*[0] [-1] -*[1] [-1] -rm[-1] -ifft -k[0]
-endl -done -v +
#@gmic unstrip : _smoothness,_scale,_threshold
#@gmic : Remove stripes in an image
#@gmic : $ image.jpg -f '.5*i*(1+.25*sin(x))' --unstrip
unstrip : -skip ${1=25},${2=20},${3=4}
-e[^-1] "Remove stripes"
-v - -repeat $! -l[$>]
# create a mask
--l[-1]
-tape -powerspectrum -norm -detect_spots 1,$3 -dilate_circ $2 -gt 0
-n 0,1 -negative -circle 50%,50%,$2,1,1
-if {@{-1,im}<.9} # check if some spots have been detected
active=1 -blur $1 -n 0,1 -fftshift -if {iM==0} -f 1 -endif
-else
active=0
-endif
-endl
#apply the mask
-if {$active==1}
-fft[0] -*[0] [-1] -*[1] [-1] -rm[-1] -ifft
-endif
-k[0]
-endl -done -v +
#@gmic autocorrelate
#@gmic : Autocorrelation using fourier transform
#@gmic : $ image.jpg -autocorrelate
autocorrelate :
-e[^-1] "Compute autocorrelation"
-v - -repeat $! -l[$>]
-fft -sqr -+ -sqrt -ifft -k[0] -fftshift
-endl -done -v +
#@gmic psf : _NA,_n,_wavelength,_pixel_size
#@gmic : Generate a rough approximation of a microscope PSF
#@gmic : $ 64,64,32 -psf , -+ 1 -log
psf : -skip ${1=1.40},${2=1.33},${3=488},${4=160},${5=200}
C={2*pi/$3*$1/$2*50}
-v - -repeat $! -l[$>]
-f 'dx=x-w/2;dy=y-h/2;dz=z-d/2;if($C*sqrt(dx*dx+dy*dy)<(d-abs(dz)),1,0)'
-blur 1
-s z -repeat $! -l[$>] -fftpolar -k[0] -endl -done -a z
-sqr
-endl -done -v +
#@gmic beads2psf :
#@gmic : Compute an approximate PSF from an image bead using autocorrelation method
beads2psf : -skip ${1=5}
-e[^-1] "Compute a PSF from an image bead using autocorrelation method"
-v - -repeat $! -l[$>]
-tape -autocorrelate -- {sqrt(@{0,iv})} -threshold 0,1
-f 'dx=x-w/2;dy=y-h/2;dz=z-d/2;sigma=9+$1*dz*dz;i*exp(-.5*(dx*dx+dy*dy)/(sigma))/sqrt(2*pi*sigma)'
-sqr -* {1/(ia*w*h*d*s)}
-endl -done -v +
#@gmic simmod:
#@gmic : Analyse SIM modulation by dividing by the sum of the images
simmod :
--+ -*[-1] {1/($!-1)} -/[0--2] [-1] -rm[-1]
#@gmic spotify : _scale>0,_nb_iter>0,
#@gmic : Make everything look like a spot
#@gmic : Default values '_nb_iter=1, _scale=1'
#@gmic : $ image.jpg --spotify 1,10
#@gmic : $ image.jpg --spotify 1,20 -norm[-1] -gt[-1] 5% -blur 1 -*
spotify : -check "${1=1}>0 && ${2=1}>0"
-e[^-1] "Spotify with scale $1 with $2 iterations"
-v - -repeat $! -l[$>]
s=@{0,a} -repeat $2 -blur $1 --blur {2*$1} -- -cut 0,100% -f 'i*{$s}/ia' -done
-endl -done -v +
#@gmic depthmap
#@gmic : Compute a depth map from the gradients norm
#@gmic : $ image.jpg -depthmap
depthmap:
-e[^-1] "Depth map"
-v - -repeat $! -l[$>]
--blur 2 -gradient_norm -reverse -/ -f '1/sqrt(i*i)-1'
-fft 100%,100%,1,1,'-(4-2*cos(2*x*pi/w)-2*cos(2*y*pi/h))'
-=[-1] 1 -/[-3,-2] [-1] -rm[-1] -ifft -k[0] -n 0,1
-endl -done -v +
#@gmic mapblur : _levels
#@gmic : Blur the image with a map
#@gmic : $ image.jpg --f '10*x/w' -mapblur
mapblur: -check "${1=10}>0"
-e[^-1] "Blur images using a blur map (works using pairs of images)."
-v - -repeat {$!/2} -l[{2*$>},{2*$>+1}]
smin=@{1,im} smax=@{1,iM}
-l[0] -repeat $1 --blur[0] {$smin+$>*($smax-$smin)/($1)} -done -rm[0] -a z -endl
-l[1] -tones $1 -gt 0 -blur 1 -a z -endl
-* -s z -+
-endl -done -v +
#@gmic tubeness : _scale>0
#@gmic : Tubeness filter based on the eigen value of the Hessian
#@gmic : Default values '_scale=1'
#@gmic : $ image.jpg --tubeness 3
#@gmic : $ image.jpg --tubeness 1 -n 0,255 -blend add
tubeness : -check "${1=1}>0"
-e[^-1] "Tubeness with scale $1."
-v - -repeat $! -l[$>]
-blur $1
-s c -repeat $! -l[$>]
-hessian -a c -eigen -k[0] -s c -k[1] -* -1 -cut 0,100%
-endl -done -a c
-endl -done -v +
firstEigen: -eigen -k[0]
#@gmic tubenessp : _scale>0
#@gmic : Tubeness filter based on the eigen value of the Hessian
#@gmic : Default values '_scale=1'
#@gmic : $ image.jpg --tubeness 3
#@gmic : $ image.jpg --tubeness 1 -n 0,255 -blend add
tubenessp : -check "${1=1}>0"
-e[^-1] "Tubeness with scale $1."
-v - -repeat $! -l[$>]
-blur $1
-s c -repeat $! -l[$>]
-hessian -a c -apply_parallel_overlap "firstEigen",1 -s c -k[1] -* -1
-endl -done -a c
-endl -done -v +
#@gmic bgsubstract : _length>0
#@gmic : Substract the background using a temporal top-hat filter
bgsubstract: -check "${1=5}>0"
-e[^-1] "Temporal background substraction with length $1."
-v - -repeat $! -l[$>]
1,1,$1 -f[-1] 1 --erode[0] [1] --[0] [-1] -rm[1,-1]
-endl -done -v +
#@gmic schizo : _amplitude,_amplitude_normal,_nb_iterations,_strength
#@gmic : Schizo filter gives either a furry image or a smoothed image
#@gmic : Default values '_amplitude=100,amplitude_normal=-50 _nb_iter=5,_strength=.75'
#@gmic : $ image.jpg --schizo 100,-50 --schizo[0] -50,100 -max 0
schizo : -skip ${1=100},${2=-50},${3=5},${4=.75}
-e[^-1] "Schizo filter smoothing with // $1 and T $2 and $3 iterations."
-v - -repeat $! -l[$>]
[0]
-repeat $3
-l[-1]
--iee -*[-1] {$1/(0.0001+max(abs(@{-1,m}),abs(@{-1,M})))}
--inn[0] -*[-1] {$2/(0.0001+max(abs(@{-1,m}),abs(@{-1,M})))}
-+
-endl
-*[-1] $4 --*[0] {1-$4} -+[-1,-2]
-done -rm[0]
-endl -done -v +
#@gmic scandoc : _smooth,_background,_black,_white
#@gmic : improve scanned document
#@gmic : $ image.jpg -scandoc
scandoc: -skip ${1=3},${2=100},${3=10%},${4=90%}
-v - -repeat $! -l[$>] -split_opacity -l[0]
-median $1 --blur $2 -- -min 0
-s c -n 0,1 -a c -c $3,$4 -n 0,255
-endl -a c -endl -done -v +
#@gmic oblur: _nb_scales,_nb_angles
#@gmic : Oriented blurs
oblur: -skip ${1=1},${2=6}
-v - -repeat $! -l[$>]
-repeat $1 s={2^($>+2)} -repeat $2 a={$>/$!*180}
-echo_stdout $s", "$a
#--blur_linear[0] $s,.1,$a
--l[0] -blur_linear $s,1,$a --blur 1 -- -endl
-if {$!==3} -max[1,2] -endif
-done -done
-rm[0]
-endl -done -v +
#@gmic oheat: _nb_scales,_nb_angles
#@gmic : Oriented blurs
oheat: -skip ${1=1},${2=6}
-v - -repeat $! -l[$>]
-repeat $1 -repeat $2 a={$>/$!*180}
--l[0] -blur_linear 2,.5,$a --blur 1 -- -endl
-done
-max[1--1] -+
-done
-endl -done -v +
#@gmic warp_affine
#@gmic : Warp the image [0] using an affine field defined by a 3x3 matrix [1]
#@gmic : $ image.jpg 3 -f[-1] 1 -diagonal[-1] -noise[-1] .1 --warp_affine -k[0,-1]
warp_affine :
--l[0,1]
params=(@{1,i(0,0)},@{1,i(1,0)},@{1,i(2,0)};\
@{1,i(0,1)},@{1,i(1,1)},@{1,i(2,1)};\
@{1,i(0,2)},@{1,i(1,2)},@{1,i(2,2)})
@{0,w},@{0,h},1,1,1 --f[-1] x --f[-1] y -a[-3--1] c
-mix_channels[-1] $params
-channels[-1] 1,2
-warp[0] [-1],0,2,0 -rm[-1,-2]
-endl
-rm[0,1]
#@gmic midway
#@gmic : Midway equalization of two channels
#@gmic : $ image.jpg -channels 0,1 -s c -*[-1] 2 -a c --midway
midway :
-repeat $! -l[$>]
--l[0]
-resize 20%,20%
-s c -unroll y -l[0] 1,@{0,h},1,1,1 -a x -endl -transpose[0]
-l[0] -svd -f[-2] 'if(i>1e-6,1/i,0)' -diagonal[-2] -transpose[-1] -mmul -endl -mmul
a=@{0,0} b=@{0,1} -rm[-1]
-endl
-s c
-+[-1] {$b} -*[-1] {1/$a} -a c
-endl -done
midway2:
--l[0] -s c -y y 1,@{0,h},1,1,1 -a x -svd -k[-1] -endl
params=(@{1,i(0,0)},@{1,i(1,0)},@{1,i(2,0)};\
@{1,i(0,1)},@{1,i(1,1)},@{1,i(2,1)};\
@{1,i(0,2)},@{1,i(1,2)},@{1,i(2,2)})
-rm[1]
-echo_stdout $params
-mix_channels[0] $params -n 0,255
#@gmic vobs : _scale
#@gmic : Motion quantity (Normal motion) $ h * (|Ixy|^2 |It|/|Ixy|) / h * Ixy^2$
#@gmic : Irani, Michal and Rousso, Benny and Peleg, Shmuel, Detecting and tracking multiple moving objects using temporal integration, ECCV'92, \href{http://dx.doi.org/10.1007/3-540-55426-2_33}{pdf}.
#@gmic : $ 100,100,10 -noise 1 -blur 1 --vobs
vobs : -check "${1=1}>0 && ${2=3}>0"
-e[^-1] "Motion quantity with scale $1"
-v - -repeat $! -l[$>]
-gradient -a[0,1] c -norm[0] -abs[1] -*[1] [0] -sqr[0] -blur $1,1,1 -reverse -max[1] 5% -/
-endl -done -v +
#@gmic display_vobs
#@gmic : Display local diffusion coefficient
#@gmic : $ 200,100 -noise .7,2 -blur 2,1,1 -repeat 20 --l[-1] --laplacian -*[-1] .05 -+ -endl -done -a z -display_vobs
display_vobs :
--vobs 1 A={round(@{-1,im},0.001)} B={round(@{-1,iM},0.001)} -*[-1] '{128/max(im,iM)}' -+[-1] 128 -map[-1] 5
-resize[0] 100%,100%,100%,3,1 -apply_gamma[0] 1.5 -n[0] 0,255
-l[0] -s z -frame 5,12,64 -shift 0,5,0,0,2 -text "Original sequence",5,0,13,1,255 -a z -endl
-l[1] -s z -repeat $! -l[$>] 1,100% -f[-1] 'h-y' -n 0,255 -map[-1] 5 -resize[-1] 5,@{0,h},1,3,5 -frame[-1] 3,0,64 -resize[-1] 100%,@{0,h},1,3,5 -a x
-frame 5,12,64 -shift 0,5,0,0,2
-text "Vobs ["$A":"$B"]",5,0,13,1,255 -endl -done -a z -endl
-a x
display_pseudocolor :
A={round(@{-1,im},0.0001)} B={round(@{-1,iM},0.0001)} -n[-1] 0,255 -map[-1] 5
-rectangle {w-50-5},{h/4-5},{w-5},{h-h/4+5},.5,0,0,0
-add_colorbar[-1] {w-50},{h/4},{w-40},{h-h/4},$A,$B,6,255
#@gmic display_colordepth : _dz
display_colordepth :
-e[^-1] "display the 3D image with a depth color coded."
-v - -repeat $! -l[$>]
H={d*$1} -colordepth , -a z -min {ia+10*sqrt(iv)} -n 0,255 -s z
-rectangle {w-50-5},{h/4-5},{w-5},{h-h/4+5},.5,0,0,0
-add_colorbar[-1] {w-50},{h/4},{w-40},{h-h/4},0,$H,6,255
-endl -done -v +
#@gmic add_colorbar : x0,y0,x1,y1,_min,_max,_ntics,color,colormap
#@gmic : Add a colorbar to the image
#@gmic : $ image.jpg -luminance -map 5 -add_colorbar {w-40},20,{w-30},{h-20},0,255,6,255,5
add_colorbar :
-skip ${5=0},${6=255},${7=6},${8=255},${9=""},${10=5}
-repeat $! -l[$>]
{$3-$1},{$4-$2} -l[-1] -f 'h-y' -n 0,255 -map $10 -endl
-frame[1] 1,1,$8 -image[0] [1],$1,$2,0,0,1 -k[0]
-repeat $7
val={round($5+$>/($7-1)*($6-$5),.001)}
-text "- "$val" "$9,{$3+1},{$4-$>*($4-$2-5)/($7-1)-10},13,1,$8
-done
-endl -done
#@gmic local_diffusion_coefficient : _scale,_threshold
#@gmic : Estimate local diffusion coefficient It - D (Ixx+Iyy)=0 using D=It/(Ixx+Iyy)
#@gmic : $ 100,100 -noise .7,2 -blur 2,1,1 -repeat 20 --l[-1] --laplacian -*[-1] .05 -+ -endl -done -a z -local_diffusion_coefficient 2,.5
local_diffusion_coefficient : -check "${1=2}>0 && ${2=.5}>=0"
-e[^-1] "Local diffusion coefficient estimation using scale $1 and threshold $2"