Inpainting image, it just wont work, i have followed the equation provided

조회 수: 1 (최근 30일)
Michelle Gaughan
Michelle Gaughan 2020년 4월 4일
답변: Image Analyst 2020년 4월 4일
%%I am having writting an inpainting code and having an issue with my code, where i am trying to convert my missing pixels to i and j co-ordinates
close all
% clear; Please remember to uncomment this when you submit your code as an assignment submission.
% Read in the picture
original = double(imread('greece.tif'));
% Read in the forcing function
load forcing;
% Read in the corrupted picture which contains holes
load badpicture;
% Read in an indicator picture which is 1 where the
% pixels are missing in badicture
mask = double(imread('badpixels.tif'));
% Initialise iterations &variables here
restored = badpic;
restored2=badpic;
total_iterations=2000;
err1 = zeros(1, total_iterations);
err2 = zeros(1, total_iterations);
alpha=1;
forcing=load('forcing.mat');
f=forcing.f;
% This displays the original picture in Figure 1
figure(1);
image(original);
title('Original');
colormap(gray(256));
% Display the corrupted picture in Figure 2
figure(2);
image(badpic);
title('Corrupted Image');
colormap(gray(256));
finder = find(mask ~= 0); % This stores all the locations in vectors i and j (row and column indices for each missing pixel)
spaceD=[720,1280];
[i,j]=ind2sub(spaceD, finder);
for iteration = 1 : total_iterations,
for n=1:61440
total = badpic(i(n) - 1, j(n)) + badpic(i(n) + 1, j(n))...
+ badpic(i(n), j(n) + 1) + badpic(i(n), j(n) - 1);
update = badpic(i(n), j(n));
update = update + alpha * (total - 4 * (badpic(i(n), j(n))))/4;
restored(i(n), j(n)) = update;
end
err1(i)= std(badpic(finder) - original(finder));
end;
% Display the restored image in Figure 3 (This does NOT use the forcing function)
figure(3);
image(restored);
title('Restored Image');
colormap(gray(256));
% Repeat the restoration, again starting from the badpicture, but using the forcing function in update
for iteration = 1 : total_iterations,
for n=1:61440
total = badpic(i(n) - 1, j(n)) + badpic(i(n) + 1, j(n))...
+ badpic(i(n), j(n) + 1) + badpic(i(n), j(n) - 1)- f(i(n), j(n));
update = badpic(i(n), j(n));
update = update + alpha * (total - 4 * (badpic(i(n), j(n)))) / 4;
restored2(i(n), j(n)) = update;
end
err2(i)= std(badpic(finder) - original(finder));
end;
% Display your restored image with forcing function as Figure 4
figure(4);
image(restored2);
title('Restored Image with forcing function');
colormap(gray(256));
% Plot two error vectors versus iteration
figure(5);
plot(total_iterations,err1, 'r-', total_iterations, err2, 'b-', 'linewidth', 3);
legend('No forcing function', 'With forcing function');
xlabel('Iteration', 'fontsize', 20);
ylabel('Std Error', 'fontsize', 20);
  댓글 수: 1
John D'Errico
John D'Errico 2020년 4월 4일
I'd just download and use my inpaint_nans from the file exchange. Are you really wedded to writing it yourself?

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2020년 4월 4일
Why not simply use regionfill() the built-in function for doing it?

카테고리

Help CenterFile Exchange에서 Modify Image Colors에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by