Azzera filtri
Azzera filtri

Restoration of damaged lines in image processing

9 visualizzazioni (ultimi 30 giorni)
Original image
damaged image
I'm trying to restore the partially damaged image from the original image through interpolation to make it similar to the original image, but I don't know how. Help me

Risposta accettata

DGM
DGM il 3 Mar 2022
Modificato: DGM il 3 Mar 2022
For a shape like that, it's pretty easy to get smooth results once you move to polar coordinates.
A = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/912650/image.png');
s = size(A);
cn = round(s(1:2)/2); % [ycenter xcenter]
% find locations of outline pixels
[idxy idxx] = find(A>128); % in rect coord
[idxth idxr] = cart2pol(idxx-cn(2),idxy-cn(1)); % in polar coord
% sort pixel locations by angular position wrt image center
[idxth sortmap] = sort(idxth,'ascend');
idxr = idxr(sortmap);
% one approach would be to fit a spline to both interpolate and denoise
newth = linspace(-pi,pi,1000).';
pp = fit(idxth,idxr,'smoothingspline','smoothingparam',1-1E-5);
newr = pp(newth);
% show the two profiles
plot(idxth,idxr,'.'); hold on
plot(newth,newr,'.')
% construct output image
[newx newy] = pol2cart(newth,newr);
B = false(s);
B(sub2ind(s,round(newy+cn(1)),round(newx+cn(2)))) = true;
figure
imshow(B)
Of course, that would require CFT. If you don't have that toolbox, you can get perfectly reasonable results with regular 1D interpolation:
figure
% otherwise, you could use any 1-D interpolation or fitting method
newth = linspace(-pi,pi,1000).';
newr = interp1(idxth,idxr,newth,'makima');
nanmk = ~isnan(newr);
newr = newr(nanmk);
newth = newth(nanmk);
% show the two profiles
plot(idxth,idxr,'.'); hold on
plot(newth,newr,'.')
% construct output image
[newx newy] = pol2cart(newth,newr);
B = false(s);
B(sub2ind(s,round(newy+cn(1)),round(newx+cn(2)))) = true;
figure
imshow(B)
Note that I assumed that the center of the image corresponds to the center of the object. If that's not the case, you'd obviously want to find the center of the object's bounding box.

Più risposte (1)

Image Analyst
Image Analyst il 3 Mar 2022
For what it's worth, I'm attaching my edge linking demos. Basically it connects endpoints of a line or curve segment to the closest endpoint of a different line or curve segment.

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by