Applying porous medium equation on images

1 visualización (últimos 30 días)
Hirak Doshi
Hirak Doshi el 2 de Feb. de 2018
I wanted to apply the 2D porous medium equation on images. I am using the finite difference scheme for PDEs (FTCS method). The code works for m=1 (Standard Diffusion Equation), but not working for higher values of m. I get a black image as an output. Can someone tell me where I am going wrong ? Here is the code:
% To apply the porous medium equation u_t=laplacian(u^m) on images
%
% We shall use the finite difference approximation scheme for the
% derivatives
% Accept Image and stop time from the user
disp('Enter Image');
im=uigetfile('*.jpg','Select the Image file');
gm=input('Enter gamma value: ');
T1=input('Enter stop time: ');
% input image file and store in u1
u1=double(imread(im));
% Display Original Image
subplot(1,2,1), imshow(uint8(u1))
title('Original image');
% store size in m and n
[m,n,~]=size(u1);
% step size along t
dt=0.1;
for t = 0:dt:T1
% finite difference approximation for u_x
u_x = (u1(:,[2:n n],:) - u1(:,[1 1:n-1],:))/2;
% finite difference approximation for u_y
u_y = (u1([2:m m],:,:) - u1([1 1:m-1],:,:))/2;
% Calculate gm*u^(gm-1)*u_x
lap_x=gm*u1.^(gm-1).*u_x;
% Calculate gm*u^(gm-1)*u_y
lap_y=gm*u1.^(gm-1).*u_y;
% finite difference approximation for lap_x
lap_xx=(lap_x(:,[2:n n],:) - lap_x(:,[1 1:n-1],:))/2;
% finite difference approximation for lap_y
lap_yy = (lap_y([2:m m],:,:) - lap_y([1 1:m-1],:,:))/2;
% Calculate Laplacian of u^m
lap_u=lap_xx+lap_yy;
u1= u1 + dt*(lap_u);
temp=u1;
end
subplot(1,2,2), imshow(uint8(temp))
str1=sprintf('T=%d',T1);
title(str1);

Respuestas (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by