forked from idl-coyote/coyote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cgimage.pro
2547 lines (2341 loc) · 117 KB
/
cgimage.pro
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
; docformat = 'rst'
;
; PURPOSE:
; The purpose of this program is to create a TV command that works the way
; the TV command would be expected to work if it was written today, rather
; than 25 years ago. In other words, it knows the difference between an
; 8-bit device and a 24-bit device, it honors the POSITION keyword like
; other graphics commands in IDL, it honors the !P.MULTI value, like other
; graphics commands in IDL, it works seamlessly with both 8-bit and 24-bit
; images. In addition to other modern features, this program can also
; display images that contain an alpha channel and can display images with
; transparency.
;
;******************************************************************************************;
; ;
; Copyright (c) 2011, by Fanning Software Consulting, Inc. All rights reserved. ;
; ;
; Redistribution and use in source and binary forms, with or without ;
; modification, are permitted provided that the following conditions are met: ;
; ;
; * Redistributions of source code must retain the above copyright ;
; notice, this list of conditions and the following disclaimer. ;
; * Redistributions in binary form must reproduce the above copyright ;
; notice, this list of conditions and the following disclaimer in the ;
; documentation and/or other materials provided with the distribution. ;
; * Neither the name of Fanning Software Consulting, Inc. nor the names of its ;
; contributors may be used to endorse or promote products derived from this ;
; software without specific prior written permission. ;
; ;
; THIS SOFTWARE IS PROVIDED BY FANNING SOFTWARE CONSULTING, INC. ''AS IS'' AND ANY ;
; EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES ;
; OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT ;
; SHALL FANNING SOFTWARE CONSULTING, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, ;
; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED ;
; TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; ;
; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ;
; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ;
; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;
; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;
;******************************************************************************************;
;
;+
; The purpose of this program is to create a TV command that works the way
; the TV command would be expected to work if it was written today, rather
; than 25 years ago. In other words, it knows the difference between an
; 8-bit device and a 24-bit device, it honors the POSITION keyword like
; other graphics commands in IDL, it honors the !P.MULTI value, like other
; graphics commands in IDL, it works seamlessly with both 8-bit and 24-bit
; images. In addition to other modern features, this program can also
; display images that contain an alpha channel and can display transparent
; images.
;
; There is a common block in cgImage that is defined as follows upon exiting
; this command::
;
; COMMON FSC_$CGIMAGE, $
; _cgimage_xsize, $ ; The X size of the image.
; _cgimage_ysize, $ ; The Y size of the imge.
; _cgimage_winxsize, $ ; The X size of the window displaying the image.
; _cgimage_winysize, $ ; The Y size of the window displaying the image.
; _cgimage_position, $ ; The final position of the image in the window.
; _cgimage_winID, $ ; The window index number of the window displaying the image.
; _cgimage_current ; Set to 1 if a call to cgImage is made.
;
; The program requires the `Coyote Library <http://www.idlcoyote.com/documents/programs.php>`
; to be installed on your machine.
;
; To learn more about transparent images and cgImage see the article
; `Working with Transparent Images and cgImage <http://www.idlcoyote.com/cg_tips/transimage.php>`.
;
; :Categories:
; Graphics
;
; :Examples:
; To display an image with a contour plot on top of it, type::
;
; filename = FILEPATH(SUBDIR=['examples','data'], 'worldelv.dat')
; image = BYTARR(360,360)
; OPENR, lun, filename, /GET_LUN
; READU, lun, image
; FREE_LUN, lun
;
; thisPostion = [0.1, 0.1, 0.9, 0.9]
; cgIMAGE, image, POSITION=thisPosition, /KEEP_ASPECT_RATIO
; CONTOUR, image, POSITION=thisPosition, /NOERASE, XSTYLE=1, $
; YSTYLE=1, XRANGE=[0,360], YRANGE=[0,360], NLEVELS=10
;
; To display four images in a window without spacing between them::
;
; !P.Multi=[0,2,2]
; cgImage, image, Margin=0
; cgImage, image, Margin=0
; cgImage, image, Margin=0
; cgImage, image, Margin=0
; !P.Multi = 0
;
; To display four image in a window with associated color bars::
;
; !P.Multi=[0,2,2]
; p = [0.02, 0.3, 0.98, 0.98]
; LoadCT, 0
; cgImage, image, Position=p
; cgColorbar, Position=[p[0], p[1]-0.1, p[2], p[1]-0.05]
; p = [0.02, 0.3, 0.98, 0.98]
; LoadCT, 2
; cgImage, image, Position=p
; cgColorbar, Position=[p[0], p[1]-0.1, p[2], p[1]-0.05]
; p = [0.02, 0.3, 0.98, 0.98]
; LoadCT, 3
; cgImage, image, Position=p
; cgColorbar, Position=[p[0], p[1]-0.1, p[2], p[1]-0.05]
; p = [0.02, 0.3, 0.98, 0.98]
; LoadCT, 5
; cgImage, image, Position=p
; cgColorbar, Position=[p[0], p[1]-0.1, p[2], p[1]-0.05]
; !P.Multi =0
;
; To set a missing value to -32767 and the color white and do
; a 3% histogram clip of the image::
;
; cgLoadCT, 4, /Brewer, NColors=254
; TVLCT, palette, /Get
; cgImage, image, Missing_Value=-32767, Missing_Color='white', Stretch='Clip', Clip=3
;
; To display a transparent image on top of another image::
;
; cgImage, cgDemoData(7), CTIndex=0
; cgImage, cgDemoData(5), CTIndex=33, Transparent=50, $
; AlphaFGPosition=[0.25, 0.25, 0.75, 0.75], Missing_Value=0
;
; .. image:: cgimage.png
;
; :Author:
; FANNING SOFTWARE CONSULTING::
; David W. Fanning
; 1645 Sheely Drive
; Fort Collins, CO 80526 USA
; Phone: 970-221-0438
; E-mail: david@idlcoyote.com
; Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
;
; :History:
; Modification History::
; Written by: David W. Fanning, from modifications to TVIMAGE. 3 Feb 2011.
; 8 Feb 2011. Added OPOSITION keyword. DWF.
; 27 Feb 2011. Added keywords to make cgImage more compatible with TVImage calls. DWF.
; Color table vectors must be obtained AFTER loading the color palette. 6 March 2011. DWF.
; I have been convinced (conversations with Wayne Landsman) that if the
; CENTER keyword is set, the MINUS_ONE keyword is not needed, since
; it was created to solve the same problem. So, I have changed the
; default setting of MINUS_ONE to 0. 14 March 2011. DWF.
; Corrected a problem with restoring color tables if a PALETTE is used. 31 March 2011. DWF.
; Whoops! Documented a CHARSIZE keyword, but forgot to define it. 7 July 2011.
; Damnation! I did the same thing with the FONT keyword! 25 July 2011.
; And now a TITLE keyword! What the devil is going on!? 29 Aug 2011.
; Very slight modifications to image size and start position so that the image is
; positioned completely inside the axes. 30 Sept 2011. DWF.
; Fitting the image inside the axes causes image matching problems (and lines!) in
; other programs, so I've decided to only do positioning inside axes when the
; user asks for this capability by setting the new FIT_INSIDE keyword. 16 Nov 2011. DWF.
; Problem with transparent images with alpha channels caused by changes in the TVImage->cgImage
; transition. Added AlphaFGPosition keyword to address issues. Cleaned up the
; code and improved the internal documentation. 22 Nov 2011. DWF.
; Added the ability to stretch 2D image arrays in various ways before display. 1 Dec 2011.
; Added the ability to handle missing data in 2D arrays before display. 1 Dec 2011.
; Added a DISPLAY keyword to display the image in windows with the image aspect ratio. 2 Dec 2011.
; Added the ability to send the output directly to a file via the OUTPUT keyword. 9 Dec 2011, DWF.
; PostScript, PDF, and Imagemagick parameters can now be tailored with cgWindow_SetDefs. 14 Dec 2001. DWF.
; Modified to use cgDefaultColor for default color selection. 24 Dec 2011. DWF.
; Changes to allow better default colors, based on changes to cgColor and cgDefaultColor. 1 Feb 2012. DWF.
; I was passing the wrong MINVALUE and MAXVALUE values to the scaling function. 12 Feb 2012. DWF.
; I made cgImage aware of a "feature" of MAP_SET that sets !P.MULTI[0]=-1, which was screwing
; up the algorithm to cause cgImage to erase the display window. 28 Feb 2012. DWF.
; Added a Standard Deviation stretch, including the EXCLUDE and MULTIPLIER keywords to the
; SDevScl command. 6 June 2012. DWF.
; Now saving the image POSITION in FSC_$CGIMAGE common block, even if in PostScript, because other
; routines (e.g., cgMap) may depend on it (e.g., using ONIMAGE keyword). 26 July 2012. DWF.
; Added the ability to use escape characters in plot titles to specify cgSymbol symbols. 27 July 2012. DWF.
; Modified the way the XRANGE and YRANGE keywords work when the OVERPLOT keyword is also set. In this case,
; I will modify the image position to honor the XRANGE and YRANGE values with respect to the axes that the
; image is being overplot onto. 15 August 2012. DWF.
; Set the NOERASE keyword if the OVERPLOT keyword is set and NOERASE is undefined. 16 Aug 2012. DWF.
; Modified the way the HIST_EQUAL stretch works. Previously the image was displayed as all zeros
; if the input image had a minimum value less that zero. 21 Aug 2012. DWF.
; Fixed a problem with the INTERPOLATE variable that prevented interpolaton from occurring. 12 Sept 2012. DWF.
; A misspelled MULTIPLIER keyword was interfering with a Standard Deviation stretch. 16 Sept 2012. DWF
; Added the TRANSPARENT keyword to allow transparent display of images. 17 October 2012. DWF.
; Added the MAPCOORD keyword to allow the XRANGE and YRANGE of the image to be specified by the map
; coordinate object. 17 October 2012. DWF.
; Added CTINDEX, BREWER, and REVERSE keywords to make loading a color table palette easier. 17 October 2012. DWF.
; Now setting MISSING_VALUE pixels to completely transparent if a transparent image is created. 17 October 2012. DWF.
; Added the ability to apply a stretch to a 2D image prior to converting it to a transparent image. 18 October 2012.DWF.
; Added a FILENAME keyword so that files of known format (GeoTIFF, JPEG, PNG, etc.) can be read to supply an
; image for display. 18 October 2012. DWF.
; Fixed a problem that prevented transparent images from be displayed with !P.Multi. 20 Oct 2012. DWF.
; Provided a fix to allow transparent images in versions of IDL from IDL 6.4 and earlier. 18 Nov 2012. DWF.
; When reading a GeoTiff file, the map object created should be named mapCoord, not map, so that
; the image data ranges can be set automatically. 11 January 2013. DWF.
; Additional work to allow overplotting of transparent images. 12 Jan 2013. DWF.
; For some reason I thought I had to have transparency ON when overplotting. This turns out to be wrong
; and gets in the way of outputting to PostScript and working with some map projected images. I've
; removed this requirement in the code. I also fixed a problem in which the OUTPUT position changes
; if the TRANSPARENT keyword is used. 27 January 2013. DWF.
; I had some code dealing with XRANGE and YRANGE properties of the image when a map coodinate object
; was used with cgImage. This was inadvertently setting the XRANGE and YRANGE properties of the
; image, which was in turn causing the range values to be SAVED in the plotting system variables.
; This interferred with backward compatibility with the TV command, so I have removed it. 31 Jan 2013. DWF.
; Whoops! Typo in my last fix. Getting too old, I guess. 6 Feb 2013. DWF.
; Setting any of the MISSING_*** keywords while doing multiple plots resulted in the value
; of !P.Multi being ignored for the image. This is fixed for now, but just a warning. Setting
; these keywords creates transparent images, and makes things MUCH more complicated. So, I'm
; probably at the limit of what is possible now. :-) 30 April 2013. DWF.
; The LAYOUT keyword went on walkabout after the last changes. Restored to operation. 12 July 2013. DWF.
; The YTITLE keyword was missing when passed to cgWindow. Fixed now. 24 Oct 2013. DWF.
; Fixed a couple of places where I meant "missing_index" and used "missing_color". 26 Jan 2014. DWF.
; Added check for open graphics window when displaying alpha-channel image. 31 March 2014. DWF.
; Added XVECTOR and YVECTOR keywords. 1 April 2014. DWF.
; Fixed a problem in which the POSITION of the image was specified as an integer array when it
; should have been a floating point array. 8 January 2015. DWF.
; Added compression stretch and updated retired program references. 27 Mar 2015. DWF.
;
; :Copyright:
; Copyright (c) 2011-2015, Fanning Software Consulting, Inc.
;-
;
;+
; This function creates a transparent image out of a normal 2D or 3D image.
;
; :Params:
; image: in, required
; The input image. Must be either 2D or a true-color image.
; transparent: in, optional, type=integer, default=50
; The transparentcy of the image with respect to the background image. A number
; from 0 to 100.
;
; :Keywords:
; missing_value: in, optional, type=integer
; The number that represents the missing value in the image. Available only with 2D images.
; This value is set to be completely transparent in the image.
; palette: in, optional, type=bytarr
; A 3x256 byte array containing the color table vectors that the image is to
; be displayed in.
; success: out, optional
; An output keyword that is set to 1 if the transparent image is created
; successfully. Otherwise, set to 0.
;-
FUNCTION cgImage_Make_Transparent_Image, image, transparent, $
MISSING_VALUE=missing_value, $
PALETTE=palette, $
SUCCESS=success
Compile_Opt idl2
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
void = cgErrorMsg()
success = 0
RETURN, 0
ENDIF
success = 1
IF N_Elements(image) EQ 0 THEN Message, 'An image parameter is required'
IF N_Elements(transparent) EQ 0 THEN transparent = 50
; Make sure the transparent value is between 0 and 100 initially, and between 0 and 1 finally.
transparent = (0 > transparent < 100) / 100.0
ndims = Size(image, /N_DIMENSIONS)
CASE ndims OF
2: BEGIN
s = Size(image, /DIMENSIONS)
IF N_Elements(palette) NE 0 THEN BEGIN
IF (Size(palette, /DIMENSIONS))[0] EQ 3 THEN BEGIN
r = Reform(palette[0,*])
g = Reform(palette[1,*])
b = Reform(palette[2,*])
ENDIF ELSE BEGIN
r = palette[*,0]
g = palette[*,1]
b = palette[*,2]
ENDELSE
ENDIF ELSE BEGIN
TVLCT, r, g, b, /Get
ENDELSE
newimage = BytArr(4, s[0], s[1])
newImage[0,*,*] = r[image]
newImage[1,*,*] = g[image]
newImage[2,*,*] = b[image]
newimage[3,*,*] = BytArr(s[0],s[1]) + (255 * (1.0 - transparent))
; Is there missing data to consider?
IF (N_Elements(missing_value) NE 0) THEN BEGIN
; The missing value may be the symbol for NAN.
IF Finite(missing_value) THEN BEGIN
missingIndices = Where(image EQ missing_value, missingCnt)
ENDIF ELSE BEGIN
missingIndices = Where(Finite(image) EQ 0, missingCnt)
ENDELSE
; Make the missing pixels completely transparent in the alpha channel.
IF missingCnt GT 0 THEN BEGIN
alpha = Reform(newimage[3,*,*])
alpha[missingIndices] = 0B
newimage[3,*,*] = Temporary(alpha)
ENDIF
ENDIF
END
3: BEGIN
dims = Image_Dimensions(image, XSIZE=xsize, YSIZE=ysize, ALPHACHANNEL=alpha, TRUEINDEX=true)
newimage = BytArr(4, xsize, ysize)
; Prepare an alpha image, if needed.
IF ~alpha THEN BEGIN
index = Where(Size(image,/DIMENSIONS) EQ 3)
CASE index OF
0: aImage = image
1: aImage = Transpose(image, [1,0,2])
2: aimage = Transpose(image, [2,0,1])
ENDCASE
newImage[0:2,*,*] = aImage
newimage[3,*,*] = BytArr(xsize,ysize) + (255 * (1.0 - transparent))
ENDIF ELSE BEGIN
index = Where(Size(image,/DIMENSIONS) EQ 4)
CASE index OF
0: aImage = image
1: aImage = Transpose(image, [1,0,2])
2: aimage = Transpose(image, [2,0,1])
ENDCASE
newImage[0:2,*,*] = aImage[0:2,*,*]
newimage[3,*,*] = BytArr(xsize,ysize) + (255 * (1.0 - transparent))
ENDELSE
END
ELSE: Message, 'Cannot process images that are not 2D or True-Color for transparentcy.'
ENDCASE
RETURN, newImage
END
;+
; This routine prepares a transparent image (an image with an alpha channel)
; for display.
;
; :Returns:
; Returns an image that has been blended with the background image and is
; suitable for display with cgImage.
;
; :Params:
; image: in, required
; The input image that is being prepared for display. It will contain
; an alpha channel.
; alphabackgroundimage: in, required
; The background image. The input image will be blended
; with the background image.
;
; :Keywords:
; alphabgposition: in, required, type=fltarr
; The normalized position or portion of the background image used to create the alpha image.
; alphafgposition: in, required, type=fltarr
; The normalized position in the background image where the input image is to be located.
; tv: in, optional, type=boolean, default=0
; If this keyword is set, the alpha channel is removed from the
; input image, because we cannot display an image with an alpha
; channel if the cgImage command is acting like a smarter IDL
; TV command.
;-
FUNCTION cgImage_Prepare_Alpha, image, alphaBackgroundImage, $
ALPHABGPOSITION=alphabgpos, $
ALPHAFGPOSITION=alphafgpos, $
TV=tv
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /Cancel
ok = cgErrorMsg()
IF Ptr_Valid(ptr) THEN BEGIN
image = Temporary(*ptr)
Ptr_Free, ptr
ENDIF
IF N_Elements(thisDevice) NE 0 THEN Set_Plot, thisDevice
RETURN, image
ENDIF
; Prepare an alpha image, if needed.
index = Where(Size(image,/DIMENSIONS) EQ 4)
CASE index OF
0: aImage = Transpose(image, [1,2,0])
1: aImage = Transpose(image, [0,2,1])
ELSE: aImage = image
ENDCASE
; Separate the alpha channel.
alpha_channel = aImage[*,*,3]
; If this is acting like a TV command, then there is no alpha channel.
; Exit now.
IF Keyword_Set(tv) THEN RETURN, aImage[*,*,0:2]
; Now we have an alpha channel.
alpha_channel = (alpha_channel / 255.0) * 1.0
foregndImage = aImage[*,*,0:2]
; Get the size and dimensions of the background image.
ndim = Size(alphaBackgroundImage, /N_DIMENSIONS)
CASE ndim OF
2: BEGIN
TVLCT, r, g, b, /GET
s = Size(alphaBackgroundImage, /DIMENSIONS)
bImage = BytArr(s[0], s[1], 3)
bImage[*,*,0] = r[alphaBackgroundImage]
bImage[*,*,1] = g[alphaBackgroundImage]
bImage[*,*,2] = b[alphaBackgroundImage]
END
3: BEGIN
index = Where(Size(alphaBackgroundImage,/DIMENSIONS) EQ 3)
CASE index OF
0: bImage = Transpose(alphaBackgroundImage, [1,2,0])
1: bImage = Transpose(alphaBackgroundImage, [0,2,1])
ELSE: bImage = alphaBackgroundImage
ENDCASE
END
ELSE: Message, 'Unexpected dimensions of the background image.'
ENDCASE
; I need a 24-bit image to work with. This is most easily done
; in the Z-Graphics buffer, set to work in 24-bit mode. Unfortunately,
; this mode was introduced in IDL 7, so I can't use it with IDL 6.4
; or earlier versions. I can, however, TRY to use a pixmap in earlier
; versions. I have reports that this works fine. So, I am modifying this
; section of code to get the 24-bit image I need out of a pixmap for versions
; of IDL before IDL 7.0.
thisRelease = Float(!Version.Release)
; Now that we have a background image, display that in
; the Z-Graphics buffer or in a pixmap if IDL 6.4 or earlier.
sb = Size(bImage, /DIMENSIONS)
sf = Size(foregndImage, /DIMENSIONS)
IF thisRelease GE 6.5 THEN BEGIN
thisDevice = !D.Name
Set_Plot, 'Z'
Device, Get_Decomposed=theState
Device, Set_Resolution=sb[0:1], Decomposed=1, Set_Pixel_Depth=24
ENDIF ELSE BEGIN
thisDevice = !D.Name
IF (thisDevice EQ 'PS') OR (thisDevice EQ 'Z') THEN BEGIN
IF StrUpCase(!Version.OS_Family) EQ 'WINDOWS' THEN setToDev = 'WIN' ELSE setToDev = 'X'
ENDIF
currentWindow = !D.Window
IF N_Elements(setToDev) NE 0 THEN Set_Plot, setToDev
cgDisplay, /FREE, /PIXMAP, sb[0], sb[1]
pixmap = !D.Window
ENDELSE
; Turn off !P.MULTI handling for this part.
multi = !P.Multi
!P.Multi = 0
IF N_Elements(alphabgpos) EQ 0 THEN BEGIN
cgImage, bImage
ENDIF ELSE BEGIN
cgImage, bImage, Position=alphabgpos
ENDELSE
!P.Multi = multi
; Calculate the parameters for taking a snapshot of the
; relevant portion of the window.
xstart = alphafgpos[0]*sb[0]
cols = Round((alphafgpos[2] - alphafgpos[0]) * sb[0])
ystart = alphafgpos[1]*sb[1]
rows = Round((alphafgpos[3] - alphafgpos[1]) * sb[1])
; Take a snapshot
bsnap = TVRD(xstart, ystart, cols, rows, TRUE=3)
; Get the size of the snapshot.
sb = Size(bsnap, /DIMENSIONS)
; Clean-up
IF thisRelease GE 6.5 THEN BEGIN
Device, Decomposed=theState
Set_Plot, thisDevice
ENDIF ELSE BEGIN
WDelete, pixmap
IF N_Elements(setToDev) NE 0 THEN Set_Plot, thisDevice
IF (currentWindow LE 0) AND ((!D.Flags AND 256) NE 0) THEN WSet, currentWindow
ENDELSE
; Make the foreground image the right size.
foregndImage = cgResizeImage(foregndImage, cols, rows)
alpha = cgResizeImage(alpha_channel, sb[0], sb[1], /INTERPOLATE)
alpha = Rebin(alpha, sb[0], sb[1], 3)
; Blend the two images in the location of the POSITION.
blendImage = foregndImage*alpha + (1 - alpha)*bsnap
; Now put this blended portion back into the background image.
outimage = bimage
outimage[xstart:xstart+cols-1, ystart:ystart+rows-1, *] = blendImage
; Put the dimensions back the way they came in.
index = Where(Size(foregndImage,/DIMENSIONS) EQ 3)
CASE index OF
0: outImage = Transpose(outImage, [2,0,1])
1: outImage = Transpose(outImage, [1,0,2])
ELSE: outImage = outImage
ENDCASE
RETURN, outimage
END
;--------------------------------------------------------------------------
;+
; This routine scales or otherwise prepares an image to be displayed.
;
; :Returns:
; Returns an image that can be displaye properly.
;
; :Params:
; image: in, required
; The input image that is being prepared for display.
; xsize: in, optional
; The output X size of the image.
; ysize: in, optional
; The output Y size of the image.
;
; :Keywords:
; bottom: in, optional, type=integer, default=0
; If the SCALE keyword is set, the image is scaled before display so that all
; displayed pixels have values greater than or equal to BOTTOM and less than
; or equal to TOP.
; beta: in, optional, type=float, default=3.0
; The beta factor in a Hyperpolic Sine stretch.
; clip: in, optional, type=float, default=2
; A number between 0 and 50 that indicates the percentage of pixels to clip
; off either end of the image histogram before performing a linear stretch.
; constant: in, optional, type=float, default=1.0
; A constant multiplier for the cgLogScl stretch.
; exclude: in, optional
; The value to exclude in a standard deviation stretch.
; exponent: in, optional, type=float, default=4.0
; The logarithm exponent in a logarithmic stretch.
; gamma: in, optional, type=float, default=1.5
; The gamma factor in a gamma stretch.
; interpolate: in, optional, type=boolean, default=0
; Set this keyword to interpolate with bilinear interpolation the display image as it
; is sized to its final position in the display window. Interpolation will potentially
; create image values that do not exist in the original image. The default is to do no
; interpolation, so that image values to not change upon resizing. Interpolation can
; result in smoother looking final images.
; maxvalue: in, optional, type=varies
; If this value is defined, the data is linearly scaled between MINVALUE
; and MAXVALUE. MAXVALUE is set to MAX(image) by default. Setting this
; keyword to a value automatically sets `SCALE` to 1. If the maximum value of the
; image is greater than 255, this keyword is defined and SCALE=1.
; mean: in, optional, type=float, default=0.5
; The mean factor in a logarithmic stretch.
; minus_one: in, optional, type=boolean, default=0
; The value of this keyword is passed along to the cgResizeImage
; command. It prevents cgResizeImage from adding an extra row and
; column to the resulting array, which can be a problem with
; small image arrays.
; minvalue: in, optional, type=varies
; If this value is defined, the data is linearly scaled between MINVALUE
; and `MAXVALUE`. MINVALUE is set to MIN(image) by default. Setting this
; keyword to a value automatically sets SCALE=1. If the minimum value of the
; image is less than 0, this keyword is defined and SCALE=1.
; missing_index: in, optional, type=integer, default=255
; The index of the missing color in the final byte scaled image.
; missing_value: in, optional, type=integer
; The number that represents the missing value in the image.
; multiplier: in, optional, type=float
; The multiplication factor in a standard deviation stretch. The standard deviation
; is multiplied by this factor to produce the thresholds for a linear stretch.
; negative: in, optional, type=boolean, default=0
; Set this keyword if you want to display the image with a negative or reverse stretch.
; scale: in, optional, type=boolean, default=0
; Set this keyword to byte scale the image before display. If this keyword is not set,
; the image is not scaled before display. This keyword will be set automatically by using
; any of the keywords normally associated with byte scaling an image.
; stretch: in, optional, type=integer/string, default=1
; The type of scaling performed prior to display.
; May be specified as a number or as a string (e.g, 4 or "Log").
;
; Number Type of Stretch
; 0 None No scaling whatsoever is done.
; 1 Linear scaled = BytScl(image, MIN=minValue, MAX=maxValue)
; 2 Clip A histogram stretch, with a percentage of pixels clipped at both the top and bottom
; 3 Gamma scaled = cgGmaScl(image, MIN=minValue, MAX=maxValue, Gamma=gamma)
; 4 Log scaled = cgLogScl(image, MIN=minValue, MAX=maxValue, Mean=mean, Exponent=exponent)
; 5 Asinh scaled = cgAsinhScl(image, MIN=minValue, MAX=maxValue, Beta=beta)
; 6 SquareRoot A linear stretch of the square root histogram of the image values.
; 7 Equalization A linear stretch of the histogram equalized image histogram.
; 8 Gaussian A Gaussian normal function is applied to the image histogram.
; 9 MODIS Scaling done in the differential manner of the MODIS Rapid Response Team
; and implemented in the Coyote Library routine ScaleModis.
; 10 StdDev A standard deviation stretch. scaled = cgSDevScl(image, Multiplier=2.0).
; 11 Compression Compress the mid-tones of the image. scaled = cgCompressScl(image, Constant=2.0)
; sigma: in, optional, type=float, default=1.0
; The sigma scale factor in a Gaussian stretch.
; top: in, optional, type=integer, default=255
; If the SCALE keyword is set, the image is scaled before display so that all
; displayed pixels have values greater than or equal to BOTTOM and less than
; or equal to TOP.
;-
FUNCTION cgImage_Prepare_Output, image, xsize, ysize, $
BOTTOM=bottom, $
BETA=beta, $
CLIP=clip, $
CONSTANT=constant, $
EXCLUDE=exclude, $
EXPONENT=exponent, $
GAMMA=gamma, $
INTERPOLATE=interpolate, $
MAXVALUE=maxvalue, $
MEAN=mean, $
MINUS_ONE=minus_one, $
MINVALUE=minvalue, $
MISSING_INDEX=missing_index, $
MISSING_VALUE=missing_value, $
MULTIPLIER=multiplier, $
NEGATIVE=negative, $
SCALE=scale, $
STRETCH=stretch, $
SIGMA=sigma, $
TOP=top
Compile_Opt idl2
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /Cancel
ok = cgErrorMsg()
RETURN, image
ENDIF
; I would like to avoid making a copy of the image, if possible.
; If nothing needs to be done, just return the image.
IF (N_Elements(xsize) EQ 0) && $
(N_Elements(missing_value) EQ 0) && $
~scale THEN RETURN, image
; Is there a missing value to worry about? We can only worry
; about missing values with 2D image arrays.
ndims = Size(image, /N_DIMENSIONS)
IF (N_Elements(missing_value) NE 0) && (ndims EQ 2) THEN BEGIN
; Get the image type.
imageType = Size(image, /TNAME)
; Create a temporary image variable. If you will be scaling the data,
; make the image a float if it is not float or double already.
CASE imageType OF
'FLOAT': tempImage = image
'DOUBLE': tempImage = image
ELSE: tempImage = Float(image)
ENDCASE
; The missing value may be the symbol for NAN.
IF Finite(missing_value) THEN BEGIN
missingIndices = Where(tempImage EQ missing_value, missingCnt)
ENDIF ELSE BEGIN
missingIndices = Where(Finite(tempImage) EQ 0, missingCnt)
ENDELSE
; Set the missing indices to the correct NAN value.
IF imageType EQ 'DOUBLE' THEN BEGIN
IF missingCnt GT 0 THEN tempImage[missingIndices] = !Values.D_NAN
ENDIF ELSE BEGIN
IF missingCnt GT 0 THEN tempImage[missingIndices] = !Values.F_NAN
ENDELSE
ENDIF
; Do you need scaling?
IF Keyword_Set(scale) || (stretch NE 0) THEN BEGIN
; Create a temporary image, if you don't already have one.
IF N_Elements(tempImage) EQ 0 THEN BEGIN
imageType = Size(image, /TNAME)
CASE imageType OF
'FLOAT': tempimage = image
'DOUBLE': tempimage = image
ELSE: tempImage = Float(image)
ENDCASE
ENDIF
; Select the particular kind of stretch you want to do. Unfortunately, we
; can still cause underflow error messages when doing stretch, despite best
; attempts to prevent this. Turn these messages off here.
curExcept = !Except
!Except = 0
CASE stretch OF
; 0 None No scaling whatsoever is done.
; 1 Linear scaled = BytScl(image, MIN=minValue, MAX=maxValue)
; 2 Clip A histogram stretch, with a percentage of pixels clipped at both the top and bottom
; 3 Gamma scaled = cgGmaScl(image, MIN=minValue, MAX=maxValue, Gamma=gamma)
; 4 Log scaled = cgLogScl(image, MIN=minValue, MAX=maxValue, Mean=mean, Exponent=exponent)
; 5 Asinh scaled = cgAsinhScl(image, MIN=minValue, MAX=maxValue, Beta=beta)
; 6 SquareRoot A linear stretch of the square root histogram of the image values.
; 7 Equalization A linear stretch of the histogram equalized image histogram.
; 8 Gaussian A Gaussian normal function is applied to the image histogram.
; 9 MODIS Scaling done in the differential manner of the MODIS Rapid Response Team
; 10 StdDev A standard deviation stretch.
; 11 Compressioni A compression stretch of the image mid-tones.
0: ; No stretch at all.
1: BEGIN ; Linear stretch.
tempImage = BytScl(tempImage, Max=maxvalue, Min=minvalue, /NAN, TOP=top) + bottom
IF negative THEN tempImage = Byte(top) - tempImage
END
2: BEGIN ; Histogram clip stretch.
tempImage = cgClipScl(tempImage, clip, OMIN=bottom, OMAX=top, NEGATIVE=negative)
END
3: BEGIN ; Gamma log scale stretch.
tempImage = cgGmaScl(tempImage, Max=maxvalue, Min=minvalue, $
Gamma=gamma, Negative=negative, OMAX=top, OMIN=bottom)
END
4: BEGIN ; Log scale stretch.
tempImage = cgLogScl(tempImage, Max=maxvalue, Min=minvalue, $
Constant=constant, Negative=negative, $
OMIN=bottom, OMAX=top)
END
5: BEGIN ; Hyperpolic sine stretch.
tempImage = cgASinhScl(tempImage, Max=maxvalue, Min=minvalue, $
BETA=beta, Negative=negative, OMAX=top, OMIN=bottom)
END
6: BEGIN ; Square Root stretch.
tempImage = BytScl(SQRT(tempImage), Max=maxvalue, Min=minvalue, /NAN, TOP=top) + bottom
IF negative THEN tempImage = Byte(top) - tempImage
END
7: BEGIN ; Histogram equalization stretch.
IF (top EQ 255) && (bottom EQ 0) THEN BEGIN
tempImage = Hist_Equal(tempImage, MaxV=maxvalue, MinV=minvalue)
ENDIF ELSE BEGIN
tempImage = Bytscl(Float(Hist_Equal(tempImage, MaxV=maxvalue, MinV=minvalue)), /NAN, TOP=top) + bottom
ENDELSE
IF negative THEN tempImage = Byte(top) - tempImage
END
8: BEGIN ; Gaussian stretch.
tempImage = cgGaussScl(tempImage, Max=maxvalue, Min=minvalue, $
Sigma=sigma, Negative=negative, OMIN=bottom, OMAX=top)
END
9: BEGIN ; MODIS image stretch.
tempImage = ScaleModis(tempImage)
END
10: BEGIN ; Standard deviation stretch.
tempImage = cgSDevScl(tempImage, MULTIPLIER=multiplier, EXCLUDE=exclude, $
Negative=negative, OMAX=top, OMIN=bottom)
END
11: BEGIN ; Compression scale stretch.
tempImage = cgCompressScl(tempImage, Max=maxvalue, Min=minvalue, $
Mean=mean, Exponent=exponent, Negative=negative, $
OMIN=bottom, OMAX=top)
END
ELSE: Message, 'Unknown scaling index.'
ENDCASE
; Clear the math error register and turn normal error checking on.
void = Check_Math()
!Except = curExcept
ENDIF
; After scaling, you may need to replace missing values with the
; missing index.
IF N_Elements(missingCnt) NE 0 THEN BEGIN
IF missingCnt GT 0 THEN tempImage[missingIndices] = missing_index
ENDIF
; If you created a temporary image, then return that.
; Otherwise you can return the original image, modified
; to the appropriate size.
IF N_Elements(tempImage) EQ 0 THEN BEGIN
IF (N_Elements(xsize) EQ 0) THEN BEGIN
RETURN, image
ENDIF ELSE BEGIN
RETURN, cgResizeImage(image, xsize, ysize, $
INTERP=interpolate, MINUS_ONE=minus_one)
ENDELSE
ENDIF ELSE BEGIN
IF (N_Elements(xsize) EQ 0) THEN BEGIN
RETURN, tempImage
ENDIF ELSE BEGIN
RETURN, cgResizeImage(tempImage, xsize, ysize, $
INTERP=interpolate, MINUS_ONE=minus_one)
ENDELSE
ENDELSE
END
;+
; The purpose of this program is to create a TV command that works the way
; the TV command would be expected to work if it was written today, rather
; than 25 years ago. In other words, it knows the difference between an
; 8-bit device and a 24-bit device, it honors the POSITION keyword like
; other graphics commands in IDL, it honors the !P.MULTI value, like other
; graphics commands in IDL, it works seamlessly with both 8-bit and 24-bit
; images. In addition to other modern features, this program can also
; display images that contain an alpha channel and can display transparent
; images.
;
; Also, two-dimensional image arrays can be manipulated, stretched,
; and scaled directly with keywords to cgImage. These keywords do not
; work with alpha channel images, or if the TV keyword is used with
; cgImage.
;
; :Params:
; image: in, required, type=various
; An 8-bit (MxN), 24-bit (e.g., MxNx3), or a 24-bit + alpha channel
; (e.g., MxNx4) image to display.
; x: in, optional, type=integer
; The X position of the lower-left corner of the image in device
; coordinates. This parameter is only recognized if the TV keyword
; is set. If the Y position is not used, X is taken to be the image
; "position" in the window. See the TV command documenation for details.
; y: in, optional, type=integer
; The Y position of the lower-left corner of the image in device
; coordinates. This parameter is only recognized if the TV keyword
; is set.
;
; :Keywords:
; addcmd: in, optional, type=boolean, default=0
; Set this keyword to add this command to an already open cgWindow to
; be executed when the window is resized. If the DISPLAY keyword is also
; set, this keyword will act as if the WINDOW keyword were set.
; alphabackgroundimage: in, optional, type=varies
; Normally, when a image with an alpha channel is displayed, the image is
; blended with whatever is currently in the display window. This means, the
; program has to obtain that background image. This is not a problem on devices
; (e.g., WIN, X, Z) that allow this kind of operation, but it is on devices
; (e.g., the PostScript device, PS) that do not. To get around this problem,
; you can pass the background image to the cgImage program. This background image
; will be blended with the alpha channel image you wish to display. If an alpha
; channel image is displayed on a device in which there is no way to obtain the
; background image, and this keyword is not used to pass a background image, then
; the alpha channel image will be blended with a white background image.
; This keyword is only used if an alpha channel image is passed to the
; program via the IMAGE parameter. The AlphaBackgroundImage does not need
; to have the same dimensions as the alpha channel image. The background image
; can be either a 2D image or a 24-bit image.
; alphabgposition: in, optional, type=fltarr(4)
; The normalized position or portion of the background image that is going to be used
; to create the alpha channel image. Normally, and by default, the alphabgposition encompasses
; the entire graphics window, [0.0, 0.0, 1.0, 1.0].
; alphafgposition: in, optional, type=fltarr(4)
; The normalized position in the background image where the input image is to be located.
; By default, the input image takes up the entire extent of the background image, [0.0, 0.0, 1.0, 1.0].
; axis: in, optional, type=boolean, default=0
; A misspelled version of the AXES keyword. Provided as a service to people whose
; fingers have minds of their own.
; axes: in, optional, type=boolean, default=0
; Set this keyword to display the image with axes surrounding the image. If the POSITION
; keyword is not used, a MARGIN of 0.1 is used to allow the axes to show. If you wish
; to make the image fit entirely inside the axes, set the `FIT_INSIDE` keyword. Otherwise,
; the axis sit on top of the image data.
; axkeywords: in, optional, type=structure
; A structure of AXIS keywords and values that can be used to configure the axes
; in whatever way the user desires. Many of the most often used axis keywords are available
; as cgImage keywords. For example::
; IDL> axis_format = {XTicks:4, XTickname:['Cow', 'Pig', 'Dog', 'Cat', 'Owl']}
; IDL> cgImage, cgDemoData(7), AXKEYWORDS=axis_format, /Axes, XRange=[0,20]
; background: in, optional, type=string, default='white'
; The name of the background color for the image display. Unlike the TV command in IDL,
; the cgImage command will erase the display before executing the command like other
; fundamental graphics commands (e.g., Plot, Contour, Surface) in IDL.
; beta: in, optional, type=float, default=3.0
; The beta factor in a Hyperpolic Sine stretch. Available only with 2D images.
; bottom: in, optional, type=integer, default=0
; If the SCALE keyword is set, the image is scaled before display so that all
; displayed pixels have values greater than or equal to BOTTOM and less than
; or equal to TOP. Available only with 2D images.
; brewer: in, optional, type=boolean, default=0
; This keyword is used only if the `CTIndex` keyword is used to select a color table number.
; Setting this keyword allows Brewer color tables to be used.
; charsize: in, optional, type=float
; Sets the character size. Used only if the AXES keyword is also set. By default,
; the value from cgDefCharsize().
; clip: in, optional, type=float, default=2
; A number between 0 and 50 that indicates the percentage of pixels to clip
; off either end of the image histogram before performing a linear stretch.
; Available only with 2D images.
; color: in, optional, type=string, default='opposite'
; The name of the color in which to draw the axes. Used only if the `AXES` keyword is set.
; ctindex: in, optional, type=integer
; The index number of a color table. The `Brewer` and `Reverse` keywords will be checked
; to see how to load the color table into the `Palette` keyword. This keyword will take
; precidence over any colors that are loaded with the `Palette` keyword. The default is
; to use whatever colors are loaded in the current hardware color table.
; display: in, optional, type=boolean, default=0
; If this keyword is set, a new display window is created (with cgDisplay) that has the
; same aspect ratio as the image. The image is displayed in that window. If the WINDOW
; keyword is also set, a new cgWindow is created with the WASPECT keyword set to the image
; aspect ratio, and the image is displayed in that new cgwindow.
; erase: in, optional, type=boolean, default=1
; An obsolete keyword. Used only for compatibility with the earlier TVImage command. The
; default for cgImage is to always erase the graphics display before displaying the image
; unless told otherwise by setting the `NOERASE` keyword. This makes cgImage consistent with
; other IDL graphics commands.
; exclude: in, optional
; The value to exclude in a standard deviation stretch.
; exponent: in, optional, type=float, default=4.0
; The logarithm exponent in a logarithmic stretch. Available only with 2D images.
; filename: in, optional, type=string
; The name of a file that IDL can read with READ_IMAGE (e.g, GEOTIFF, TIF, JPEG, PNG, etc.).
; The file is read to obtain the image to be displayed.
; fit_inside: in, optional, type=boolean, default=0
; When the AXES keyword is set, the default is to position the axes on top of the image
; using the POSITION. However, if this keyword is set, the axes are positioned at POSITION
; and the image is sized so that it fits entirely inside the axes.
; font: in, optional, type=integer
; This keyword selects the font used for axis and title display. The default is to use
; the value of !P.Font.
; gamma: in, optional, type=float, default=1.5
; The gamma factor in a gamma stretch. Available only with 2D images.
; interpolate: in, optional, type=boolean, default=0
; Set this keyword to interpolate with bilinear interpolation the display image as it
; is sized to its final position in the display window. Interpolation will potentially
; create image values that do not exist in the original image. The default is to do no
; interpolation, so that image values to not change upon resizing. Interpolation can
; result in smoother looking final images.
; keep_aspect_ratio: in, optional, type=boolean, default=0
; By default, the output image is resized into the `POSITION` in the graphics window.
; This can result in a distortion of the image aspect ratio (the Y size of the image
; divided by the X size of the image). Setting this keyword will preserve the original
; aspect ratio of the image in the output display window. In effect, the image will
; be placed in the window `POSITION` in a way that preserves its aspect ratio. The
; actual final location of the image in the display window can be obtained via the
; `OPOSITION` keyword.
; layout: in, optional, type=intarr
; This keyword specifies a grid with a graphics window and determines
; where the graphic should appear. The syntax of LAYOUT is a 3-element
; array: [ncolumns, nrows, location]. The grid is determined by the
; number of columns (ncolumns) by the number of rows (nrows). The location
; of the graphic is determined by the third number. The grid numbering
; starts in the upper left (1) and goes sequentually by column and then
; by row. Note that using the LAYOUT keyword automatically sets the NOERASE
; keyword to 1.
; mapcoord: in, optional, type=object
; An object reference to a map coordinate object (e.g., cgMap). If present, the
; XRANGE and YRANGE keyword values will be obtained from this map object, if they
; are not defined otherwise.
; margin: in, optional, type=float, default=0.0
; A single value, expressed as a normalized coordinate, that
; can easily be used to calculate a position in the window.
; The margin is used to calculate a `POSITION` that gives
; the image an equal margin around the edge of the window.
; The margin must be a number in the range 0.0 to 0.333. This
; keyword is ignored if the `POSITION` or `OVERPLOT` keywords are
; used. It is also ignored when cgImage is executed in a
; multi-plot window, EXCEPT if it's value is zero. In this
; special case, the image will be drawn into its position in
; the multi-plot window with no margins whatsoever. (The
; default is to have a slight margin about the image to separate
; it from other images or graphics. The default margin is 0.05.)
; maxvalue: in, optional, type=varies
; If this value is defined, the data is linearly scaled between MINVALUE
; and MAXVALUE. MAXVALUE is set to MAX(image) by default. Setting this
; keyword to a value automatically sets `SCALE` to 1. If the maximum value of the
; image is greater than 255, this keyword is defined and SCALE=1.
; mean: in, optional, type=float, default=0.5
; The mean factor in a logarithmic stretch. Available only with 2D images.
; minus_one: in, optional, type=boolean, default=0
; The value of this keyword is passed along to the cgResizeImage
; command. It prevents cgResizeImage from adding an extra row and
; column to the resulting array, which can be a problem with
; small image arrays.
; minvalue: in, optional, type=varies
; If this value is defined, the data is linearly scaled between MINVALUE
; and `MAXVALUE`. MINVALUE is set to MIN(image) by default. Setting this
; keyword to a value automatically sets SCALE=1. If the minimum value of the
; image is less than 0, this keyword is defined and SCALE=1.
; missing_color: in, optional, type=string, default='white'
; The color name of the missing value. Available only with 2D images.