MATLAB implementation of the pseudo-color gray image enhancement

Pseudo-color enhancement

Pseudo-color enhancement benefits : the ability to distinguish people on the gray scale image is relatively low, and the ability to distinguish colors is very strong, pseudo color enhanced to more effectively extract graphical information, enhance the legibility of the original image details, easier target recognition.

   Pseudo-color enhancement is about various gradation gray scale image in a linear or non-linear mapping function into a different color, to thereby obtain a color image. The main method of dividing method has a density, a gray scale color transform in the frequency domain pseudo-color enhancement and three.
   The following is mainly about grayscale - color transform , to obtain R, G, B three color components according to the mapping function, then the three color components RGB synthesized color image. Specific conversion rules are as follows :( wherein L is a gray scale, I (i, j) is a gray value corresponding to a certain pixel, R, G, B color component corresponding to)

Gray value range R G B
0-L/4 0 4I(i,j) L
L/4-L/2 0 L -4I(i,j)+2L
0-L/4 4I(i,j)-2L L 0
0-L/4 L -4I(i,j)+4L 0

Achieve results

Here Insert Picture Description

Reference Code

im=imread('D:\Fig0419(b).tif');
figure('name','灰度级-彩色变换法');
subplot(1,2,1);
imshow(im);
%将灰度值先转换为double类型便于后续处理
im=double(im);
[M,N]=size(im);
%初始化R,G,B,RGB
R=ones(M,N);
G=ones(M,N);
B=ones(M,N);
RGB=ones(M,N,3);
%灰度值范围
L=256;
for i=1:M
    for j=1:N
        if im(i,j)<=L/4
            R(i,j)=0;
            G(i,j)=4*im(i,j);
            B(i,j)=L;
        else
            if im(i,j)<=L/2
                R(i,j)=0;
                G(i,j)=L;
                B(i,j)=-4*im(i,j)+2*L;
            else
                if im(i,j)<=3*L/4
                    R(i,j)=4*im(i,j)-2*L;
                    G(i,j)=L;
                    B(i,j)=0;
                else
                    R(i,j)=L;
                    G(i,j)=-4*im(i,j)+4*L;
                    B(i,j)=0;
                end
            end
        end
    end
end
%合成伪彩色图像
for i=1:M
    for j=1:N
        RGB(i,j,1)=R(i,j);
        RGB(i,j,2)=G(i,j);
        RGB(i,j,3)=B(i,j);
    end
end
%把大于255的数全部转化为255,而小于255的部分则保持原样不变。
RGB=uint8(RGB);
subplot(1,2,2);
imshow(RGB);
Published 18 original articles · won praise 40 · views 50000 +

Guess you like

Origin blog.csdn.net/seawaysyyy/article/details/105228690