remove noise in binary image using morphological operators in matlab

To remove noise in binary images using morphological operators in MATLAB, you can follow these steps:

  1. Read the binary image using the imread function.
main.m
binaryImg = imread('binary_image.png');
40 chars
2 lines
  1. Apply morphological opening using the bwareaopen function. This will remove small objects less than a specified area in pixel units. The strel function is used to define the structuring element for the opening operation.
main.m
se = strel('disk', 3); % Create a disk-shaped structuring element with radius 3
binaryImg = bwareaopen(binaryImg, 50); % Remove small objects less than 50 pixels in area
170 chars
3 lines
  1. Apply morphological closing using the imclose function. This will fill gaps in the binary image and smooth the edges of objects. Again, a structuring element is defined using the strel function.
main.m
se = strel('disk', 5); % Create a disk-shaped structuring element with radius 5
binaryImg = imclose(binaryImg, se); % Close gaps and smooth edges
146 chars
3 lines
  1. If there is still noise present in the binary image, you can apply morphological erosion using the imerode function. This will remove small protrusions from the binary image. Note that this may also cause some objects to become smaller.
main.m
se = strel('square', 3); % Create a square-shaped structuring element with side length 3
binaryImg = imerode(binaryImg, se); % Remove small protrusions
152 chars
3 lines
  1. Display the resulting image using the imshow function.
main.m
imshow(binaryImg);
19 chars
2 lines

Here is the complete code for noise removal in binary images using morphological operators in MATLAB:

main.m
binaryImg = imread('binary_image.png');
se = strel('disk', 3);
binaryImg = bwareaopen(binaryImg, 50);
binaryImg = imclose(binaryImg, se);
se = strel('square', 3);
binaryImg = imerode(binaryImg, se);
imshow(binaryImg);
218 chars
8 lines

gistlibby LogSnag