Image Inversion

InvertIm inverts an image array im in the sense of reversing its grayscale (NOT matrix inversion)
3.8K Downloads
Updated 11 Apr 2007

No License

InvertIm generalized image inversion (grayscale reversal)

This function has several options that are useful for inversion of medical images for use in other software.

invIm=InvertIm(im) inverts an image array im in the sense of reversing its grayscale (NOT matrix inversion). InvertIm effects the inversion by computing new image data rather than by reversing the colormap or look-up-table (LUT), which is often, but not always, a better approach. im can be an array of any dimension composed of numeric or binary elements (integers [uint8, int8, uint16, int16, etc.], floating point [double or single], or logical). The result invIm is the same data class as im.

For numeric arrays, the inverse is computed using

invIm = (maxVal + minVal) - im

with appropriate treatment of the different data types. For integer arrays, minVal and maxVal are the minimum and maximum allowed integers. For floating point arrays, if the image data lie within the range [0,1], the inversion is performed with default minVal and maxVal of 0 and 1. If the image data lie outside [0,1], then the minimum and maxmimum values of the data are used for minVal and maxVal.

Invert(im, bitsStored) returns the inverse of the image im using a maxVal of 2^bitsStored. This option is convenient when inverting images with a limited dynamic range, e.g., when you have a 16-bit image that only uses the first 12 bits of data. This option is only applicable to integer data.

invIm=Invert(im, [], lowerLimit) returns the inverse of the image im using a minVal of lowerLimit. This option is useful, for example, when inverting signed integer image data that is only positive.

invIm=Invert(im, [], [], upperLimit) returns the inverse of the image im using a maxVal of upperLimit.

All three optional arguments may be used together (e.g., invIm=Invert(im, bitsStored, lowerLimit, upperLimit)), but upperLimit will supercede bitsStored.

Cite As

Stead Kiger (2024). Image Inversion (https://www.mathworks.com/matlabcentral/fileexchange/14609-image-inversion), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R14SP2
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Images in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0.0