Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. function g=gaussien(x,y,l)
  2. rho = l*1/2;
  3.  
  4. g=%e^(-((x^2+y^2))/(2*rho^2))/(2*%pi*rho^2);
  5.  
  6.  
  7. endfunction
  8.  
  9. function m=gaussian_mask(l)
  10. y = l; x = l;
  11. mat = resize_matrix([],x,y);
  12. //Creation du masque
  13. for j=1:y
  14. for i=1:x
  15. mat(i,j)=gaussien(i-y/2,j-x/2,l)
  16. end
  17. end
  18. //Calibrage
  19. a = 1 /((max(mat)-min(mat)));
  20. for i=1:y
  21. for j=1:x
  22. mat(i,j)= (a*mat(i,j))-(a*min(mat));
  23. end
  24. end
  25. m=mat
  26. endfunction
  27.  
  28. function f=low_pass_filter(l)
  29. mat = resize_matrix([],x,y);
  30. for j=1:y
  31. for i=1:x
  32. mat(i,j)=%e^i;
  33. end
  34. end
  35. f=mat
  36. endfunction
  37.  
  38. function m=apply_mask(img,mask)
  39. z = size(img);
  40. zm = size(mask);
  41. x=z(1);y=z(2);xm=zm(1);ym=zm(2);
  42. ceilxm = ceil(xm/2);
  43. ceilym = ceil(ym/2);
  44. empty_mat = resize_matrix([],x,y);
  45. for i=1:x
  46. for j=1:y
  47. moy = 0;
  48. compt =0;
  49.  
  50. for k=1:xm
  51. for l=1:ym
  52. xp = i + k - ceilxm;
  53. yp = j + l - ceilym;
  54. if ((yp >=1 & xp >= 1) & (yp <= y & xp <= x))
  55. moy = moy + (img(xp,yp) * (mask(k,l)));
  56. compt =compt + 1*(mask(k,l)) ;
  57. end
  58. end
  59.  
  60. end
  61.  
  62. empty_mat(i,j)=moy/compt;
  63. end
  64. end
  65. m=empty_mat;
  66. endfunction
  67.  
  68. function c=gradient(mat)
  69. z=size(mat);
  70. x=z(1);y=z(2);
  71. output = resize_matrix([],x,y);
  72. for i=1:x
  73. for j=1:y
  74. if ((i >1 & j>1) & (i <x & j<y ))
  75. output(i,j)=sqrt((mat(i-1,j)-mat(i+1,j))^2 + (mat(i,j-1)-mat(i,j+1))^2);
  76. end
  77. end
  78. end
  79. c=output
  80. endfunction
  81.  
  82. function s=seuil(mat,noir,blanc)
  83. z=size(mat);
  84. x=z(1);y=z(2);
  85. for i=1:x
  86. for j=1:y
  87. if mat(i,j)>noir then
  88. mat(i,j)=0;
  89. elseif mat(i,j)<blanc then
  90. mat(i,j)=255;
  91. end
  92. end
  93. end
  94. s=mat
  95. endfunction
  96.  
  97. function get_temp(img)
  98. z=size(img);
  99. x=z(1);y=z(2);
  100. results = resize_matrix([],5,25);
  101. moyenne = 0;
  102. for g=1:6
  103. grad = gradient(apply_mask(img,gaussian_mask(g+1)));
  104. for m=1:25
  105. moy=0;compt=0;
  106. mask = seuil(grad,m,255);
  107. for i=1:x
  108. for j=1:y
  109. if(mask(i,j)==0)
  110. moy=moy+img(i,j);
  111. compt = compt+1;
  112. end
  113. end
  114. end
  115. moy = moy/compt;
  116. results(g,m) = moy*(-201-(-128.150))/199-128.150;
  117. moyenne = moyenne + results(g,m);
  118. end
  119. end
  120.  
  121.  
  122. disp("La température est de : "+string(moyenne/count)+"°C avec un ecart type de : "+string(stdev(results))+"°C");
  123. endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement