How to remove morphological features from an image mask
1 回表示 (過去 30 日間)
古いコメントを表示
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);
![](/matlabcentral/answers/uploaded_files/63660/before.bmp)
![](/matlabcentral/answers/uploaded_files/63662/after.bmp)
0 件のコメント
回答 (1 件)
Prasad Mendu
2016 年 11 月 23 日
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:
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!