Bwlabel function and Regionprops function usage detailed __matlab notes

Source: Internet
Author: User
Tags scalar
1, Bwlabel is used to mark the two-dimensional two-value image of the connected group, in short, is the black background of how many white block, that is, from the black background screening white block. L = Bwlabel (bw,n) returns a matrix L, the same size as BW, containing labels for the connected components in BW. N is 4-connected or 8-connected [L,num] = Bwlabel (bw,n) returns in NUM the number of connected objects found in BW. That is, Bwlabel can be derived from a two-value image produced by the BW Array (may also be created by themselves, as long as the match element is 0 or 1 on the line), distinguish between the number of 1 of them (note: In the BW array, 0 for the black background, 1 for white) like0 1 1 0 0 0 1
0 1 1 0 0 0 1
0 1 1 0 0 0 1 in such an array, it is obvious that 0 blocks two on the 1 background, so the L array returned after Bwlabe is: 0 1 1 0 0 0-2
0 1 1 0 0 0 2
0 1 1 0 0 0 2 (of course, this I do not actually run, but should be no problem.) What does that mean? Which means the return of the L inside through the 1,2,3, ... N to identify a certain position (pixel) belonging to the first few connected components of this binary image. To have a deeper and clearer understanding, there is a need to understand the definition of unicom here, in fact, there are 4-connected (up and down) and 8-connected (all of which are connected) (and even less commonly used custom connectivity, in the future help to see conn Such input parameters are useful). If you set two return parameters, Num can return the number of blocks. In addition, there is a similar function called Bwlabeln, the difference is as follows: The difference of speed, the function of the implementation of some special circumstances to do a special optimization. Bwlabel in the vertical direction of the block is relatively long time faster, in other cases, are bwlabeln faster. Another Bwlabel acceptable l can also be multidimensional, and Bwlabel can only accept two-dimensional L. Specific extension application will have a lot of, with this mark as the beginning, we can write some of their own functions, of course, MATLAB image processing toolbox Inside some of the functions can and this very good coordination to achieve some good application. For example, through the Regionprops function to determine the characteristics of each block (such as center, area, etc.) STATS = Regionprops (l,properties) measures a set of properties for each labeled RE Gion in the label Matrix L.

2, Regionprops:

The purpose is get the properties of region, the function used to measure the properties of the image region.

Syntax: STATS = Regionprops (l,properties)

Description: measures a series of attributes for each callout area in the callout matrix L. The different positive integer elements in L correspond to different regions, for example: the element corresponding to integer 1 in L is corresponding to region 2, and so on, which is equal to Integer 2 in 1;l. The return value stats is an array of structures with a length of Max (L (:)), and the corresponding fields of the structure array define the measurements under the corresponding properties for each region. Properties can be a comma-separated list of strings, a cell array full of strings, a single string of ' All ' or ' basic '. If properties are equal to the string ' All ', the metric data in the list of all the following strings will be computed, if properties are not specified or equal to ' basic ', the property: ' Area ', ' centroid ', and ' BoundingBox ' will be Calculation. The following list is all valid property strings, which are case-sensitive and can be abbreviated.

Property string list

Area

Equivdia Meter

majoraxislength

BoundingBox

Eu Lernumber

minoraxislength

centroid

E Xtent

Orientation

Convexarea

Extrema

pixelidxlist

Convexhull

Filledarea

pixellist

Conveximage

Filledimage

Solidity

Eccentricity

Image

 

attribute Detail definition: This section will combine a concrete example to illustrate the meaning of various string correlation attributes, the matrix is taken from the pattern recognition in ant-like image after preprocessing of the striped segmentation images, as shown below:

This is a two-value image, before the application of the Regionprops function must be labeled, you can call the Bwlabel function and pseudo color processing, annotated image as follows:

The following is based on the above materials to examine the meaning of attributes.

' area ': a scalar that calculates the total number of pixels in each region of the image. Note: This value may be slightly different from the value computed by the function Bwarea. For such a number, we can use it divided by the number of pixels in the entire image region to get the stripe ratio, can be used as a candidate for pattern recognition, and this feature is affine invariant.

' BoundingBox ': is a vector of 1 rows of Ndims (L) *2 columns, the smallest rectangle that contains the corresponding region. The BoundingBox form is [ul_corner width], where ul_corner in the coordinates of [x y z ...] gives the upper-left corner of the bounding box, boxwidth to [x_width y_width ...] form the border box along each The length of the dimension direction. In this example, the smallest rectangle for each part of the region is the following figure. Note: Please familiarize yourself with the use of function rectangle here.

' centroid ': a vector of 1 rows of Ndims (L), giving the center of mass (center of gravity) of each region. Note: The first element of the centroid is the horizontal center of gravity (X-coordinate) and the second element is the vertical coordinate of the center of gravity (y-coordinate). Centroid all other elements are arranged in a dimension order. The following figure uses a center-centered small circle to demonstrate the effect of centroid detection:

' majoraxislength ': is a scalar, the length of the ellipse with the same standard second-order central moment as the region (in pixel sense). This property supports only two-dimensional callout matrices.

' minoraxislength ': the short axis length (pixel meaning) of an ellipse with the same standard second-order central moment as the region. This property supports only two-dimensional callout matrices.

' eccentricity ': is a scalar, with the region has the same standard second-order central moment of the eccentricity of the ellipse (can be used as a feature). This property supports only two-dimensional callout matrices.

' Orientation ': is a scalar, the angle (degree) between the long axis and the x axis of the ellipse with the same standard second-order central moment as the region. This property supports only two-dimensional callout matrices.

We can look at the trend of the eccentricity and get a general sense of how the roundness of the region in the whole region is, for example, the following figure is the centrifugal rate change in 12 regions:

From the above, we can see that the roundness of the region as a whole is not good, in fact, we can consider using the heart rate vector as a pattern recognition feature.

' image ': a two-valued image with a logical matrix of the same size as an area. You can use this attribute to extract each sub area directly and then handle it accordingly.

' filledimage ': The only difference is that this is a logical matrix that has been filled.
In this case, there is no difference between the above and only when the region is empty there is a significant difference.

' Filledarea ': is a scalar that fills the number of on pixels in an area image.

' convexhull ': is a matrix of P row 2, containing the smallest convex polygon of a region. Each row of this matrix stores the XY coordinates of one vertex of this polygon. This property supports only 2-D callout matrices. For example, the smallest convex polygon of all the subregions in this example is the following figure

Look at the big picture in area 2nd:

' conveximage ': a two-value image that is used to draw the smallest convex polygon in the above area. At the same time, the pixels inside the convex package are open, and the image dimensions are the same as the corresponding boundary rectangles in this area. This property supports only 2-D callout matrices. Note: function Roipoly is useful here.

' Convexarea ': is a scalar that fills the number of on pixels in the region's convex polygon image.

' Eulernumber ': is a scalar, a topological invariant in a geometric topology-the Euclidean number, equal to the number of objects in the image minus the number of holes in the target. This property supports only 2-D callout matrices. The Euler numbers in this example are all 1.

' extrema ':8 row 2 column matrix, eight direction region extreme point. Each row of the matrix stores the XY coordinates of these points, in the form of [Top-left top-right right-top right-bottom bottom-right bottom-left Left-bottom]. This property supports only 2-D callout matrices.

' Equivdiameter ': is a scalar, equivalent diameter: the diameter of a circle with the same area as an area. The calculation formula is: sqrt (4*AREA/PI). This property supports only 2-D callout matrices.

' solidity ': is a scalar, at the same time in the region and its smallest convex polygon in the proportion of pixels. The formula is: Area/convexarea, which is also an affine feature that actually reflects the degree of fixation of the region. This property supports only 2-D callout matrices.

' Extent ': is a scalar, while in the region and its smallest boundary rectangle in the pixel proportions. The formula is: area divided by the boundary rectangle, which is also an affine feature that actually reflects the extent of the region's extended range. This property supports only 2-D callout matrices. No more calculation results are given.

' pixelidxlist ':p-Element vector, index subscript for storing area pixels.

' pixellist ':the P row ndims (L) column matrix, which stores the pixel coordinates corresponding to the above index.

Support class: the input annotation matrix L can have any numeric type.

Reminders

use comma to split list syntax: when you design an algorithm based on the output of the Regionprops function, the comma-separated list syntax highlights its value. For example, for a property that stores a scalar, you can use this syntax to create a vector that contains the value of this property in different areas of the image. For example, the following two sentences are equivalent:

Stats (1). Area, stats (2). Area, ..., stats (end). Area
Stats. Area

Therefore, you can use the following method to create the appropriate vector:

Regionprops (L, ' area '); Allarea = [Stats. Area];

Allarea is a vector that has the same length as the stats of an array of structures.

region selection based on specific principles: It is useful to combine functions IsMember and regionprops when you want to select an area based on specific criteria criteria. For example, create a two-valued image that contains only an area greater than 80 to command

IDX = Find ([stats. Area] > 80); BW2 = IsMember (L,IDX);

Computational Performance considerations: Most of the property measurements are calculated with very little time, except for those that depend heavily on the number of regions and pixels in the image L. For example:

' Convexhull ' conveximage ' convexarea ' filledimage '

It is also recommended that all property values be computed at a time, because it is similar to separate calculations and calculations.

work with a two-value image: The two-value image must be converted to a callout matrix before calling Regionprops. Two functions can be done:

L = Bwlabel (BW); L = double (BW);

Note: Although these two functions produce different annotation matrices from the same binary image, they are equivalent. For example: give the following two-value matrix BW,

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

Bwlabel creates a contiguous region callout matrix that contains two callouts, respectively, of integers 1 and 2.

MyLabel = Bwlabel (BW) mylabel = 1 1 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 0 0 0 0

Double creates a discontinuous region callout matrix that contains an integer 1 callout.

Mylabel2 = Double (BW) Mylabel2 = 1 1 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0

Regionprops is not responsible for automatically converting binary image data types, it is up to you to decide which data conversion method to use to store the data you want.

The extension of the regionprops function: on the basis of the Regionprops function, you can use the basic data it provides to extend its function, develop the curvature data of the region and the skeleton data as its additional attribute values. So that it can be used to do more detailed feature extraction.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.