Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function g=gaussien(x,y,l)
- rho = l*1/2;
- g=%e^(-((x^2+y^2))/(2*rho^2))/(2*%pi*rho^2);
- endfunction
- function m=gaussian_mask(l)
- y = l; x = l;
- mat = resize_matrix([],x,y);
- //Creation du masque
- for j=1:y
- for i=1:x
- mat(i,j)=gaussien(i-y/2,j-x/2,l)
- end
- end
- //Calibrage
- a = 1 /((max(mat)-min(mat)));
- for i=1:y
- for j=1:x
- mat(i,j)= (a*mat(i,j))-(a*min(mat));
- end
- end
- m=mat
- endfunction
- function f=low_pass_filter(l)
- mat = resize_matrix([],x,y);
- for j=1:y
- for i=1:x
- mat(i,j)=%e^i;
- end
- end
- f=mat
- endfunction
- function m=apply_mask(img,mask)
- z = size(img);
- zm = size(mask);
- x=z(1);y=z(2);xm=zm(1);ym=zm(2);
- ceilxm = ceil(xm/2);
- ceilym = ceil(ym/2);
- empty_mat = resize_matrix([],x,y);
- for i=1:x
- for j=1:y
- moy = 0;
- compt =0;
- for k=1:xm
- for l=1:ym
- xp = i + k - ceilxm;
- yp = j + l - ceilym;
- if ((yp >=1 & xp >= 1) & (yp <= y & xp <= x))
- moy = moy + (img(xp,yp) * (mask(k,l)));
- compt =compt + 1*(mask(k,l)) ;
- end
- end
- end
- empty_mat(i,j)=moy/compt;
- end
- end
- m=empty_mat;
- endfunction
- function c=gradient(mat)
- z=size(mat);
- x=z(1);y=z(2);
- output = resize_matrix([],x,y);
- for i=1:x
- for j=1:y
- if ((i >1 & j>1) & (i <x & j<y ))
- output(i,j)=sqrt((mat(i-1,j)-mat(i+1,j))^2 + (mat(i,j-1)-mat(i,j+1))^2);
- end
- end
- end
- c=output
- endfunction
- function s=seuil(mat,noir,blanc)
- z=size(mat);
- x=z(1);y=z(2);
- for i=1:x
- for j=1:y
- if mat(i,j)>noir then
- mat(i,j)=0;
- elseif mat(i,j)<blanc then
- mat(i,j)=255;
- end
- end
- end
- s=mat
- endfunction
- function get_temp(img)
- z=size(img);
- x=z(1);y=z(2);
- results = resize_matrix([],5,25);
- moyenne = 0;
- for g=1:6
- grad = gradient(apply_mask(img,gaussian_mask(g+1)));
- for m=1:25
- moy=0;compt=0;
- mask = seuil(grad,m,255);
- for i=1:x
- for j=1:y
- if(mask(i,j)==0)
- moy=moy+img(i,j);
- compt = compt+1;
- end
- end
- end
- moy = moy/compt;
- results(g,m) = moy*(-201-(-128.150))/199-128.150;
- moyenne = moyenne + results(g,m);
- end
- end
- disp("La température est de : "+string(moyenne/count)+"°C avec un ecart type de : "+string(stdev(results))+"°C");
- endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement