Morphological opening with a circular structuring element

16 Ansichten (letzte 30 Tage)
med-sweng
med-sweng am 10 Okt. 2012
In matlab, how can I perform a morphological opening with a circular structuring element with radius 10?
Thanks.

Antworten (1)

Image Analyst
Image Analyst am 10 Okt. 2012
Bearbeitet: Image Analyst am 10 Okt. 2012
SE = strel('disk', R, N)
IM2 = imopen(IM,SE)
Here's the full demo:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
format longg;
format compact;
fontSize = 20;
% Read in a standard MATLAB gray scale demo image.
folder = 'C:\Users\Mark\Documents\Temporary';
folder = 'D:\Downloads';
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'cameraman.tif';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage);
% Display the original gray scale image.
subplot(1, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0.5 1 .5]);
% Give a name to the title bar.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
% Construct the structuring element.
structuringElement = strel('disk', 5, 4);
% Do the morphological opening.
openedImage = imopen(grayImage, structuringElement);
% Display the original gray scale image.
subplot(1, 2, 2);
imshow(openedImage, []);
title('Opened Image', 'FontSize', fontSize);

Kategorien

Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by