Fire Detection using Image Processing

Hello!My project is stuck in at the point where my algorithm for detecting fire pixels detects areas that aren't fire.For some images it works perfectly but there are many things to improve.
What should I do to reduce areas that are not fire.I've been thinking removing regular areas but I think the fire pixel algorithm could be improved.What do you think?
Any help is welcomed.
The images resulted are
and
function densitate=calcDensitate(test,densitate,ksize)
r=(ksize-1)/2;
[linii,coloane]=size(densitate);
rowBound=linii-r;
colBound=coloane-r;
for j=r+1:colBound
col1=j-r;
col2=j+r;
delta=1;
for k=1:ksize
delta=delta+test(k,col2)-test(k,col1);
end
densitate(r,j)=densitate(r,j-1)+delta/255;
end
for i=r+1:rowBound
row1=i-r;
row2=i+r;
delta=1;
for k=1:ksize
delta=delta+test(row2,k)+test(row1,k);
end
densitate(i,r)=densitate(i-1,r)+delta/255;
end
for i=r+1:rowBound
for j=r+1:colBound
delta=(test(r+i,j+r)-test(i-r,j+r)-test(i+r,j-r)+test(i-r,j-r))/255;
densitate(i,j)=densitate(i-1,j)+densitate(i,j-1)-densitate(i-1,j-1)+delta;
end
end
This is the main function
img=imread('cadru230.jpg');
img=imgaussfilt(img,[3 3]);
tau=40;
subplot(2,2,1);
imshow(img);
red=img(:,:,1);
green=img(:,:,2);
blue=img(:,:,3);
%img=im2double(img);
hsv=rgb2hsv(img);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ycbcrmap=rgb2ycbcr(img);
Y=ycbcrmap(:,:,1);
% Y=round(Y,2);
Cb=ycbcrmap(:,:,2);
% Cb=round(Cb,2);
Cr=ycbcrmap(:,:,3);
% Cr=round(Cr,2);
%%%%%%%%%%%%%calculare Ymean
[a,b]=size(Y);
SumaLinii=sum(Y);
total=sum(SumaLinii);
Ymean=total/(a*b);
[a,b]=size(Cb);
SumaLinii=sum(Cb);
total=sum(SumaLinii);
CbMean=total/(a*b);
% CbMean=round(CbMean,2);
%%%%%%%%%%%%%calculare CrMean
[a,b]=size(Cr);
SumaLinii=sum(Cr);
total=sum(SumaLinii);
CrMean=total/(a*b);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
h=hsv(:,:,1);
h=round(h,2);
s=hsv(:,:,2);
s=round(s,2);
v=hsv(:,:,3);
v=round(v,2);
[lin,col]=size(s);
test=ones(lin,col)*255;
for i=1:lin
for j=1:col
ss=1-3.0*min(red(i,j),min(green(i,j),red(i,j)))/(red(i,j) +green(i,j)+blue(i,j));
if(~(abs(Cb(i,j)-Cr(i,j)<tau)&&red(i,j)>180 && red(i,j)>=green(i,j) && green(i,j)>blue(i,j) && ss>=((255-red(i,j))*0.2/180) &&(v(i,j)>0.8 && v(i,j)<1)&& (Y(i,j)>=Ymean) && (Cb(i,j)<=CbMean) && (Cr(i,j)>=CrMean)))
%if(~(red(i,j)>=green(i,j) && green(i,j)>blue(i,j) && (red(i,j)>115 &&red(i,j)<135) && s(i,j)>(255-(red(i,j)*60)/120)))
test(i,j)=0;
%contor=contor+1;
end
end
end
BW2 = bwareaopen(test,100);
test=imclearborder(test);
stats = struct2table(regionprops(test,{'Area','Solidity','PixelIdxList'}));
idx = stats.Solidity < 0.9 | stats.Area <350;
for kk = find(idx)'
test(stats.PixelIdxList{kk}) = true;
end
subplot(2,2,2);
imshow(test);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%aplic denoise
r=(7-1)/2;
densitate=zeros(lin,col);
densitate=calcDensitate(test,densitate,7);
for i=r:lin-r
for j=r:col-r
count=densitate(i,j);
if(count<5)
test(i,j)=0;
end
end
end
subplot(2,2,3);
imshow(test);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%fill
test=medfilt2(test);
sv=fspecial('sobel');
sx=sv';
Gy=imfilter(test,sv,'replicate');
Gx=imfilter(test,sx,'replicate');
TL=0.39; %prag mic si prag mare
TH=0.98;
% kk=edge(test,'sobel',0.39);
% ll=edge(test,'sobel',0.98);
kk=edge(test,'sobel',0.39);
ll=edge(test,'sobel',0.98);
lll=edge(test,'canny',[TL TH]);
final=imadd(kk,ll);
edgePixels=nnz(final);
area=bwarea(final);
subplot(2,2,4);
imshow(final);

4 comentarios

Shubham Channe
Shubham Channe el 18 de Abr. de 2020
Sir I'm Also trying same project and met with same issue if u got the coorect code can u please help me with correct code.
KALYAN ACHARJYA
KALYAN ACHARJYA el 18 de Abr. de 2020
Because here you are manually adjusting the thresholding values based on specific single image
G Gion
G Gion el 23 de Jul. de 2021
When we run this programme we are getting The error as not enough arguments
Walter Roberson
Walter Roberson el 23 de Jul. de 2021
You have to run the code that is labeled "This is the main function".

Iniciar sesión para comentar.

Respuestas (2)

Alex Che
Alex Che el 21 de Abr. de 2020

1 voto

That's the solution i found 8 months ago.I used the fluctuation of area and perimeter for every fire-like object and I put it into an algorithm to figure out which is fire. I also put a graphic which show the variation of area and number of pixels and for almost every video input works. In the frame 150 you observe a great variation of area for an object which represent the spreading fire.
Image Analyst
Image Analyst el 18 de Abr. de 2020

0 votos

Since there will be lamps and other things that could also be bright in the scene I think you'll have to analyze a video stream and see if the area of the bright things varies over time. See attached demo and adapt it as needed.

1 comentario

Alex Che
Alex Che el 21 de Abr. de 2020
Editada: Alex Che el 21 de Abr. de 2020
This is the solution that seemed the best to me as well if you don't have enough data to try a Convolutional Neural Network

Iniciar sesión para comentar.

Categorías

Más información sobre Images en Centro de ayuda y File Exchange.

Preguntada:

el 11 de Abr. de 2019

Comentada:

el 23 de Jul. de 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by