Clear Filters
Clear Filters

How to remove morphological features from an image mask

2 views (last 30 days)

I would like to add the sections resembling circles or ellipses back into the image mask created using the code below. The image mask produced by the code and the desired output are shown below. Does anyone have any recommendations for how to do this?

% Threshold the image using Otsu's method
  level = graythresh(image);
  bwimage = im2bw(image,level);
    %% Process the ROI
    % Create ROI image
    ROIImage = imfill(bwimage,'holes');
    % Find ROI boundary
    ROIboundaries = bwboundaries(ROIImage);
    [~,I] = sort(cellfun(@length,ROIboundaries));
    % Sort by length of the boundary
    ROIboundaries = ROIboundaries(I);
    % Find the largest boundary (ROI)
    ROIboundary = ROIboundaries{end};
    % Mask the image with the ROI
    [m,n] = size(ROIImage);
    ROImask = poly2mask(ROIboundary(:,2),ROIboundary(:,1),m,n);
    % Zero pixels outside the ROI
    ROIImage(ROImask==0) = 0;
    bwimage(ROImask==0) = 0;
    % Convert to logical
    ROIoutputimage = logical(ROIImage);

Answers (1)

Prasad Mendu
Prasad Mendu on 23 Nov 2016
You can use some relevant inbuilt functions available in MATLAB for Morphological Operations to achieve this. Refer to the documentation links given below to get started on this:

Community Treasure Hunt

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

Start Hunting!