imadjust to adjust contrast in matlab

In MATLAB, the imadjust function can be used to adjust the intensity values of an image to improve its contrast. Here is the basic syntax for using imadjust:

main.m
J = imadjust(I, [low_in high_in], [low_out high_out], gamma)
61 chars
2 lines
  • I is the input image.
  • [low_in high_in] specifies the range of pixel values in the input image that will be mapped to the output range [low_out high_out]. By default, [low_in high_in] is the minimum and maximum pixel values in I.
  • [low_out high_out] specifies the desired range of output pixel values. By default, [low_out high_out] is the minimum and maximum values that can be represented by the image's class.
  • gamma is an optional parameter that adjusts the shape of the intensity mapping function. A value of 1 (the default) means a linear mapping.

Here is an example of using imadjust to enhance the contrast of an image:

main.m
I = imread('cameraman.tif');
J = imadjust(I, [0.3 0.7], [0 1]);
imshowpair(I, J, 'montage');
93 chars
4 lines

This code reads in the "cameraman.tif" image, sets the input intensity range to be from 0.3 to 0.7, and sets the output intensity range to be from 0 to 1. It then displays the original image and the adjusted image side-by-side for comparison using the imshowpair function.

Note that imadjust can be very useful for improving the visibility of details in an image, but it can also lead to loss of information or artifacts if used excessively. Always experiment with different intensity ranges and the gamma parameter to find the best settings for your particular image.

gistlibby LogSnag