当前位置:网站首页>[chapter 01 image defogging technology based on histogram optimization - full system matlab intelligent driving depth learning]

[chapter 01 image defogging technology based on histogram optimization - full system matlab intelligent driving depth learning]

2022-06-22 01:54:00 Haibao 7

There is no doubt about it , In automotive intelligent technology 、 Automobile new energy technology 、 Automotive electronics is a race track for the best . The requirements of intelligent driving technology are also constantly improving .
Intelligent vehicle teaching platform 、 Intelligent network teaching platform 、 Automobile electronic teaching equipment 、 In the loop simulation system , At present, there are many mainstream systems , Common basic parts and algorithm development , Intelligent driving module , It is better to get started matlab platform .
MATLAB/Simulink The two key parts of the are :m The grammar of the language and the various toolkits it carries .

A powerful toolbox covering all areas is MATLAB The core of software , Various function、app、blcoks Are included in these toolkits . therefore MATLAB/Simulink Learning from , The core is the learning of these toolkits . So we are learning MATLAB When , You can learn by using the toolbox as a unit .
and ,matlab It has obvious advantages in resource integration , Great backwardness , Enough to learn the real thing , From entry to mastery  Insert picture description here

Histogram technology processing

Common means of image enhancement , But the global square equalization often brings distortion to the image , In order to deal with related problems , This paper adopts the global square equilibrium 、 Local square equilibrium and Retinex Algorithm to process the image .
For the specific functions and the application of their syntax , stay matlab Of Help documents can be searched by themselves , Case study and application .
Let's start with an example :
The effect of processing vehicle tires is shown in the figure .
 Insert picture description here

demo.m

clc; clear all; close all;
I = imread('tire.tif');
J = histeq(I);
figure; 
subplot(2, 2, 1); imshow(I, []); title(' Original picture ');
subplot(2, 2, 2); imshow(J, []); title(' Image after original image equalization ');
subplot(2, 2, 3); imhist(I, 64); title(' Histogram of the original image ');
subplot(2, 2, 4); imhist(J, 64); title(' Histogram after equalization ');

image file , The effect of the original image is shown in the figure
 Insert picture description here

Image defogging technology system based on histogram optimization

GUI The interface is as shown in the figure :
 Insert picture description here

Image defogging system , First load the image and display , Then select the defogging algorithm , Finally, you can observe the histogram contrast effect

Initfig.m

function InitFig(hObject,handles)
axes(handles.axes1); cla; set(gca, 'Color', [0.8039 0.8784 0.9686]);
axes(handles.axes2); cla; axis on; box on; set(gca, 'Color', [0.8039 0.8784 0.9686]);
set(gca, 'XTickLabel', [], 'YTickLabel', [], 'XTick', [], 'YTick', []);
set(handles.textInfo, 'String', ...
    ' Image defogging system , First load the image and display , Then select the defogging algorithm , Finally, you can observe the histogram contrast effect .');

Screenshot function
SnapImage.m

function SnapImage()
imagesPath = '.\\snap_images';
if ~exist(imagesPath, 'dir')
    mkdir(imagesPath);
end

[FileName,PathName,FilterIndex] = uiputfile({'*.jpg;*.tif;*.png;*.gif','All Image Files';...
          '*.*','All Files' },' Save the screenshot ',...
          '.\\snap_images\\temp.jpg');
if isequal(FileName, 0) || isequal(PathName, 0)
    return;
end
fileStr = fullfile(PathName, FileName);
f = getframe(gcf);
f = frame2im(f);
imwrite(f, fileStr);
msgbox(' The snapshot file was saved successfully !', ' Prompt information ');

Image saving subfunction :
SaveImage.m

function SaveImage(Img)
imagesPath = '.\\results';
if ~exist(imagesPath, 'dir')
    mkdir(imagesPath);
end

[FileName,PathName,FilterIndex] = uiputfile({'*.jpg;*.tif;*.png;*.gif','All Image Files';...
          '*.*','All Files' },' Save the screenshot ',...
          '.\\results\\result.jpg');
if isequal(FileName, 0) || isequal(PathName, 0)
    return;
end
fileStr = fullfile(PathName, FileName);
imwrite(Img, fileStr);
msgbox(' Processing results saved successfully !', ' Prompt information ');

use Retinex Of MSR Realize image defogging operation .
Subfunctions RemoveFogByRetinex.m

function In = RemoveFogByRetinex(f, flag)
%  use Retinex Of MSR Realize image defogging 
%  Input parameters :
%  f—— Image matrix 
%  flag—— show marks 
%  Output parameters :
%  In—— The resulting image 

if nargin < 2
    flag = 1;
end
% Extract the R、G、B component 
fr = f(:, :, 1);
fg = f(:, :, 2);
fb = f(:, :, 3);
% Data type normalization 
mr = mat2gray(im2double(fr));
mg = mat2gray(im2double(fg));
mb = mat2gray(im2double(fb));
% Definition alpha Parameters 
alpha = 1200;
% Define template size 
n = 128;
% Computing Center 
n1 = floor((n+1)/2);
for i = 1:n
    for j = 1:n
        % Gauss function 
        b(i,j)  = exp(-((i-n1)^2+(j-n1)^2)/(4*alpha))/(pi*alpha);
    end
end
% Convolution filtering 
nr1 = imfilter(mr,b,'conv', 'replicate');
ng1 = imfilter(mg,b,'conv', 'replicate');
nb1 = imfilter(mb,b,'conv', 'replicate');
ur1 = log(nr1);
ug1 = log(ng1);
ub1 = log(nb1);
tr1 = log(mr);
tg1 = log(mg);
tb1 = log(mb);
yr1 = (tr1-ur1)/3;
yg1 = (tg1-ug1)/3;
yb1 = (tb1-ub1)/3;
% Definition beta Parameters 
beta = 55;
% Define template size 
x = 32;
% Computing Center 
x1 = floor((n+1)/2);
for i = 1:n
    for j = 1:n
        % Gauss function 
        a(i,j)  = exp(-((i-n1)^2+(j-n1)^2)/(4*beta))/(6*pi*beta);
    end
end
% Convolution filtering 
nr2 = imfilter(mr,a,'conv', 'replicate');
ng2 = imfilter(mg,a,'conv', 'replicate');
nb2 = imfilter(mb,a,'conv', 'replicate');
ur2 = log(nr2);
ug2 = log(ng2);
ub2 = log(nb2);
tr2 = log(mr);
tg2 = log(mg);
tb2 = log(mb);
yr2 = (tr2-ur2)/3;
yg2 = (tg2-ug2)/3;
yb2 = (tb2-ub2)/3;
% Definition eta Parameters 
eta = 13944.5;
% Define template size 
l = 500;
% Computing Center 
l1 = floor((n+1)/2);
for i = 1:n
    for j = 1:n
        % Gauss function 
        e(i,j)  = exp(-((i-n1)^2+(j-n1)^2)/(4*eta))/(4*pi*eta);
    end
end
% Convolution filtering 
nr3 = imfilter(mr,e,'conv', 'replicate');
ng3 = imfilter(mg,e,'conv', 'replicate');
nb3 = imfilter(mb,e,'conv', 'replicate');
ur3 = log(nr3);
ug3 = log(ng3);
ub3 = log(nb3);
tr3 = log(mr);
tg3 = log(mg);
tb3 = log(mb);
yr3 = (tr3-ur3)/3;
yg3 = (tg3-ug3)/3;
yb3 = (tb3-ub3)/3;
dr = yr1+yr2+yr3;
dg = yg1+yg2+yg3;
db = yb1+yb2+yb3;
cr = im2uint8(dr);
cg = im2uint8(dg);
cb = im2uint8(db);
%  Integrate the processed components to obtain the result image 
In = cat(3, cr, cg, cb);
% Results show 
if flag
    figure;
    subplot(2, 2, 1); imshow(f); title(' Original image ', 'FontWeight', 'Bold');
    subplot(2, 2, 2); imshow(In); title(' Processed image ', 'FontWeight', 'Bold');
    %  Graying , Used to calculate histogram 
    Q = rgb2gray(f);
    M = rgb2gray(In);
    subplot(2, 2, 3); imhist(Q, 64); title(' Original gray histogram ', 'FontWeight', 'Bold');
    subplot(2, 2, 4); imhist(M, 64); title(' Processed gray histogram ', 'FontWeight', 'Bold');
end

Gray histogram and image normalization function :
RemoveFogByGlobalHisteq.m

function In = RemoveFogByGlobalHisteq(I, flag)

if nargin < 2
    flag = 1;
end
R = I(:,:,1);
G = I(:,:,2);
B = I(:,:,3);
M = histeq(R);
N = histeq(G);
L = histeq(B);
In = cat(3, M, N, L);
if flag
    figure;
    subplot(2, 2, 1); imshow(I); title(' Original image ', 'FontWeight', 'Bold');
    subplot(2, 2, 2); imshow(In); title(' Processed image ', 'FontWeight', 'Bold');
    Q = rgb2gray(I);
    W = rgb2gray(In);
    subplot(2, 2, 3); imhist(Q, 64); title(' Original gray histogram ', 'FontWeight', 'Bold');
    subplot(2, 2, 4); imhist(W, 64); title(' Processed gray histogram ', 'FontWeight', 'Bold');
end

All the source code of this article is packaged and sorted out –> Portal

Image defogging technology based on histogram optimization - The whole system –MATLAB Intelligent driving deep learning
The global processing effect is shown in the figure .
 Insert picture description here
The effect of local histogram equalization
 Insert picture description here
adopt Retinex Comparison of the fog removal effect of the algorithm :

 Insert picture description here

Compare with the corresponding histogram
 Insert picture description here
Run the main process file
MainForm.fig
Download a full set of source code

原网站

版权声明
本文为[Haibao 7]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206220101378996.html