1
1
const generic_docs = "
2
2
- The first form accepts inputs as matrices, or file names of the data bands.
3
- - The second form is more versatile but also more complex to describe.
3
+ - The last form is more versatile but also more complex to describe.
4
4
- `cube`: Is the file name of a 'cube', a multi-layered file normally created with the [`cutcube`](@ref) function.
5
5
If this file was created with band descriptions one can use the `bands` or the `bandnames` options.
6
6
- `bands`: _cubes_ created with [`cutcube`](@ref) assign descriptions starting with \" Band1 ...\" an so on
@@ -12,13 +12,18 @@ const generic_docs = "
12
12
- `bandnames`: When we know the common designation of a band, for example \" Green\" , or any part of a band
13
13
description, for example \" NIR\" , we can use that info to create a `bandnames` string vector that will be
14
14
matched against the cube's bands descriptions.
15
- - `kwargs`:
15
+
16
+ ### Kwargs
16
17
- `threshold`: When a threshold is provided we return a GMTgrid where `vals[ij] < threshold = NaN`
17
18
- `classes`: is a vector with up to 3 elements (class separators) and we return a UInt8 GMTimage with the
18
19
indices categorized into vals[ij] > classes[1] = 1; vals[ij] > classes[2] = 2; vals[ij] > classes[3] = 3 and 0 otherwise.
19
20
- `mask`: Used together with `threshold` outputs a UInt8 GMTimage mask with `vals[ij] >= threshold = 255` and 0 otherwise
20
21
If `mask=-1` (or any other negative number) we compute instead a mask where `vals[ij] < threshold = 255` and 0 otherwise
21
22
- `save`: Use `save=\" file_name.ext\" ` to save the result in a disk file. File format is picked from file extension.
23
+ - `order` | `bands_order` | `rgb`: For the ``GLI``, ``TGI`` and ``VARI`` (RGB) indices, we allow to reorder the bands
24
+ and change the expected RGB order. Pass in a string, or symbol, with the color order. For example, `order=:rbg`
25
+ will swap the green and blue components making the result index identify the _reds_ instead of the _greens_.
26
+ Not good for vegetation indices, but potentially useful for other purposes.
22
27
23
28
If none of `bands`, `layers` or `bandnames` is provided, we use the default band names shown in the first form.
24
29
@@ -477,6 +482,9 @@ function helper_sp_indices(kwargs...)
477
482
(haskey (dd, :mask )) && delete! (dd, :mask )
478
483
(haskey (dd, :classes )) && delete! (dd, :classes )
479
484
(haskey (dd, :threshold )) && delete! (dd, :threshold )
485
+ (haskey (dd, :rgb )) && delete! (dd, :rgb )
486
+ (haskey (dd, :order )) && delete! (dd, :order )
487
+ (haskey (dd, :bands_order )) && delete! (dd, :bands_order )
480
488
(length (d) > 0 ) && println (" Warning: the following options were not consumed in sp_indices => " , keys (dd))
481
489
return mask, rev_mask, classes, threshold, save_name, dbg
482
490
end
@@ -498,11 +506,21 @@ function sp_indices(bnd1::String, bnd2::String, bnd3::String=""; index::String="
498
506
end
499
507
500
508
# ----------------------------------------------------------------------------------------------------------
501
- function sp_indices (rgb:: GMT.GMTimage{UInt8, 3} ; index:: String = " " , kwargs ... )
509
+ function sp_indices (rgb:: GMT.GMTimage{UInt8, 3} ; index:: String = " " , kw ... )
502
510
# This method applyies only in the case of the RGB vegetation indices (GLI, TGI, VARI)
503
511
(index != " GLI" && index != " TGI" && index != " VARI" ) && error (" With RGB images input, only `GLI`, `TGI` and `VARI` indices are supported, not $index " )
504
512
(rgb. layout[3 ] != ' B' ) && error (" For now, only band interleavedRGB composition is supported and not $(rgb. layout) " )
505
- img = sp_indices (view (rgb, :, :, 1 ), view (rgb, :, :, 2 ), view (rgb, :, :, 3 ); index= index, kwargs... )
513
+ # Here we are allowing cheating the indices by altering the bands order. These indices expect (were deffined)
514
+ # the bands in RGB order but nothing stops us to to change that and convert a green index into a blue index.
515
+ # For that pass string with the R,G,B in the wished order to the 'order' option. E.g. 'order="rbg"'
516
+ bds:: Vector{Int} = [1 ,2 ,3 ] # The default RGB order
517
+ if ((val = find_in_kwargs (kw, [:order :bands_order :rgb ])[1 ]) != = nothing )
518
+ o = lowercase (string (val))
519
+ bds[1 ] = (o[1 ] == ' r' ) ? 1 : (o[1 ] == ' g' ) ? 2 : (o[1 ] == ' b' ) ? 3 : error (" Non 'r', 'g' or 'b' in the 'order' option" )
520
+ bds[2 ] = (o[2 ] == ' r' ) ? 1 : (o[2 ] == ' g' ) ? 2 : (o[2 ] == ' b' ) ? 3 : error (" Non 'r', 'g' or 'b' in the 'order' option" )
521
+ bds[3 ] = (o[3 ] == ' r' ) ? 1 : (o[3 ] == ' g' ) ? 2 : (o[3 ] == ' b' ) ? 3 : error (" Non 'r', 'g' or 'b' in the 'order' option" )
522
+ end
523
+ img = sp_indices (view (rgb, :, :, bds[1 ]), view (rgb, :, :, bds[2 ]), view (rgb, :, :, bds[3 ]); index= index, kw... )
506
524
return mat2grid (img, rgb)
507
525
end
508
526
0 commit comments