Main.m
上传用户:zcsybk2
上传日期:2022-02-09
资源大小:1k
文件大小:2k
源码类别:

2D图形编程

开发平台:

Matlab

  1. im1 = imread('1.jpg');       % input image
  2. choice = input('Choise=  '); % 1=PM exponential method, 2= other PM method, 3=isotropic Diffusion
  3. itr = input('Iteration=  '); % number of iteration
  4. z=input('z=  ');             % isotropic coefficient
  5. im1 = double(im1);
  6. im = im1;
  7. N =  [0 1 0; 0 -1 0; 0 0 0];
  8. S =  [0 0 0; 0 -1 0; 0 1 0];
  9. E =  [0 0 0; 0 -1 1; 0 0 0];
  10. W =  [0 0 0; 1 -1 0; 0 0 0];
  11. NE = [0 0 1; 0 -1 0; 0 0 0];
  12. SE = [0 0 0; 0 -1 0; 0 0 1];
  13. SW = [0 0 0; 0 -1 0; 1 0 0];
  14. NW = [1 0 0; 0 -1 0; 0 0 0];
  15. for t = 1:itr
  16.         delN =  conv2(im,N,'same');
  17.         delS =  conv2(im,S,'same');   
  18.         delW =  conv2(im,W,'same');
  19.         delE =  conv2(im,E,'same');   
  20.         delNE = conv2(im,NE,'same');
  21.         delSE = conv2(im,SE,'same');   
  22.         delSW = conv2(im,SW,'same');
  23.         delNW = conv2(im,NW,'same'); 
  24.         
  25.        
  26.         if choice == 1
  27.             S_N = exp(-(delN/k).^2);
  28.             S_S = exp(-(delS/k).^2);
  29.             S_W = exp(-(delW/k).^2);
  30.             S_E = exp(-(delE/k).^2);
  31.             S_NE = exp(-(delNE/k).^2);
  32.             S_SE = exp(-(delSE/k).^2);
  33.             S_SW = exp(-(delW/k).^2);
  34.             S_NW = exp(-(delNW/k).^2);
  35.         
  36.         
  37.         elseif choice == 2
  38.             S_N =  1./(1 + (delN/k).^2);
  39.             S_S =  1./(1 + (delS/k).^2);
  40.             S_W =  1./(1 + (delW/k).^2);
  41.             S_E =  1./(1 + (delE/k).^2);
  42.             S_NE = 1./(1 + (delNE/k).^2);
  43.             S_SE = 1./(1 + (delSE/k).^2);
  44.             S_SW = 1./(1 + (delSW/k).^2);
  45.             S_NW = 1./(1 + (delNW/k).^2);
  46.                 
  47.         elseif choice == 3
  48.             S_N = z;
  49.             S_S = z;
  50.             S_W = z;
  51.             S_E = z;
  52.             S_NE =z;
  53.             S_SE =z;
  54.             S_SW =z;
  55.             S_NW =z;
  56.         end
  57.         
  58.        
  59.         dx = 1;
  60.         dy = 1;
  61.         dxy = sqrt(2);
  62.         delta = 1/7;
  63.         im = im + delta*((1/(dy^2))*S_N.*delN + (1/(dy^2))*S_S.*delS + ...
  64.                   (1/(dx^2))*S_W.*delW + (1/(dx^2))*S_E.*delE + ...
  65.                   (1/(dxy^2))*S_NE.*delNE + (1/(dxy^2))*S_SE.*delSE + ...
  66.                   (1/(dxy^2))*S_SW.*delSW + (1/(dxy^2))*S_NW.*delNW );
  67.            
  68. end
  69. clc;
  70.           figure, subplot 211, imshow(im1,[]),title('Original Image'), subplot 212, imshow(im,[]); title('Diffused Image')
  71.