black task processing in an image

2 views (last 30 days)
Hello
I have a problem with the image display level, the problem is that I have black spots in the white part and I want to eliminate them
attaching the resulting image and the .mat file
thank you in advanceask.jpg

Accepted Answer

Image Analyst
Image Analyst on 7 Mar 2019
Threshold the image and then call imfill()
binaryImage = grayImage > someValue;
binaryImage = imfill(binaryImage, 'holes');
If you want only holes of a certain diameter filled, then it's a little trickier, so write back.
  5 Comments
dakhli mohamed
dakhli mohamed on 7 Mar 2019
here is the image obtained after the execution of your code
net.jpg
Image Analyst
Image Analyst on 8 Mar 2019
Then try this, if you want all black holes filled to white:
s = load('outputt.mat')
u = logical(s.u);
subplot(2, 1, 1);
imshow(u, 'InitialMagnification', 200);
axis('on', 'image');
% Fill in everything.
[rows, columns] = find(u);
boundaryIndexes = boundary(columns, rows);
hold on;
plot(columns(boundaryIndexes), rows(boundaryIndexes), 'r-', 'LineWidth', 2);
newImage = poly2mask(columns(boundaryIndexes), rows(boundaryIndexes), size(u, 1), size(u, 2));
subplot(2, 1, 2);
imshow(newImage, 'InitialMagnification', 200);
axis('on', 'image');
0000 Screenshot.png

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!