How can I restore image if I need to use command "interp2"

How can I restore image if I need to use command "interp2"

1 Comment

Why do you need to use interp2() specifically?
I see two tasks:
  1. identify the defects
  2. fill the defects
... and I don't see how interp2() will be useful for either of those.

Sign in to comment.

Answers (2)

What does restore mean to you?
Does it mean to some how recover the exact original image, after having interpolated it to some other size? Depending on the interpolation done, that may be impossible, or it may be trivial. It is impossible to know, since we don't know what you might do using interp2.
For example, IF you had decided to double the number of pixels (minus 1) using interp2, then you have merely generated new pixels intermediate to every old pixel in the image. But the old pixels are still there. But, had you used interp2 to subsample the image, reducing the size, then there is now insufficient information remaining to ever recover what was lost.
Does restore mean somehow using interp2 to modify the image for some defect? Again, once you change the image in some way, we cannot know what you decided to do to it, so the question cannot be answered.
I'm just going to put this here.
% the image
inpict = imread('kithat.jpg'); % why JPG for a small grayscale image?
inpict = im2gray(inpict); % convert it back to grayscale
% just binarize the image
% luckily the defects are locally-isolated well enough that this works
% manually select the relevant blobs by their position; discard everything else
% the light-on-dark defects
mask1 = imbinarize(inpict,'adaptive','sensitivity',0);
pickpts = [187 80; 190 97]; % [x y]
mask1 = bwselect(mask1,pickpts(:,1),pickpts(:,2));
% the dark-on-light defects
mask2 = ~imbinarize(inpict,'adaptive','sensitivity',1);
pickpts = [187 147]; % [x y]
mask2 = bwselect(mask2,pickpts(:,1),pickpts(:,2));
% combine the masks
mask = mask1 | mask2;
% dilate the mask because JPG compression means that the defects
% are all surrounded by artifacts that also need to be removed
mask = imdilate(mask,ones(3));
% inpaint the image
outpict = regionfill(inpict,mask);
% the end.
imshow(outpict)
Where was interp2() needed?

2 Comments

It doesn't need intep2, but my professor wants it. I've been searching for weeks and still haven't figured it out.
It's not clear to me how one would use interp2() for either finding the defect or for doing the inpainting. Interp2() works on gridded data, and you'd basically be trying to find a way to exclude the defect pixels from the reference array. I suppose you could do an extreme resampling as an expensive blur and then use the mask to replace the defects with the filtered image, but that seems like a bad way to do it.

Sign in to comment.

Products

Release

R2023a

Edited:

DGM
on 3 Apr 2023

Community Treasure Hunt

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

Start Hunting!