MATLAB Image Enhancement Program example

Source: Internet
Author: User
Tags square root

 

1. grayscale transformation Enhancement Program:% Gray Transform
CLC;
I = imread ('pout. tif ');
Imshow (I );
J = imadjust (I, [0.3 0.7], [0 1], 1 );   % Transforms the walues in the % intensity image I to values in J by linealy mapping % values between 0.3 and 0.7 to values between 0 and 1.
Figure;
Imshow (j );
J = imadjust (I, [0.3 0.7], [0 1], 0.5 );   % If gamma is less than 1, Mapping Si weighted toward higher (brighter)% Output values.
Figure;
Imshow (j );
J = imadjust (I, [0.3 0.7], [0 1], 1.5 );   % If gamma is greater than 1, the mapping Si weighted toward lower (darker)% Output values.
Figure;
Imshow (j)
J = imadjust (I, [0.3 0.7], [0 1], 1 );   % If top <bottom, the output image is reversed, as in a photographic negative.
Figure;
Imshow (j );

 2. histogram gray transformation % histogram gray transformation
[X, MAP] = imread ('forest. tif ');
I = ind2gray (x, MAP); % converts the indexed image to a grayscale image
Imshow (I );
Title ('original image ');
Improfile % select a diagonal line with the mouse to display the gray value of the Line Segment
Figure; subplot (121)
Plot (0: 0. 01:1, SQRT (0: 0. 01:1 ))
Axis Square
Title ('square root grayscale transformation function ')
Subplot (122)
Maxnum = double (max (I); % get the maximum value of a two-dimensional array
J = SQRT (double (I)/maxnum); % converts the data type to double, and then performs square root Transformation
The % SQRT function does not support the uint8 type.
J = uint8 (J * maxnum); % converts the data type to uint8
Imshow (j)
Title ('square root transformed image') 3. histogram equalization program example % histgram eaqualization
CLC;
% Clear command window
I = imread ('tire. tif ');
% Reads the image in tire. tif into I
Imshow (I );
% Displays the intensity image I with 256 gray levels
Figure;
% Creates a new figure window
Imhist (I );
% Displays a histogram for the intensity image I
J = histeq (I, 64 );
% Transforms the intensity image I, returning J an intensity
Figure;
% Image with 64 discrete levels
Imshow (j );
Figure;
Imhist (j );
J = histeq (I, 32 );
% Transforms the intensity image, returning in % J an intensity
Figure;
% Image with 32 discrete levels
Imshow (j );
Figure;
Imhist (j); 4. histogram-based program example % histgram regulization
CLC;
% Clear command window
I = imread ('tire. tif ');
% Reads the image in tire. tif into I
J = histeq (I, 32 );
% Transforms the intensity image I, returning in
% J an intensity image with 32 discrete levels
[Counts, X] = imhist (j );
% Displays a histogram for the intensity image I
Q = imread ('ut. tif ');
% Reads the image in tire. tif into I
Figure;
Imshow (Q );
Figure;
Imhist (Q );
M = histeq (Q, counts );
% Transforms the intensity image Q so that
% Histogram of the output image m approximately matches counts
Figure;
Imshow (m );
Figure;
Imhist (m); Procedures for enhancing airspace Filtering1. linear smoothing filtering
I = imread ('ight. tif ');
J = imnoise (I, 'sale & pepper', 0.02 );
Subplot (1, 221), imshow (I)
Title ('original image ')
Subplot (1, 222), imshow (j)
Title ('add prepaster noise image ')
K1 = filter2 (fspecial ('average', 3), j)/255; % apply the 3*3 neighbor window method
Subplot (1, 223), imshow (K1)
Title ('neighborhood average filtered image of 3 X3 Windows ')
K2 = filter2 (fspecial ('average', 7), j)/255; % use the 7*7 neighbor window method
Subplot (1, 224), imshow (K2)
Title ('7x7 neighboring average filtered image ')

 

 

2. Median Filter
The two-dimensional median filter function medfit2 in MATLAB is used to remove pretzels from images.
% Image noise ction with median filter
CLC;
Hood = 3; % filter window
[I, MAP] = imread ('Eight. tif ');
Imshow (I, MAP );
Noisy = imnoise (I, 'sale & pepper', 0.05 );
Figure;
Imshow (noisy, MAP );
Filtered1 = medfilt2 (noisy, [hood]);
Figure;
Imshow (filtered1, MAP );
Hood = 5;
Filtered2 = medfilt2 (noisy, [hood]);
Figure;
Imshow (filtered2, MAP );
Hood = 7;
Filtered3 = medfilt2 (noisy, [hood]);
Figure;
Imshow (filtered3, MAP );3. 4. 8-neighbor mean Filtering Algorithm
% Image noise ction with mean Algorithm
CLC;
[I, MAP] = imread ('Eight. tif ');
Noisy = imnoise (I, 'sale & pepper', 0.05 );
Myfilt1 = [0 1 0; 1 1 1; 0 1 0]; % 4 neighborhood average filter Template
Myfilt1 = myfilt1/9; % template Normalization
Filtered1 = filter2 (myfilt1, noisy );
Imshow (filtered1, MAP );
Myfilt2 = [1 1 1; 1 1 1; 1 1 1];
Myfilt2 = myfilt2/9;
Filtered2 = filter2 (myfilt2, noisy );
Figure;
Imshow (filtered2, MAP); examples of frequency enhancement programs1. low-pass filter
% Lowpass filter
CLC;
[I, MAP] = imread ('Eight. tif ');
Noisy = imnoise (I, 'gaussian, 0.05 );
Imshow (noisy, MAP );
Myfilt1 = [1 1 1; 1 1 1; 1 1 1];
Myfilt1 = myfilt1/9;
Filtered1 = filter2 (myfilt1, noisy );
Figure;
Imshow (filtered1, MAP );
Myfilt2 = [1 1 1; 1 2 1; 1 1 1];
Myfilt2 = myfilt2/10;
Filtered2 = filter2 (myfilt2, noisy );
Figure;
Imshow (filtered2, MAP );
Myfilt3 = [1 2 1; 2 4 2; 1 2 1];
Myfilt3 = filter2 (myfilt3, noisy );
Figure;
Imshow (filtered3, MAP );2. An example of a low-pass filter image in bouwbos
I =imread('saturn.png ');
J = imnoise (I, 'sale & pepper', 0.02 );
Subplot (1, 121), imshow (j)
Title ('noisy original image ')
J = double (j );
F = fft2 (j );
G = fftshift (f );
[M, N] = size (f );
N = 3; D0 = 20;
N1 = floor (M/2); N2 = floor (n/2 );
For I = 1: m;
For j = 1: N;
D = SQRT (i-n1) ^ 2 + (j-n2) ^ 2 );
H = 1/(1 + 0.414 * (D/D0) ^ (2 * n ));
G (I, j) = H * g (I, j );
End
End
G = ifftshift (g );
G = uint8 (real (ifft2 (G )));
Subplot (122), imshow (g)
Title ('third-level Butterworth filtered image ')
 Example of a color enhancement program1. Example of true color enhancement:
% True color image decomposition
CLC;
Rgb1_imread('peppers.png ');
Subplot (1, 221), imshow (RGB)
Title ('original true-color image ')
Subplot (222), imshow (RGB (:,:, 1 ))
Title ('red component of a true color image ')
Subplot (223), imshow (RGB (:,:, 2 ))
Title ('green component of a true color image ')
Subplot (224), imshow (RGB (:,:, 3 ))
Title ('Blue components of a true color image ')
 2. Examples of pseudo-color enhancement:
I = imread ('cameraman. tif ');
Imshow (I );
X = grayslice (I, 16); % thresholds the intensity image I using
% Threshold values 1/16, 2/16 ,....., 15/16, returning an indexed % image in X
Figure;
Imshow (x, hot (16 ));
  3. Example of a fake color enhancement processing program
Extends rgb1_imread('ghost.bmp ');
Imshow (RGB );
Rgbnew (:,:, 1) = RGB (:,:, 3 );
Rgbnew (:,:, 2) = RGB (:,:, 1 );
Rgbnew (:,:, 3) = RGB (:,:, 2 );
Figure;
Subplot (121 );
Imshow (RGB );
Subplot (122 );
Imshow (rgbnew );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.