www.mathworks.com Open in urlscan Pro
104.89.34.216  Public Scan

URL: https://www.mathworks.com/help/images/ref/strel.html
Submission: On July 18 via manual from US — Scanned from DE

Form analysis 2 forms found in the DOM

GET /support/search.html

<form id="docsearch_form" action="/support/search.html" method="get" accept-charset="utf-8" data-release="R2022a" data-language="en">
  <div class="input-group">
    <label class="sr-only">Search Help Center</label>
    <input id="suggestion" type="hidden" name="suggestion" value="">
    <span role="status" aria-live="polite" class="ui-helper-hidden-accessible"></span>
    <input id="docsearch" class="form-control conjoined_search" type="search" name="q" placeholder="Search Help Center" autocomplete="off">
    <div class="input-group-btn">
      <button type="button" class="btn btn_search_adjacent dropdown-toggle" data-toggle="dropdown"><span class="caret"></span><span class="search_scope_label">Help Center</span></button>
      <ul class="dropdown-menu list-unstyled dropdown-menu-right" role="menu">
        <!--<li data-toggle="collapse" data-target="#search_scope_support"><a href="#">Support</a></li>-->
        <li data-toggle="collapse" data-target="#search_scope_site" class="support_search_scope_trigger"><a href="#">MathWorks</a></li>
      </ul>
      <script>
        $(".support_search_scope_trigger").click(function() {
          $("#search_scope_support").removeClass("in");
          $("#query").val($("#search").val());
        });
      </script>
      <button type="submit" name="submitsearch" id="support_submitsearch" class="btn icon-search btn_search_adjacent btn_search icon_16"></button>
    </div>
  </div>
</form>

Name: searchGET /search/site_search.html

<form name="search" id="site_search" class="site_search" action="/search/site_search.html" method="get">
  <div class="input-group">
    <label class="sr-only">Search MathWorks.com</label>
    <input type="hidden" name="c[]" value="entire_site">
    <input type="search" name="q" id="query" class="form-control conjoined_search" placeholder="Search MathWorks.com" autocomplete="off" \="">
    <div class="input-group-btn">
      <button type="button" class="btn btn_search_adjacent dropdown-toggle" data-toggle="dropdown"><span class="caret"></span><span class="search_scope_label">MathWorks</span></button>
      <ul class="dropdown-menu list-unstyled dropdown-menu-right" role="menu">
        <li data-toggle="collapse" data-target="#search_scope_support" class="site_search_scope_trigger"><a href="#">Support</a></li>
      </ul>
      <script>
        $(".site_search_scope_trigger").click(function() {
          $("#search_scope_site").removeClass("in");
          $("#search").val($("#query").val());
        });
      </script>
      <button type="submit" id="searchbutton" class="btn icon-search btn_search_adjacent btn_search icon_16"></button>
    </div>
  </div>
</form>

Text Content

WE VALUE YOUR PRIVACY

We and our partners store and/or access information on a device, such as cookies
and process personal data, such as unique identifiers and standard information
sent by a device for personalised ads and content, ad and content measurement,
and audience insights, as well as to develop and improve products.

With your permission we and our partners may use precise geolocation data and
identification through device scanning. You may click to consent to our and our
partners’ processing as described above. Alternatively you may access more
detailed information and change your preferences before consenting or to refuse
consenting. Please note that some processing of your personal data may not
require your consent, but you have a right to object to such processing. Your
preferences will apply to a group of websites. You can change your preferences
at any time by returning to this site or visit our privacy policy.

MORE OPTIONSAGREE
Skip to content
Toggle Main Navigation


 * Sign In to Your MathWorks AccountSign In to Your MathWorks Account
 * Products
 * Solutions
 * Academia
 * Support
 * Community
 * Events
 * Get MATLAB


MATHWORKS MATRIX MENU

 * MATLAB
 * Help Center
 * MathWorks

 * MATLAB Answers
 * File Exchange
 * Videos
 * Online Training
 * Blogs
 * Cody
 * MATLAB Drive
 * ThingSpeak
 * Bug Reports
 * Community

 * Products
 * Solutions
 * Academia
 * Support
 * Community
 * Events

 * Get MATLAB
 * Sign In to Your MathWorks AccountSign In to Your MathWorks Account


 * MATHWORKS MATRIX MENU
   
    * MATLAB
    * Help Center
    * MathWorks
   
    * MATLAB Answers
    * File Exchange
    * Videos
    * Online Training
    * Blogs
    * Cody
    * MATLAB Drive
    * ThingSpeak
    * Bug Reports
    * Community

Help CenterHelp Center

Search Help Center
Help Center
   
 * MathWorks

Search MathWorks.com
MathWorks
 * Support

Close Mobile Search
Open Mobile Search
Off-Canvas Navigation Menu Toggle
 * Documentation Home

 * Image Processing Toolbox
 * Image Filtering and Enhancement
 * Morphological Operations

 * Image Processing Toolbox
 * 3-D Volumetric Image Processing

 * strel
 * On this page
   
 * Description
 * Creation
 * Description
   * Arbitrary Neighborhood Shape
   * 2-D Geometric Neighborhood Shapes
   * 3-D Geometric Neighborhood Shapes
    * Input Arguments
      * nhood
      * r
      * n
      * len
      * deg
      * [m n]
      * w
      * [m n p]

 * Properties
   * Neighborhood
   * Dimensionality
 * Object Functions
 * Examples
   * Create Square Structuring Element
   * Create Line-Shaped Structuring Element
   * Create Disk-Shaped Structuring Element
   * Create 3-D Sphere-shaped Structuring Element
 * Tips
 * Algorithms
 * References
 * Extended Capabilities
 * Version History
   * Linear Structuring Elements Use Angle in Range [0, 180]
 * See Also

 * Documentation
 * Examples
 * Functions
 * Apps
 * Videos
 * Answers

 * Trial Software
 * Trial Software
 * Product Updates
 * Product Updates

Resources
 * Documentation
 * Examples
 * Functions
 * Apps
 * Videos
 * Answers


Main Content


STREL

Morphological structuring element

expand all in page


DESCRIPTION

A strel object represents a flat morphological structuring element, which is an
essential part of morphological dilation and erosion operations.

A flat structuring element is a binary valued neighborhood, either 2-D or
multidimensional, in which the true pixels are included in the morphological
computation, and the false pixels are not. The center pixel of the structuring
element, called the origin, identifies the pixel in the image being processed.
Use the strel function (described below) to create a flat structuring element.
You can use flat structuring elements with both binary and grayscale images. The
following figure illustrates a flat structuring element.



To create a nonflat structuring element, use offsetstrel.


CREATION


SYNTAX

SE = strel(nhood)
SE = strel("diamond",r)
SE = strel("disk",r)
SE = strel("disk",r,n)
SE = strel("octagon",r)
SE = strel("line",len,deg)
SE = strel("rectangle",[m n])
SE = strel("square",w)
SE = strel("cube",w)
SE = strel("cuboid",[m n p])
SE = strel("sphere",r)



DESCRIPTION

ARBITRARY NEIGHBORHOOD SHAPE

SE = strel(nhood) creates a flat structuring element with specified neighborhood
nhood.

2-D GEOMETRIC NEIGHBORHOOD SHAPES

SE = strel("diamond",r) creates a diamond-shaped structuring element, where r
specifies the distance from the structuring element origin to the points of the
diamond.

example

SE = strel("disk",r) creates a disk-shaped structuring element, where r
specifies the radius.

SE = strel("disk",r,n) creates a disk-shaped structuring element, where r
specifies the radius and n specifies the number of line structuring elements
used to approximate the disk shape. Morphological operations run much faster
when the structuring element uses approximations.

SE = strel("octagon",r) creates a octagonal structuring element, where r
specifies the distance from the structuring element origin to the sides of the
octagon, as measured along the horizontal and vertical axes. r must be a
nonnegative multiple of 3.

example

SE = strel("line",len,deg) creates a linear structuring element that is
symmetric with respect to the neighborhood center, with approximate length len
and angle deg.

SE = strel("rectangle",[m n]) creates a rectangular structuring element of size
[m n].

example

SE = strel("square",w) creates a square structuring element whose width is w
pixels.

3-D GEOMETRIC NEIGHBORHOOD SHAPES

SE = strel("cube",w) creates a 3-D cubic structuring element whose width is w
pixels.

SE = strel("cuboid",[m n p]) creates a 3-D cuboidal structuring element of size
m-by-n-by-p pixels.

example

SE = strel("sphere",r) creates a 3-D spherical structuring element whose radius
is r pixels.

Compatibility

The following syntaxes still work, but offsetstrel is the preferred way to
create these nonflat structuring element shapes:

 * SE = strel("arbitrary",nhood,h), where h is a matrix of the same size as
   nhood containing the height values associated with each nonzero element of
   nhood.

 * SE = strel("ball",r,h,n)


INPUT ARGUMENTS

expand all


NHOOD — NEIGHBORHOOD
NUMERIC ARRAY

Neighborhood, specified as numeric array of any dimension. All nonzero pixels of
nhood belong to the neighborhood for the morphological operation. The center (or
origin) of nhood is its center element, given by floor((size(nhood) + 1)/2).

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 |
uint32 | uint64 | logical


R — RADIUS OF STRUCTURING ELEMENT
POSITIVE INTEGER

Radius of the structuring element, specified as a positive integer.

 * For the disk shape, r is the distance from the origin to the edge of the
   disk.

 * For the diamond shape, r is the distance from the structuring element origin
   to the points of the diamond.

 * For the octagon shape, r is the distance from the structuring element origin
   to the sides of the octagon, as measured along the horizontal and vertical
   axes. r must be a multiple of 3.

 * For the sphere shape, r is the distance from the origin to the edge of the
   sphere.

Data Types: double


N — NUMBER OF PERIODIC LINE STRUCTURING ELEMENTS USED TO APPROXIMATE SHAPE
4 (DEFAULT) | 0 | 6 | 8

Number of periodic line structuring elements used to approximate shape,
specified as 0, 4, 6, or 8. Morphological operations using disk approximations
run much faster when the structuring element uses approximations (n > 0).

Value of nBehaviorn > 0strel uses a sequence of n periodic line-shaped
structuring elements to approximate the shape. Sometimes strel must use two
extra line structuring elements in the approximation, in which case the actual
number of decomposed structuring elements is n+2.n = 0strel does not use any
approximation. The structuring element members comprise all pixels whose centers
are no greater than r away from the origin.

Data Types: double


LEN — LENGTH OF LINEAR STRUCTURING ELEMENT
POSITIVE NUMBER

Length of linear structuring element, specified as a positive number. len is
approximately the distance between the centers of the structuring element
members at opposite ends of the line.

Data Types: double


DEG — ANGLE OF LINEAR STRUCTURING ELEMENT
NUMERIC SCALAR

Angle of linear structuring element, in degrees, specified as numeric scalar.
The angle is measured in a counterclockwise direction from the horizontal axis.

Data Types: double


[M N] — SIZE OF RECTANGULAR STRUCTURING ELEMENT
2-ELEMENT VECTOR OF POSITIVE INTEGERS

Size of rectangular structuring element, specified as a 2-element vector of
positive integers. The structuring element has m rows and n columns.

Data Types: double


W — WIDTH OF SQUARE OR CUBIC STRUCTURING ELEMENT
POSITIVE INTEGER

Width of square or cubic structuring element, specified as a positive integer.

Data Types: double


[M N P] — SIZE OF CUBOIDAL STRUCTURING ELEMENT
3-ELEMENT VECTOR OF POSITIVE INTEGERS

Size of cuboidal structuring element, specified as a 3-element vector of
positive integers. The structuring element has m rows, n columns, and p planes.

Data Types: double


PROPERTIES

expand all


NEIGHBORHOOD — STRUCTURING ELEMENT NEIGHBORHOOD
LOGICAL ARRAY

Structuring element neighborhood, specified as a logical array.

Data Types: logical


DIMENSIONALITY — DIMENSIONS OF STRUCTURING ELEMENT
NONNEGATIVE SCALAR

Dimensions of structuring element, specified as a nonnegative scalar.

Data Types: double


OBJECT FUNCTIONS

imdilateDilate imageimerodeErode imageimcloseMorphologically close
imageimopenMorphologically open imageimbothatBottom-hat filteringimtophatTop-hat
filteringbwhitmissBinary hit-miss operation

decomposeReturn sequence of decomposed structuring elementsreflectReflect
structuring elementtranslateTranslate structuring element


EXAMPLES

collapse all


CREATE SQUARE STRUCTURING ELEMENT


Try This ExampleCopy Command  Copy Code

Create an 11-by-11 square structuring element.

SE = strel('square', 11)

SE = 
strel is a square shaped structuring element with properties:

      Neighborhood: [11x11 logical]
    Dimensionality: 2







CREATE LINE-SHAPED STRUCTURING ELEMENT


Try This ExampleCopy Command  Copy Code

Create a line-shaped structuring element with a length of 10 at an angle of 45
degrees.

SE = strel('line', 10, 45)

SE = 
strel is a line shaped structuring element with properties:

      Neighborhood: [7x7 logical]
    Dimensionality: 2



View the structuring element.

SE.Neighborhood

ans = 7x7 logical array

   0   0   0   0   0   0   1
   0   0   0   0   0   1   0
   0   0   0   0   1   0   0
   0   0   0   1   0   0   0
   0   0   1   0   0   0   0
   0   1   0   0   0   0   0
   1   0   0   0   0   0   0







CREATE DISK-SHAPED STRUCTURING ELEMENT


Try This ExampleCopy Command  Copy Code

Create a disk-shaped structuring element with a radius of 15.

SE3 = strel('disk', 15)

SE3 = 
strel is a disk shaped structuring element with properties:

      Neighborhood: [29x29 logical]
    Dimensionality: 2



Display the disk-shaped structuring element.

figure
imshow(SE3.Neighborhood)







CREATE 3-D SPHERE-SHAPED STRUCTURING ELEMENT


Try This ExampleCopy Command  Copy Code

Create a 3-D sphere-shaped structuring element with a radius of 15.

SE = strel('sphere', 15)

SE = 
strel is a sphere shaped structuring element with properties:

      Neighborhood: [31x31x31 logical]
    Dimensionality: 3



Display the structuring element.

figure
isosurface(SE.Neighborhood)







TIPS

 * Structuring elements that do not use approximations (n = 0) are not suitable
   for computing granulometries.


ALGORITHMS

For all of the geometrical shapes, structuring elements are constructed using a
family of techniques known collectively as structuring element decomposition.
The principle is that dilation by some large structuring elements can be
computed faster by dilation with a sequence of smaller structuring elements. For
example, dilation by an 11-by-11 square structuring element can be accomplished
by dilating first with a 1-by-11 structuring element and then with an 11-by-1
structuring element. This results in a theoretical performance improvement of a
factor of 5.5, although in practice the actual performance improvement is
somewhat less. Structuring element decompositions used for the "disk" shape is
an approximations—all other decompositions are exact.


REFERENCES

[1] van den Boomgard, R, and R. van Balen, "Methods for Fast Morphological Image
Transforms Using Bitmapped Images," Computer Vision, Graphics, and Image
Processing: Graphical Models and Image Processing, Vol. 54, Number 3, pp.
252–254, May 1992.

[2] Adams, R., "Radial Decomposition of Discs and Spheres," Computer Vision,
Graphics, and Image Processing: Graphical Models and Image Processing, Vol. 55,
Number 5, pp. 325–332, September 1993.

[3] Jones, R., and P. Soille, "Periodic lines: Definition, cascades, and
application to granulometrie," Pattern Recognition Letters, Vol. 17, pp.
1057–1063, 1996.


EXTENDED CAPABILITIES


C/C++ CODE GENERATION
GENERATE C AND C++ CODE USING MATLAB® CODER™.

Usage notes and limitations:



 * strel supports the generation of C code (requires MATLAB® Coder™). For more
   information, see Code Generation for Image Processing.

 * All input arguments of type char must be compile-time constants.

 * The methods associated with strel objects are not supported in code
   generation.

 * Arrays of strel objects are not supported.




VERSION HISTORY

Introduced before R2006a

expand all


R2017B: LINEAR STRUCTURING ELEMENTS USE ANGLE IN RANGE [0, 180]

Behavior changed in R2017b

Starting in R2017b, strel constrains linear structuring elements to have an
angle in the range [0, 180]. If you specify a value of deg outside this range,
then strel calculates the angle as mod(deg,180).

Prior to R2017b, in some situations, strel would create different linear
structuring elements for angles that differ by a factor of 180 degrees.


SEE ALSO

offsetstrel


TOPICS

 * Structuring Elements

×


OPEN EXAMPLE

You have a modified version of this example. Do you want to open this example
with your edits?

No, overwrite the modified version Yes

Thank you for your feedback!
Why did you choose this rating? Submit
How useful was this information?
Unrated 1 star 2 stars 3 stars 4 stars 5 stars
×


MATLAB COMMAND

You clicked a link that corresponds to this MATLAB command:



Run the command by entering it in the MATLAB Command Window. Web browsers do not
support MATLAB commands.

Close

×


SELECT A WEB SITE

Choose a web site to get translated content where available and see local events
and offers. Based on your location, we recommend that you select: United States.

United States
 * Switzerland (English)
 * Switzerland (Deutsch)
 * Switzerland (Français)

 * 中国 (简体中文)
 * 中国 (English)

You can also select a web site from the following list:


HOW TO GET BEST SITE PERFORMANCE

Select the China site (in Chinese or English) for best site performance. Other
MathWorks country sites are not optimized for visits from your location.


AMERICAS

 * América Latina (Español)
 * Canada (English)
 * United States (English)


EUROPE

 * Belgium (English)
 * Denmark (English)
 * Deutschland (Deutsch)
 * España (Español)
 * Finland (English)
 * France (Français)
 * Ireland (English)
 * Italia (Italiano)
 * Luxembourg (English)

 * Netherlands (English)
 * Norway (English)
 * Österreich (Deutsch)
 * Portugal (English)
 * Sweden (English)
 * Switzerland
   * Deutsch
   * English
   * Français
 * United Kingdom (English)


ASIA PACIFIC

 * Australia (English)
 * India (English)
 * New Zealand (English)
 * 中国
   * 简体中文
   * English
 * 日本 (日本語)
 * 한국 (한국어)

Contact your local office

 * Trial Software
 * Trial Software
 * Product Updates
 * Product Updates

MathWorks

Accelerating the pace of engineering and science

MathWorks is the leading developer of mathematical computing software for
engineers and scientists.

Discover...

Explore Products

 * MATLAB
 * Simulink
 * Student Software
 * Hardware Support
 * File Exchange

Try or Buy

 * Downloads
 * Trial Software
 * Contact Sales
 * Pricing and Licensing
 * How to Buy

Learn to Use

 * Documentation
 * Tutorials
 * Examples
 * Videos and Webinars
 * Training



Get Support

 * Installation Help
 * Answers
 * Consulting
 * License Center
 * Contact Support

About MathWorks

 * Careers
 * Newsroom
 * Social Mission
 * Customer Stories
 * About MathWorks

 * United States


 * Trust Center
 * Trademarks
 * Privacy Policy
 * Preventing Piracy
 * Application Status




© 1994-2022 The MathWorks, Inc.


 * 
 * 
 * 
 * 
 * 
 * 



Join the conversation