Module: GDAL::RasterBandMixins::AlgorithmMethods::ClassMethods
- Defined in:
- lib/gdal/raster_band_mixins/algorithm_methods.rb
Instance Method Summary collapse
-
#compute_median_cut_pct(red_band, green_band, blue_band, colors, color_interpretation, progress_function: nil, progress_arg: nil) ⇒ GDAL::ColorTable
Compute the optimal PCT for RGB image.
-
#dither_rgb_to_pct(red_band, green_band, blue_band, output_band, color_table, progress_function: nil, progress_arg: nil) ⇒ GDAL::RasterBand
24-bit to 8-bit conversion with dithering.
Instance Method Details
#compute_median_cut_pct(red_band, green_band, blue_band, colors, color_interpretation, progress_function: nil, progress_arg: nil) ⇒ GDAL::ColorTable
Compute the optimal PCT for RGB image. Implements a median cut algorithm to compute an “optimal” pseudo-color table for representing an input RGB image. This PCT could then be used with dither_rgb_to_pct
to convert a 24-bit RGB image into an 8-bit pseudo-colored image.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/gdal/raster_band_mixins/algorithm_methods.rb', line 27 def compute_median_cut_pct(red_band, green_band, blue_band, colors, color_interpretation, progress_function: nil, progress_arg: nil) color_table = GDAL::ColorTable.new(color_interpretation) FFI::GDAL::Alg.GDALComputeMedianCutPCT( red_band, green_band, blue_band, nil, # This isn't yet supported in GDAL. colors, color_table.c_pointer, progress_function, progress_arg ) color_table end |
#dither_rgb_to_pct(red_band, green_band, blue_band, output_band, color_table, progress_function: nil, progress_arg: nil) ⇒ GDAL::RasterBand
24-bit to 8-bit conversion with dithering. Utilizes Floyd-Steinberg dithering, using the provided color table.
The red, green, and blue input bands do not necessarily need to come from the same file, but they must be the same width and height. They will be clipped to 8-bit during reading, so non-eight bit bands are generally inappropriate. Likewise, output_band
will be written with 8-bit values and must match the width and height of the source bands.
The ColorTable cannot have more than 256 entries.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/gdal/raster_band_mixins/algorithm_methods.rb', line 66 def dither_rgb_to_pct(red_band, green_band, blue_band, output_band, color_table, progress_function: nil, progress_arg: nil) red_ptr = GDAL._pointer(GDAL::RasterBand, red_band) green_ptr = GDAL._pointer(GDAL::RasterBand, green_band) blue_ptr = GDAL._pointer(GDAL::RasterBand, blue_band) output_ptr = GDAL._pointer(GDAL::RasterBand, output_band) color_table_ptr = GDAL._pointer(GDAL::ColorTable, color_table) FFI::GDAL::Alg.GDALDitherRGB2PCT( red_ptr, green_ptr, blue_ptr, output_ptr, color_table_ptr, progress_function, progress_arg ) output_band end |