ImageDev

RescaleIntensity

Performs a linear scaling of the gray level values of an image.

Access to parameter description

This algorithm performs a linear scaling of the gray level values of an image to a user-specified interval. It can be applied to images with a gray level range other than [0, 255], and for short or floating point images.
In Figure 1, the input gray levels of interest are in the user-specified interval [a, b], and the output range is the interval [c, d].

<b> Figure 1.</b> The intensity rescaling transformation
Figure 1. The intensity rescaling transformation

The input image is I, and the output image is O. Let [a, b] be the input range and [c, d] the output range, then:
$$ \begin{array}{ll} O(n,m)=c & ~\mbox{if $I(n,m) \leq a$}\\ O(n,m)=\left(\frac{d-c}{b-a}\right)(I(n,m)-a)+c & ~\mbox{if $a < I(n,m) \leq b$}\\ O(n,m)=d & ~\mbox{if $I(n,m) > b$}\end{array} $$ The type of the output image is set by an enumerate as detailed in the Data Type Management section.

See also
See related examples

Function Syntax

This function returns outputImage.
// Function prototype
std::shared_ptr< iolink::ImageView > rescaleIntensity( std::shared_ptr< iolink::ImageView > inputImage, RescaleIntensity::OutputType outputType, RescaleIntensity::RangeMode rangeMode, iolink::Vector2d percentageRange, iolink::Vector2d intensityInputRange, iolink::Vector2d intensityOutputRange, std::shared_ptr< iolink::ImageView > outputImage = nullptr );
This function returns outputImage.
// Function prototype.
rescale_intensity(input_image: idt.ImageType,
                  output_type: RescaleIntensity.OutputType = RescaleIntensity.OutputType.SAME_AS_INPUT,
                  range_mode: RescaleIntensity.RangeMode = RescaleIntensity.RangeMode.MIN_MAX,
                  percentage_range: Union[Iterable[int], Iterable[float]] = [2, 98],
                  intensity_input_range: Union[Iterable[int], Iterable[float]] = [0, 255],
                  intensity_output_range: Union[Iterable[int], Iterable[float]] = [0, 255],
                  output_image: idt.ImageType = None) -> idt.ImageType
This function returns outputImage.
// Function prototype.
public static IOLink.ImageView
RescaleIntensity( IOLink.ImageView inputImage,
                  RescaleIntensity.OutputType outputType = ImageDev.RescaleIntensity.OutputType.SAME_AS_INPUT,
                  RescaleIntensity.RangeMode rangeMode = ImageDev.RescaleIntensity.RangeMode.MIN_MAX,
                  double[] percentageRange = null,
                  double[] intensityInputRange = null,
                  double[] intensityOutputRange = null,
                  IOLink.ImageView outputImage = null );

Class Syntax

Parameters

Parameter Name Description Type Supported Values Default Value
input
inputImage
The input image to normalize. Image Binary, Label, Grayscale or Multispectral nullptr
input
outputType
The output image data type.
UNSIGNED_INTEGER_8_BIT The output image data type is 1 byte depth. Its possible intensities are unsigned integer from 0 to 255.
UNSIGNED_INTEGER_16_BIT The output image data type is 2 bytes depth. Its possible intensities are unsigned integer from 0 to 65,535.
UNSIGNED_INTEGER_32_BIT The output image data type is 4 bytes depth. Its possible intensities are signed integer from 0 to 4,294,967,295.
SIGNED_INTEGER_8_BIT The output image data type is 1 byte depth. Its possible intensities are signed integer from -128 to 127.
SIGNED_INTEGER_16_BIT The output image data type is 2 bytes depth. Its possible intensities are signed integer from -32,768 to 32,767.
SIGNED_INTEGER_32_BIT The output image data type is 4 bytes depth. Its possible intensities are signed integer from -2,147,483,648 to 2,147,483,647.
FLOAT_32_BIT The output image data type is 4 bytes depth. Its possible intensities are unsigned floating-point from -3.4E38 to 3.4E38.
FLOAT_64_BIT The output image data type is 8 bytes depth. Its possible intensities are unsigned floating-point from -1.7E308 to 1.7E308.
SAME_AS_INPUT The output image has the same type as the input image.
Enumeration SAME_AS_INPUT
input
rangeMode
The way to define the input intensity range.
MIN_MAX The input intensity range is between the minimum and the maximum of the image intensities.
OTHER The input intensity range is between user-defined bounds [a,b].
PERCENTILE The input intensity range is between two user-defined percentiles of the image histogram.
Enumeration MIN_MAX
input
percentageRange
The low and high histogram percentile to use when the range mode is set to PERCENTILE (in percent). This parameter is ignored with other range modes. Vector2d [0, 100] {2.f, 98.f}
input
intensityInputRange
The input intensity range [a, b] to use when the range mode is set to OTHER. This parameter is ignored with other range modes. Vector2d Any value {0.f, 255.f}
input
intensityOutputRange
The output intensity range. Vector2d Any value {0.f, 255.f}
output
outputImage
The output image. Its dimensions are forced to the same values as the input. Image nullptr
Parameter Name Description Type Supported Values Default Value
input
input_image
The input image to normalize. image Binary, Label, Grayscale or Multispectral None
input
output_type
The output image data type.
UNSIGNED_INTEGER_8_BIT The output image data type is 1 byte depth. Its possible intensities are unsigned integer from 0 to 255.
UNSIGNED_INTEGER_16_BIT The output image data type is 2 bytes depth. Its possible intensities are unsigned integer from 0 to 65,535.
UNSIGNED_INTEGER_32_BIT The output image data type is 4 bytes depth. Its possible intensities are signed integer from 0 to 4,294,967,295.
SIGNED_INTEGER_8_BIT The output image data type is 1 byte depth. Its possible intensities are signed integer from -128 to 127.
SIGNED_INTEGER_16_BIT The output image data type is 2 bytes depth. Its possible intensities are signed integer from -32,768 to 32,767.
SIGNED_INTEGER_32_BIT The output image data type is 4 bytes depth. Its possible intensities are signed integer from -2,147,483,648 to 2,147,483,647.
FLOAT_32_BIT The output image data type is 4 bytes depth. Its possible intensities are unsigned floating-point from -3.4E38 to 3.4E38.
FLOAT_64_BIT The output image data type is 8 bytes depth. Its possible intensities are unsigned floating-point from -1.7E308 to 1.7E308.
SAME_AS_INPUT The output image has the same type as the input image.
enumeration SAME_AS_INPUT
input
range_mode
The way to define the input intensity range.
MIN_MAX The input intensity range is between the minimum and the maximum of the image intensities.
OTHER The input intensity range is between user-defined bounds [a,b].
PERCENTILE The input intensity range is between two user-defined percentiles of the image histogram.
enumeration MIN_MAX
input
percentage_range
The low and high histogram percentile to use when the range mode is set to PERCENTILE (in percent). This parameter is ignored with other range modes. vector2d [0, 100] [2, 98]
input
intensity_input_range
The input intensity range [a, b] to use when the range mode is set to OTHER. This parameter is ignored with other range modes. vector2d Any value [0, 255]
input
intensity_output_range
The output intensity range. vector2d Any value [0, 255]
output
output_image
The output image. Its dimensions are forced to the same values as the input. image None
Parameter Name Description Type Supported Values Default Value
input
inputImage
The input image to normalize. Image Binary, Label, Grayscale or Multispectral null
input
outputType
The output image data type.
UNSIGNED_INTEGER_8_BIT The output image data type is 1 byte depth. Its possible intensities are unsigned integer from 0 to 255.
UNSIGNED_INTEGER_16_BIT The output image data type is 2 bytes depth. Its possible intensities are unsigned integer from 0 to 65,535.
UNSIGNED_INTEGER_32_BIT The output image data type is 4 bytes depth. Its possible intensities are signed integer from 0 to 4,294,967,295.
SIGNED_INTEGER_8_BIT The output image data type is 1 byte depth. Its possible intensities are signed integer from -128 to 127.
SIGNED_INTEGER_16_BIT The output image data type is 2 bytes depth. Its possible intensities are signed integer from -32,768 to 32,767.
SIGNED_INTEGER_32_BIT The output image data type is 4 bytes depth. Its possible intensities are signed integer from -2,147,483,648 to 2,147,483,647.
FLOAT_32_BIT The output image data type is 4 bytes depth. Its possible intensities are unsigned floating-point from -3.4E38 to 3.4E38.
FLOAT_64_BIT The output image data type is 8 bytes depth. Its possible intensities are unsigned floating-point from -1.7E308 to 1.7E308.
SAME_AS_INPUT The output image has the same type as the input image.
Enumeration SAME_AS_INPUT
input
rangeMode
The way to define the input intensity range.
MIN_MAX The input intensity range is between the minimum and the maximum of the image intensities.
OTHER The input intensity range is between user-defined bounds [a,b].
PERCENTILE The input intensity range is between two user-defined percentiles of the image histogram.
Enumeration MIN_MAX
input
percentageRange
The low and high histogram percentile to use when the range mode is set to PERCENTILE (in percent). This parameter is ignored with other range modes. Vector2d [0, 100] {2f, 98f}
input
intensityInputRange
The input intensity range [a, b] to use when the range mode is set to OTHER. This parameter is ignored with other range modes. Vector2d Any value {0f, 255f}
input
intensityOutputRange
The output intensity range. Vector2d Any value {0f, 255f}
output
outputImage
The output image. Its dimensions are forced to the same values as the input. Image null

Object Examples

auto foam = readVipImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "foam.vip" );

RescaleIntensity rescaleIntensityAlgo;
rescaleIntensityAlgo.setInputImage( foam );
rescaleIntensityAlgo.setOutputType( RescaleIntensity::OutputType::SAME_AS_INPUT );
rescaleIntensityAlgo.setRangeMode( RescaleIntensity::RangeMode::MIN_MAX );
rescaleIntensityAlgo.setPercentageRange( {2, 98} );
rescaleIntensityAlgo.setIntensityInputRange( {0, 255} );
rescaleIntensityAlgo.setIntensityOutputRange( {0, 255} );
rescaleIntensityAlgo.execute();

std::cout << "outputImage:" << rescaleIntensityAlgo.outputImage()->toString();
foam = imagedev.read_vip_image(imagedev_data.get_image_path("foam.vip"))

rescale_intensity_algo = imagedev.RescaleIntensity()
rescale_intensity_algo.input_image = foam
rescale_intensity_algo.output_type = imagedev.RescaleIntensity.SAME_AS_INPUT
rescale_intensity_algo.range_mode = imagedev.RescaleIntensity.MIN_MAX
rescale_intensity_algo.percentage_range = [2, 98]
rescale_intensity_algo.intensity_input_range = [0, 255]
rescale_intensity_algo.intensity_output_range = [0, 255]
rescale_intensity_algo.execute()

print("output_image:", str(rescale_intensity_algo.output_image))
ImageView foam = Data.ReadVipImage( @"Data/images/foam.vip" );

RescaleIntensity rescaleIntensityAlgo = new RescaleIntensity
{
    inputImage = foam,
    outputType = RescaleIntensity.OutputType.SAME_AS_INPUT,
    rangeMode = RescaleIntensity.RangeMode.MIN_MAX,
    percentageRange = new double[]{2, 98},
    intensityInputRange = new double[]{0, 255},
    intensityOutputRange = new double[]{0, 255}
};
rescaleIntensityAlgo.Execute();

Console.WriteLine( "outputImage:" + rescaleIntensityAlgo.outputImage.ToString() );

Function Examples

auto foam = readVipImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "foam.vip" );

auto result = rescaleIntensity( foam, RescaleIntensity::OutputType::SAME_AS_INPUT, RescaleIntensity::RangeMode::MIN_MAX, {2, 98}, {0, 255}, {0, 255} );

std::cout << "outputImage:" << result->toString();
foam = imagedev.read_vip_image(imagedev_data.get_image_path("foam.vip"))

result = imagedev.rescale_intensity(foam, imagedev.RescaleIntensity.SAME_AS_INPUT, imagedev.RescaleIntensity.MIN_MAX, [2, 98], [0, 255], [0, 255])

print("output_image:", str(result))
ImageView foam = Data.ReadVipImage( @"Data/images/foam.vip" );

IOLink.ImageView result = Processing.RescaleIntensity( foam, RescaleIntensity.OutputType.SAME_AS_INPUT, RescaleIntensity.RangeMode.MIN_MAX, new double[]{2, 98}, new double[]{0, 255}, new double[]{0, 255} );

Console.WriteLine( "outputImage:" + result.ToString() );