Guest User

Untitled

a guest
Jan 17th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. % To apply affine diffusion equation u_t=div(A*grad u) on images
  2. % where A is a positive definite matrix
  3.  
  4. % Accept Image from the user
  5. disp('Enter Image')
  6. im=uigetfile('*.jpg','Select the Image file');
  7.  
  8. % input image file and store in u1,u2,u3
  9. u1=imread(im);
  10. u1=double(u1);
  11.  
  12. % Accept the matrix from the user
  13. a=input('Enter a: ');
  14. b=input('Enter b: ');
  15. c=input('Enter c: ');
  16. T1=input('Enter Stop Time: ');
  17.  
  18. % Display Original Image
  19. subplot(1,2,1), imshow(uint8(u1))
  20. title('Original image');
  21.  
  22. % store size in m and n
  23. [m,n,~]=size(u1);
  24.  
  25. % step size along t
  26. dt=0.25;
  27.  
  28. for t = 0:dt:T1
  29.  
  30. % finite difference approximation for u_xx
  31. u_xx = u1(:,[2:n n],:) - 2*u1 + u1(:,[1 1:n-1],:);
  32.  
  33. % finite difference approximation for u_xy
  34. u_xy = ( u1([2:m,m],[2:n,n],:) + u1([1,1:m-1],[1,1:n-1],:) - ...
  35. u1([1,1:m-1],[2:n,n],:) - u1([2:m,m],[1,1:n-1],:) ) / 4;
  36.  
  37. % finite difference approximation for u_yy
  38. u_yy = u1([2:m m],:,:) - 2*u1 + u1([1 1:m-1],:,:);
  39.  
  40. % Calculate RHS
  41. div_mat_u=a*u_xx+2*b*u_xy+c*u_yy;
  42.  
  43. u1= u1 + dt*(div_mat_u);
  44. temp=u1;
  45.  
  46. end
  47. subplot(1,2,2), imshow(uint8(temp))
  48. str1=sprintf('T=%d',T1);
  49. title(str1);
  50. clc;
Add Comment
Please, Sign In to add comment