FUNCTION MASK_IMAGE, IMAGE, MASK, TEST, COLOR, NAMES = NAMES, RUNCOLOR = RUNCOLOR rcs_id = "$Id: mask_image.pro,v 1.1 2003/06/30 20:27:21 gumley Exp $" ;+ ; PURPOSE: ; To apply a cloud mask color overlay to an 8 bit image. The user selects ; the cloud mask results to be displayed, and the color table entries to be ; used for each result. The image and mask arrays must have the same ; X and Y dimensions. The image array must be of BYTE type (i.e. already ; scaled to byte values). ; ; This function may be used with either the MAS or MODIS 48 bit cloud mask. ; ; INPUT: ; IMAGE 2D image array of BYTE type dimensioned [NX,NY] ; MASK 3D cloud mask array of BYTE type dimensioned [6,NX,NY] ; TEST 1D vector of cloud mask results to be displayed (see table) ; COLOR 1D vector of color table entries for cloud mask results ; ; OUTPUT: ; MASK_IMAGE 2D image array of BYTE type dimensioned [NX,NY]. Any pixel ; where a test is true (TEST vector) has it's value changed ; to the corresponding COLOR value. ; ; REVISED: ; 02-SEP-1997 Liam Gumley, CIMSS/SSEC ; ; EXAMPLE: ; The IDL procedures MAS_READ, MASK_READ, and COLORS are available in ; SHARP version 1.09. To use these routines, RESTORE the SHARP 1.09 save ; file before executing the example below. ; ;; Read MAS image ;mas_read, 'sample.hdf', 2, image, date, time1, time2, nscans = nscans, scene = [0,715] ; ;; Convert to BYTE type, leaving 16 entries open at the bottom of the color table ;image = bytscl( temporary( image ), top = !d.table_size - 1 - 16 ) + 16B ; ;; Read cloud mask ;mask_read, 'sample.cm', date, time1, nscans, mask, scene = [0,715] ; ;; Load 16 graphics colors at the bottom of the color table ;colors ; ;; Create image with cloud mask overlay ;test = [ 5, 4, 3 ] ;color = [ 4, 2, 5 ] ;newimage = mask_image( image, mask, test, color ) ; ;; Display image ;window, /free, xs=716, ys=716 ;loadct, 0, bottom = 16, ncolors = !d.table_size - 16 ;tv, newimage ; ; NOTES: ; The cloud mask test results in the input argument TEST are defined as shown below: ; ; Result Meaning ; ------ ------- ; ; 0 Cloud mask not determined ; 1 Cloud mask determined ; 2 Cloudy ; 3 Undecided ; 4 Probably clear ; 5 Confident clear ; 6 Night ; 7 Day ; 8 Sunglint ; 9 Snow/ice ; 10 Water ; 11 Coast ; 12 Desert ; 13 Land ; 14 Smoke or Dust ; 15 Thin cirrus VIS ; 16 Shadow ; 17 Thin cirrus IR ; 18 IR Threshold ; 19 CO2 ; 20 6.7 micron ; 21 1.88 micron ; 22 3.7-12 micron ; 23 IR Difference ; 24 3.7-11 micron ; 25 VIS Threshold ; 26 VIS Ratio ; 27 .935/.87 micron ; 28 3.7-3.9 micron Test ; 29 Temporal Variation ; 30 Spatial Variation ;- ;- set default return value result = -1 ;- set test names test_names = [ $ 'Cloud mask not determined', $ 'Cloud mask determined', $ 'Cloudy', $ 'Undecided', $ 'Probably clear', $ 'Confident clear', $ 'Night', $ 'Day', $ 'Sunglint', $ 'Snow or Ice', $ 'Water', $ 'Coast', $ 'Desert', $ 'Land', $ 'Smoke or Dust', $ 'Thin Cirrus VIS', $ 'Shadow', $ 'Thin Cirrus IR', $ 'IR Threshold', $ 'CO2', $ '6.7 micron', $ '1.88 micron', $ '3.7-12 micron', $ 'IR Difference', $ '3.7-11 micron', $ 'VIS Threshold', $ 'VIS Ratio', $ '.935/.87 micron', $ '3.7-3.9 micron', $ 'Temporal Var.', $ 'Spatial Var.' ] ;- check image argument sz = size( image ) if sz( 0 ) ne 2 or sz( 3 ) ne 1 then begin help, image message, 'IMAGE argument must be a 2D BYTE array', /continue return, result endif nx = sz( 1 ) ny = sz( 2 ) ;- check mask argument sz = size( mask ) if sz( 0 ) ne 3 or sz( 4 ) ne 1 then begin help, mask message, 'MASK argument must be a 3D BYTE array', /continue return, result endif if sz( 2 ) ne nx or sz( 3 ) ne ny then begin help, image help, mask message, 'MASK argument must have the same row and column dimensions as IMAGE', /continue return, result endif if sz( 1 ) ne 6 then begin help, mask message, 'MASK argument must have dimensions [6,NX,NY]', /continue return, result endif ;- check test argument if n_elements( test ) lt 1 then begin help, test message, 'TEST argument must be a variable or 1D vector', /continue return, result endif ;- check color argument if n_elements( color ) ne n_elements( test ) then begin help, test, color message, 'COLOR argument must have the same number of elements as TEST', /continue return, result endif ;- check keywords if n_elements( runcolor ) eq 0 then runcolor = 3 ;- define bitmask and value to check for each test ;- cloud mask byte 1 (tests 0-13) masks = [ 1B, 1B, 6B, 6B, 6B, 6B, 8B, 8B, 16B, 32B, 192B, 192B, 192B, 192B ] value = [ 0B, 1B, 0B, 2B, 4B, 6B, 0B, 8B, 0B, 0B, 0B, 64B, 128B, 192B ] ;- cloud mask byte 2 (tests 14-20) masks = [ masks, 1B, 2B, 4B, 8B, 32B, 64B, 128B ] value = [ value, 0B, 0B, 0B, 0B, 0B, 0B, 0B ] ;- cloud mask byte 3 (tests 21-28) masks = [ masks, 1B, 2B, 4B, 8B, 16B, 32B, 64B, 128B ] value = [ value, 0B, 0B, 0B, 0B, 0B, 0B, 0B, 0B ] ;- cloud mask byte 4 (tests 29-30) masks = [ masks, 1B, 2B ] value = [ value, 0B, 0B ] ;- cloud mask byte 5 (run/not-run bits for tests 18-25) masks = [ masks, 1B, 2B, 4B, 8B, 16B, 32B, 64B, 128B ] value = [ value, 0B, 0B, 0B, 0B, 0B, 0B, 0B, 0B ] ;- cloud mask byte 6 (run/not-run bits for tests 26-30) masks = [ masks, 1B, 2B, 4B, 8B, 16B ] value = [ value, 0B, 0B, 0B, 0B, 0B ] ;- create image with cloud mask overlay names = strarr( 100 ) result = image for i = 0, n_elements( test ) - 1 do begin ;- overlay the cloud mask results and tests ;- (note that the test checks to see if the bit is NOT set) case 1 of test( i ) le 13 : byte = 0 test( i ) le 20 : byte = 1 test( i ) le 28 : byte = 2 test( i ) le 30 : byte = 3 endcase check = reform( mask( byte, *, * ), nx, ny ) and masks( test( i ) ) loc = where( temporary( check ) eq value( test( i ) ), count ) if count ge 1 then result( temporary( loc ) ) = byte( color( i ) ) names( i ) = test_names( test( i ) ) endfor names = names( 0 : n_elements( test ) - 1 ) ;- return modified image array return, result END