how to remove the cracks on image?
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
This code reads in an image with cracks, creates a binary mask of where the cracks are located, and then uses the inpainting function to fill in the masked areas using the 'fast marching' method. The resulting image with the cracks removed is then displayed. Note that the specific parameters used for inpainting may need to be adjusted depending on the characteristics of the image being processed.
% Read image and display it
img = imread('image.png');
imshow(img);
% Create a binary mask where the cracks are located
mask = img == 0;
% Inpaint the masked areas using the 'fast marching' method
inpaint = inpainting(img, mask, 'fast_marching');
% Display the inpainted image
imshow(inpaint);
Editor's note: moved from duplicate thread:
i want to restore the image but it is not showing any progress can you help me out
clc
clear all
img = imread('image.png');
figure(1)
imshow(img);
I=im2bw(img)
% I = rgb2gray(img);
figure(2)
imshow(I)
% Create a binary mask where the cracks are located
mask = I== 254;
% Inpaint the masked areas using the 'fast marching' method
inpaint = inpaintExemplar(I, mask);
figure(3)
% Display the inpainted image
imshow(inpaint);
1 Kommentar
DGM
am 11 Feb. 2023
The text reads as if it were directly copied from an example or assignment. The mask generation is trivial nonsense that appears to simply be a placeholder for further work. Given that your code uses a function which isn't part of MATLAB or any of its toolboxes, and isn't on the File Exchange (that I can tell), nobody can actually run your example. If you're expected to generate the mask by some particular method covered in your studies, nobody else can know that.
This really looks like you just pasted your homework verbatim.
I posted a half-answer on your other version of this question.
Akzeptierte Antwort
DGM
am 12 Feb. 2023
Why would you assume that all of the creases in the paper have a value of exactly 254?
Since I can't demo anything interactive on the forum, I've attached a crude mask which selects some of the creases. I created the mask in GIMP, where I have tablet support and practical view controls. Otherwise, you can tediously create a mask using drawfreehand() or drawpolygon() and createMask().
% read the image
inpict = imread('image.png');
inpict = im2gray(inpict);
% this mask was generated externally
mask = imread('mk.png')>128;
% Inpaint the masked areas using the 'fast marching' method
inpaint = inpaintExemplar(inpict, mask);
% Display the inpainted image
imshow(inpaint)
If you want to magically identify creases in any image (both the bright defects and the dark shadows around them), then you're free to figure out a way.
2 Kommentare
DGM
am 12 Feb. 2023
Bearbeitet: DGM
am 12 Feb. 2023
Like I said, I literally used a brush tool in GIMP and painted the mask regions in an overlaid layer, then exported it. It's faster and easier to get a tight mask on regions like this using a brush than it is to use a polygonal or freehand perimeter selection.
That said, MATLAB doesn't have a practical way to do brushwork. If you wanted to do similar, you can use drawpolygon() or drawfreehand(), then convert the ROI object to a mask.
% read the image
inpict = imread('image.png');
inpict = im2gray(inpict);
% display the image
imshow(inpict)
% create an ROI object
ROI = drawfreehand(gca);
% now you use your mouse to create a single selection region
% when you're done selecting the region, create the mask
mk = createMask(ROI);
% ...
You could combine multiple masks using boolean operations.
unionofmasks = mask1 | mask2 | mask3;
Trying to generate it programmatically in a way that works for all the defects in the image is a different story.
Weitere Antworten (2)
Image Analyst
am 11 Feb. 2023
Honestly I'd just use the bandaid filter in Photoshop. It will do a better job than you. If you still want to do it, then try a modified median filter where you identify cracks (like they're brighter than the surrounding pixels) then replace them with the median filter in a window around the pixel, like I do in my attached salt and pepper denoising demos. You can adjust the threshold or try different segmentation methods if you want.
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!