1
$\begingroup$

I have a multispectral satellite image and I would like to "transform" each of the image bands into one with integer values. For example to stretch? the image between 0 and 255. Not sure how to proceed with this. I also thought I could make a histogram and replace each pixel value with the bin edge in which it falls into. I'm not sure. I'm currently working in python. Any thoughts on this?

$\endgroup$
  • $\begingroup$ What does your image look like now? Oh, and if it was captured by a satellite/computer, it's already discrete. $\endgroup$ – Scott Aug 29 '14 at 1:04
  • $\begingroup$ Yeah, sorry about that. Bad habbit of mine. Image is float and I want to make it an integer. $\endgroup$ – JEquihua Aug 29 '14 at 2:43
  • 1
    $\begingroup$ If I'm interpreting your question correctly, I would do something like x = floor(x * 255) with numpy. $\endgroup$ – Scott Aug 29 '14 at 16:04
2
$\begingroup$

You should check the Envi documentation (a standard tool for working with multi/hyper spectral images) on the stretches it uses to fit multi/hyperspectral data into 8 bits for display.

Here is the page on some of the stretches used, which apply an affine function to the pixel values and clip the values to the lowest and highest displayable value. In particular, look at the optimized linear stretch, which is the default one Envi uses to display things.

$\endgroup$
2
$\begingroup$

As pointed out by Scott in comment, the quick'n dirty way of doing it is to just multiply by 255 and taking the integer part of the result.

The actual answer is (unfortunately, it's a very common answer to many Image Processing tasks...) "it depends":

  • float images are usually assumed to have values between 0 and 1, but maybe it's not the case of your sensor, in which case you need to pre-multiply the values in th equi'n dirty solution by the inverse of the dynamic range of the data;
  • if you need to perform some contrast enhancement, you can apply this pre-multiplication channel-wise (by first computing the max value for each channel), for all the data at once (by looking for the max among all the channels), or you can allocate the dynamic range in a more astute way (for example by computing histograms as you suggest, or clustering on the data values...);
  • multispectral images contain usually several spectral channels ;-). If you want to visualize your data, then maybe you're also looking for a way to find a mapping between your data and Red-Green-Blue channels. Sensors that deliver Near Infrared-Red-Green data are usually remapped "as is" (following the ordering of the wavelengths), ie NIR -> Red, Red -> Green, Green -> Red, but composite values such as NDVI can be useful in some contexts;
  • if you have lots of input spectral wavelengths, then you need to choose between visualizing each channel independently, or in a cube...
$\endgroup$
-1
$\begingroup$

I think your description make it harder to understand the question.
It would be easier if you show the range of float image you have.
Is it between 0 and 1?

if it is, so you want to cast it into 0-255 integer. right? just multiply your image by 255 and round it to integer.

Note that, this casting will make your image worse (errors from rounding)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.