Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. function [outputPicture] = smoothMe (inputPicture)
  2. G=fspecial('gaussian', [10 10],3); %Create Gaussian mask
  3. outputPicture = conv2(inputPicture,G,'same'); %Convolve the grayscale image with Gaussian filters
  4. end
  5.  
  6. Ex1 :
  7. Lena = imread('lena.png'); %import image png
  8.  
  9. figure;
  10. image(Lena) %Display the initial image
  11.  
  12. GLena=rgb2gray(Lena) %Convert the Lena image to grayscale
  13.  
  14. figure;
  15. colormap(gray)
  16. imagesc(GLena) %display the gray scaled image
  17.  
  18. SmoothLena = smoothMe(GLena) %blurred image of Lena with Gaussian filter
  19.  
  20. figure;
  21. colormap(gray)
  22. imagesc(SmoothLena) %display the result
  23.  
  24. function [H_outputPicture, V_outputPicture] = sobelOperators(inputPicture)
  25. %Convolve the grayscale image with horizontal Sobel filters
  26. H_outputPicture = conv2(inputPicture, [1 2 1; 0 0 0; -1 -2 -1])
  27. %Convolve the grayscale image with vertical Sobel filters
  28. V_outputPicture = conv2(inputPicture, [1 0 -1; 2 0 -2; 1 0 -1])
  29.  
  30. end
  31.  
  32. Ex2 :
  33. Lena = imread('lena.png'); %import image rgb
  34.  
  35. figure;
  36. image(Lena) %Display the initial image
  37.  
  38. GLena = rgb2gray(Lena) %Convert the Lena image to grayscale
  39.  
  40. figure;
  41. colormap(gray)
  42. imagesc(Glena) %Display the gray scaled image
  43.  
  44. (H_SobelLena, V_SobelLena) = sobelOperators(GLena) %Apply sobel filters
  45.  
  46. figure;
  47. colormap(gray)
  48. imagesc(H_SobelLena) %Display the result of the horizontal Sobel filters
  49.  
  50. figure;
  51. colormap(gray)
  52. imagesc(V_SobelLena) %Display the result of the vertical Sobel filters
  53.  
  54. function[ match ] = recogniseFace( Unknown_face, Train_face )
  55.  
  56. %Training
  57. [U,S,D]=svds(Train_Face, 30) %First 30 Eigen vectors
  58. 1TFaces= U'*Train_Face %low dimension Training Face with 20 dimension
  59.  
  60. %Prediction
  61. 1UnknownFace = U'*Unknown_Face
  62. EuclideanDist=sqrt(sum((1TFaces-repmat(1UnknownFace,[1 34])).^2))
  63. [match_score, match]=min(EuclideanDist);
  64.  
  65. end
  66.  
  67. Ex3 :
  68. load A
  69. load UnknownFace
  70.  
  71. RealFace = reshape(UnknownFace, [100 100]);
  72. figure;
  73. colormap(gray)
  74. imagesc(RealFace) %Visualisation of the Unknown face
  75.  
  76. match = recogniseFace(UnknownFace, A) %Reconignition process using PCA on the database A of 34 known register
  77. FoundFace = reshape(A(:, match), [100 100]); %Face that have been detected
  78. figure;
  79. colormap(gray)
  80. imagesc(FoundFace) %Visualisation of the detected face
  81.  
  82. function [ ranks, frequency ] = querystring( query, Tf, uniqueCell )
  83.  
  84. queryCell = strsplit(query)';
  85. number_of_documents=size(Tf,2);
  86.  
  87. for i = 1 : size(queryCell,1)
  88. frequency(i,1:number_of_documents)= Tf(find(strcmp(uniqueCell,queryCell(i))),:);
  89. end
  90.  
  91. frequency=sum(frequency);
  92. [frequency, ranks]=sort(frequency,'descend');
  93.  
  94. end
  95.  
  96. [ranks, frequency]=querystring('superhero comic film', tfidfM, uniqueCell);
  97. ranks(1:10) %top position is document 433
  98.  
  99. function [tfidfM] = tfidf(Tf)
  100. %Input Tf is the term frequency matrix (importance of a document to a term)
  101. %N is the total number of documents in the corpus
  102. N = size(Tf, 2); %number of columns
  103. n = sum (Tf > 0, 2); %n(t) is the number of the documents in the corpus that contains term t
  104. idf = log(N./(1+n)); %Inverse Document Frequency
  105.  
  106. %Term frequency inverse document frequency Matrix
  107. tfidfM = Tf.*repmat(idf,[1 size(Tf, 2)]);
  108.  
  109. end
  110.  
  111. function [ s ] = kalmanfilter( s )
  112. %Kalman filter store state in variable s
  113. %s is a structure with field
  114. %s.x = state variables
  115. %s.F = transformation matrix
  116. %s.P = covariance of variables (how to initialize? with R)
  117. %s.R = covariance of sensor (Radar) / sampling error
  118. %s.z = new observation
  119.  
  120. %preduction
  121. s.x = s.F * s.x
  122. s.P = s.F * s.P * s.F';
  123.  
  124. %update
  125. K = s.P * inv(s.P + s.R)
  126. s.x = s.x + K *(s.z - s.x);
  127. s.P = s.P - K * s.P;
  128. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement