A list,

The main purpose of transforming the original image from RGB color space to HSV color space for enhancement processing is to separate the color component from brightness component and saturation component, keep the color component unchanged, and adjust brightness component and saturation component. In this way, the color distortion caused by the traditional method of adjusting the three color channels in RGB color space can be avoided, and the enhanced image can be more consistent with the visual characteristics of human eyes. The conversion from RGB color space to HSV color space is from unit cube based on Cartesian cartesian coordinate system to double cone based on cylindrical polar coordinate system. The basic principle of conversion is to separate brightness component in RGB, decompose chroma into hue and saturation components, and represent hue with Angle vector. The traditional Retinex algorithm uses gaussian function as its surrounding function, and the Gaussian function in MSR algorithm is replaced by bilateral filtering function. Compared with Gaussian filtering, bilateral filtering can enhance the smoothness of both spatial and temporal domain, avoid the misjudgment of Gaussian filtering, and better preserve the image edge information. The edge of the processed image is more smooth and continuous, and the image halo problem can be solved to a certain extent. The value of sigMA_S is [15 70 110], and the value of sigma_r is [0.05 0.10 0.15]. In order to make the color of the image more natural, gamma transform is performed on the incident component after bilateral filtering, where C =0.77; Gamma =[0.05 0.1 0.3].

Ii. Source code

clear all; %clear the values clc; %clear the command window tic strhead ='5'; %the name of file strtail ='.bmp'; % the format of the file str =strcat(strhead,strtail); img = im2double(imread(str)); %read the imageand convert to double.
N = 15; %the size of filter sigma = [100 , 0.3]; %the parameters of bilateral filter retimg = bialteral(img , N , sigma ); %get the illumination image

subplot(1.3.1); imshow(img); title('the original image');
subplot(1.3.2); imshow(retimg); title('the illumination image');

%% s-l
img_copy = rgb2hsv(img);
img_copy3 = log(img_copy(:,:,3));
retimg_copy = rgb2hsv(retimg);
retimg_copy3 = log(retimg_copy(:,:,3)); %only to v layer r_img = img_copy3 - retimg_copy3; r_img =exp(r_img);
N = 4;
sigma = [100.0.3];
retinex_img(:,:,3) = bialteral2(r_img,N,sigma); %get reflect image dim = size(img);for i = 1:dim(1)
     for j = 1:dim(2)        
         img_copy(i,j,3) = img_copy(i,j,3) ^ (1/3);         
     end
end
retinex_img(:, :,3) = retinex_img(:,:,3).*(img_copy(:,:,3));
 
retinex_img(:,:,1) = img_copy(:,:,1);
retinex_img(:,:,2) = img_copy(:,:,2); retinex_img = hsv2rgb(retinex_img); function retimg = bialteral(img ,N ,sigma) %% colorspace transformation img = rgb2hsv(img); %convert rgb to hsv colorspace in order to process %% pre-computer domain filtering sigma_d = sigma(1);
sigma_r = sigma(2); [X,Y] = meshgrid(-N:N,-N:N); %generate two matrix D =exp(-(X.^2+Y.^2)/(2*sigma_d^2)); %domain weights with Euclidean distance %% create waitbar h = waitbar(0.'tiny illumination retinex algorithm... ');
set(h,'Name'.'Illumination Retinex'); %% rang filtering in v layer dim = size(img); %dim=[height,length,3] B = zeros(dim); %create an image B with the same sizeand dimension with the zero value.
for i = 1:dim(1)
    for j = 1:dim(2)
        iMin = max(i-N,1);
        iMax = min(i+N,dim(1));
        jMin = max(j-N,1);
        jMax = min(j+N,dim(2));
        L = img(iMin:iMax,jMin:jMax,3); %extract the local region d = L-img(i,j,3); %the dissimilarity between the surroudand center
          
        R = exp(-(d.^2)/(2*sigma_r^2)); %range filter weights F = R.*D((iMin:iMax)-i+N+1,(jMin:jMax)-j+N+1); %its row is from iMin-i+N+1 to iMax-i+N+1.and so as line
        for m = 1:iMax-iMin+1
            for n = 1:jMax-jMin+1
                if d(m,n) < 0
                    F(m,n) = 0;
                end
            end
        end
        norm_F = sum(F(:));
        B(i,j,3) = sum(sum(F.*L))/norm_F;

        retimg(i,j,1) = img(i,j,1);
        retimg(i,j,2) = img(i,j,2);
        retimg(i,j,3) = B(i,j,3);
    end
    waitbar(i/dim(1));
end
close(h); %close the barCopy the code

3. Operation results

Fourth, note

Version: 2014 a