# Varios

Páginas: 3 (641 palabras) Publicado: 30 de septiembre de 2010
Code A: Matlab Code for Poisson Image Reconstruction from Image Gradients
% Read Input Gray Image imgstr = ’test.png’; disp(sprintf(’Reading Image %s’,imgstr)); img = imread(imgstr); [H,W,C] =size(img); img = double(img); % Find gradinets gx = zeros(H,W); gy = zeros(H,W); j = 1:H-1; k = 1:W-1; gx(j,k) = (img(j,k+1) - img(j,k)); gy(j,k) = (img(j+1,k) - img(j,k)); % Reconstruct image fromgradients for verification img_rec = poisson_solver_function(gx,gy,img); figure;imagesc(img);colormap gray;colorbar;title(’Image’) figure;imagesc(img_rec);colormap gray;colorbar;title(’Reconstructed’);figure;imagesc(abs(img_rec-img));colormap gray;colorbar;title(’Abs error’);

function [img_direct] = poisson_solver_function(gx,gy,boundary_image); % function [img_direct] =poisson_solver_function(gx,gy,boundary_image) % Inputs; Gx and Gy -> Gradients % Boundary Image -> Boundary image intensities % Gx Gy and boundary image should be of same size [H,W] = size(boundary_image); gxx = zeros(H,W); gyy =zeros(H,W); f = zeros(H,W); j = 1:H-1; k = 1:W-1; % Laplacian gyy(j+1,k) = gy(j+1,k) - gy(j,k); f = gxx + gyy;

gxx(j,k+1) = gx(j,k+1) - gx(j,k); clear j k gxx gyy gyyd gxxd

% boundary imagecontains image intensities at boundaries boundary_image(2:end-1,2:end-1) = 0; disp(’Solving Poisson Equation Using DST’); tic j = 2:H-1; k = 2:W-1; f_bp = zeros(H,W); f_bp(j,k) = -4*boundary_image(j,k) +boundary_image(j,k+1) + boundary_image(j,k-1) + boundary_image(j-1,k) + boundary_image(j+1,k); clear j k f1 = f - reshape(f_bp,H,W);% subtract boundary points contribution clear f_bp f % DST SineTransform algo starts here f2 = f1(2:end-1,2:end-1); %compute sine transform tt = dst(f2); f2sin = dst(tt’)’; %compute Eigen Values [x,y] = meshgrid(1:W-2,1:H-2); %divide f3 = f2sin./denom; %computeInverse Sine Transform tt = idst(f3); clear f3; time_used = toc;

clear f1 clear f2

denom = (2*cos(pi*x/(W-1))-2) + (2*cos(pi*y/(H-1)) - 2) ;

clear f2sin x y

img_tt = idst(tt’)’;

clear tt...

Regístrate para leer el documento completo.