Image Enhancement (1-Gray Level Transform) - Intensive MATLAB Source Code

Starting with three questions:

First question: What is the enhancement of digital images?

Personal understanding is that by smoothing and denoising the image, changing the gray level or enhancing the edge, we can show some image features we want more clearly. This is image enhancement, which focuses on contrast stretching.

Question 2: What are the benefits of image enhancement for us after a long time?

To put it plainly, image enhancement is an image preprocessing work, which makes the desired image features more conspicuous and lays a good foundation for target extraction and recognition in the later stage.

Third question: What are the methods of image enhancement?

It's hard for me to have a small partner to say that. There are gray level transformation methods to adjust gray level (what are linear, non-linear and segmented.) (What low pass, median, mean.) (What Qualcomm, sobel Operator, roberts Operator...) To see such an answer, I can only say: there is nothing wrong with old iron. But what I'm trying to say is that you're in a state of flux. I only know the time domain and the frequency domain... Hey.

OK, no more nonsense. Look at the text...

Let's look at the time domain (some people say it's airspace)

There are generally two ways in time domain: gray level transformation and convolution operation. Next, let's come to see Ha one by one. This section focuses on gray level transformation

Gray level transformation means that white dots change the gray value of part of the pixels in the image. The purpose is to expand the gray level and make the image brighter and darker, and that's all (it belongs to the simplest category in image enhancement). The general method is linear change and non-linear change. Linear variation mainly includes: proportional, inverse and piecewise functions; non-linear mainly includes: power function, logarithmic function and so on. The principle is relatively simple and directly embodied in the code.

Examples: take the image pout.tif with MATLAB as the original image

% Linear variation

close all; clear all; clc
I = imread('pout.tif');
figure;imshow(I);title('Original graph')
%Linear change, global brightening.function y = 2x + 33
g1 = 2.*I + 3;
figure;
subplot(221);imshow(I);title('Original graph');
subplot(222);imhist(I);title('Gray histogram of original image')
subplot(223);imshow(g1,[]);title('Brightening image after linear transformation')
subplot(224);imhist(g1);title('Gray Histogram of Brightened Image after Linear Transform')

%Linear change, global darkening, function y = x-50
g2 = I - 50;
figure;
subplot(221);imshow(I);title('Original graph');
subplot(222);imhist(I);title('Gray histogram of original image')
subplot(223);imshow(g2,[]);title('Darkened image after linear transformation')
subplot(224);imhist(g2);title('Gray Histogram of Darkened Image after Linear Transform')

%Piecewise function          0        x<50
%        y =   2*x + 3  50<x<=150
%                255      x>150
[m,n] = size(I);
J = ones(m,n);
for i=1:m
    for j=1:n
        if I(i,j) < 50
            J(i,j) = 0;
        elseif I(i,j) > 150
            J(i,j) = 255;
        else
            J(i,j) = I(i,j) + 50;
        end
    end
end
J = uint8(J);
figure;
subplot(221);imshow(I);title('Original graph');
subplot(222);imhist(I);title('Gray histogram of original image')
subplot(223);imshow(J);title('Image transformed by piecewise function')
subplot(224);imhist(J);title('Gray Histogram of Image after Segmental Transform')

Processing results:

From the processing results of the above image, we can see that the gray level transformation is to change the gray value of each pixel in the image. Especially the histogram of the second and third images can clearly see that the whole histogram moves 50 to the left because the whole gray value of the second image is reduced by 50. All those below and above 50 belong to 0 and 255, leaving only one part, and adding 50 to that part, so the histogram looks thinner, but it still has a rough shape, and moves 50 to the right.

Ok, this part is the gray level transformation of the linear part, and then the non-linear part.

log type, curve type, exponential type.

close all; clear all; clc
I = imread('pout.tif');
%Exponential type   y = 30*(log(x+1))
J = im2double(I);%Because I belong to uint Type, in progress log Or when the exponent runs, it must be converted to double type
K = 30*(log(J+1));
K = uint8(K);
subplot(221);imshow(I);title('Original graph');
subplot(222);imhist(I);title('Gray histogram of original image')
subplot(223);imshow(K,[]);title('log Transformed image')
subplot(224);imhist(K);title('log Gray histogram of transformed image')

%Curve shape y = x+ x*(255-x)/255
K1 = I + I.*(255-I)./255;
figure;
subplot(221);imshow(I);title('Original graph');
subplot(222);imhist(I);title('Gray histogram of original image')
subplot(223);imshow(K1,[]);title('Image after Curve Transform')
subplot(224);imhist(K1);title('Gray histogram of image after curve transformation')

%Exponential type y = e^(-0.5*x + 3)
K2 = exp(-0.5.*J + 3);
K2 = uint8(K2);
figure;
subplot(221);imshow(I);title('Original graph');
subplot(222);imhist(I);title('Gray histogram of original image')
subplot(223);imshow(K2,[]);title('Image after Curve Transform')
subplot(224);imhist(K2);title('Gray histogram of image after curve transformation')

Processing results:

OK, let's finish the gray level transformation. The next section is convolution operation.

 

Tags: MATLAB

Posted on Wed, 07 Aug 2019 06:15:02 -0700 by karlitosphere