Restoration of damaged lines in image processing

3 次查看(过去 30 天)
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

采纳的回答

DGM
DGM 2022-3-3
编辑:DGM 2022-3-3
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.

更多回答(1 个)

Image Analyst
Image Analyst 2022-3-3
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.

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by