MATLAB Answers

How to delete one of the two scripts of an image

4 views (last 30 days)
This question was flagged by 2 contributors
I have a binary image with two scripts and i need to perform an operation on them.

  0 Comments

Sign in to comment.

Accepted Answer

Ameer Hamza
Ameer Hamza on 5 Apr 2020
Following code will select the smallest region and remove it from the image
load('Image.mat');
image = preenc;
Contour = bwconncomp(image, 8);
area = regionprops(Contour, 'Area');
[~, idx] = min([area.Area]);
mask = Contour.PixelIdxList{idx};
image(mask) = 0;
imshow(image);

  2 Comments

Ameer Hamza
Ameer Hamza on 5 Apr 2020
preenc is the name of the variable in your Image.mat file. Just set it to whatever is the name of your image variable.
Ameer Hamza
Ameer Hamza on 5 Apr 2020
Like this
load('Image.mat');
image = preenc;
Contour = bwconncomp(image, 8);
area = regionprops(Contour, 'Area');
idx = find([area.Area] < 50000);
for i=1:numel(idx)
mask = Contour.PixelIdxList{idx(i)};
image(mask) = 0;
imshow(image);
end

Sign in to comment.

More Answers (0)