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

2 ビュー (過去 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 Center および File ExchangeComputer Vision with Simulink についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by