% Step 0: Compile the mex files "mex_make_local_basis.c", "mex mex_map_triangles_to_cells.c", 
%	  "mex mex_fast_map_points_to_triangles.c, "mex_interpolate_element.c"

mex mex_make_local_basis.c
mex mex_map_triangles_to_cells.c
mex mex_fast_map_points_to_triangles.c
mex mex_interpolate_element.c


% Step 1: Using the PDETOOL GUI generate a rectangular domain of size [1
% LENGTH] X [1 WIDTH] corresponding to the image of size LENGTH X WIDTH
% 
% Step 2: Using the PDETOOL GUI initialize (refine) the mesh. Then export
% the mesh to the MATLAB workspace. 
%
%
% Step 3: Call the functions fix_mesh() and rectangular_to_triangular() to
% resample the original image at the FEM triangular grid nodes

[p,t] = fix_mesh(p,t);

I = double(imread('office_noisy.png')); % make sure that the image datatype is double

[LENGTH,WIDTH] = size(I);

[Ip] = rectangular_to_triangular(I,p);


% Step 4: Now using the PDETOOL GUI solve the diffusion equation using
% "Ip" as the initial condition and find the diffused image "Ip_diffused"
%
%
% Step 5: Call the function triangular_to_rectangular() to obtain the
% rectangular diffused image
%

[I_diffused] =  triangular_to_rectangular(Ip_diffused,p,t,LENGTH,WIDTH);

% Step 6: Visualize the images
%

  figure
  subplot(1,2,1)
  imshow(I,[])
  title('Original Image')
  subplot(1,2,2)
  imshow(I_diffused,[])
  title('Diffused Image')
  
