ImageMorphology.GuoAlgo
— Typestruct GuoAlgo <: ThinAlgo end
The Guo algorithm evaluates three conditions in order to determine which pixels of the image should be removed.
The three conditions are explained in the page 361 of Guo, Z., & Hall, R. W. (1989). Parallel thinning with two-subiteration algorithms. Communications of the ACM, 32(3), 359-373.
ImageMorphology.MaxTree
— TypeMax-tree morphological representation of an image.
Details
Let's consider a thresholding operation,
mask = [val ≥ threshold for val in image]
One can identify the connected components (the sets of neighboring true values) in mask
. When image thresholding is sequentially applied for all possible thresholds, it generates a collection of connected components that could be organized into a hierarchical structure called component tree. Consider 1D "image" with values 1, 2 and 3:
2233233312223322
The connected components would be
1: AAAAAAAAAAAAAAAA
2: BBBBBBBB.CCCCCCC
3: ..DD.EEE....FF..
Here, the letters are the labels of the resulting connected components, and .
specifies that the pixel value is below the threshold. In this example, the corresponding component tree is:
A
⭩ ⭨
B C
⭩ ⭨ ⭨
D E F
A max-tree is an efficient representation of the component tree. A connected component $C$ at threshold level $t$ is represented by the single reference pixel $r$ from this level (image[r] == t
), which is the parent to all other pixels of $C$ and also to the reference pixels of the connected components at higher thresholds, which are the children of $C$. In our example, the reference pixels (denoted by the letter of the corresponding component) would be:
1: ........A.......
2: B........C......
3: ..D..E......F...
I.e.
Comp | Ref.Pixel |
---|---|
A | 9 |
B | 1 |
C | 10 |
D | 3 |
E | 6 |
F | 13 |
So the whole max-tree could be encoded as a vector of indices of parent pixels:
9 1 1 3 1 1 6 6 9 9 10 10 10 13 10 10
The max-tree is the basis for many morphological operators, namely connected operators. Unlike morphological openings and closings, these operators do not require a fixed structuring element, but rather act with a flexible structuring element that meets a certain criterion.
See also
area_opening
, area_closing
, diameter_opening
, diameter_closing
.
References
- Salembier, P., Oliveras, A., & Garrido, L. (1998). Antiextensive Connected Operators for Image and Sequence Processing. IEEE Transactions on Image Processing, 7(4), 555-570.
https://doi.org/10.1109/83.663500
- Berger, C., Geraud, T., Levillain, R., Widynski, N., Baillard, A., Bertin, E. (2007). Effective Component Tree Computation with Application to Pattern Recognition in Astronomical Imaging. In International Conference on Image Processing (ICIP), 41-44.
https://doi.org/10.1109/ICIP.2007.4379949
- Najman, L., & Couprie, M. (2006). Building the component tree in quasi-linear time. IEEE Transactions on Image Processing, 15(11), 3531-3539.
https://doi.org/10.1109/TIP.2006.877518
- Carlinet, E., & Geraud, T. (2014). A Comparative Review of Component Tree Computation Algorithms. IEEE Transactions on Image Processing, 23(9), 3885-3895.
https://doi.org/10.1109/TIP.2014.2336551
ImageMorphology.MaxTree
— MethodMaxTree(image::GenericGrayImage; connectivity=1, rev=false) -> MaxTree
Constructs the max-tree of the image
.
Arguments
connectivity::Integer=1
: defines the pixel neighborhood used to construct the connected components. The value is the maximum number of orthogonal steps to reach a neighbor. In 2D, it is 1 for a 4-neighborhood and 2 for a 8-neighborhood. See `rebuild!.rev::Bool=false
: iffalse
, the max-tree is traversed from the darkest (the root node) to the brightest, otherwise it's traversed from the brightest (the root) to the darkest.
Examples
We create a small sample image (Figure 1 from [4]) and build the max-tree.
julia> image = [15 13 16; 12 12 10; 16 12 14]
3×3 Array{Int64,2}:
15 13 16
12 12 10
16 12 14
julia> mtree = MaxTree(image, connectivity=2)
MaxTree{2}(false, [4 2 4; 8 2 8; 2 2 2], [8, 2, 5, 6, 4, 9, 1, 3, 7])
ImageMorphology.ThinAlgo
— TypeThinAlgo
A thinning algorithm.
ImageMorphology.area_closing
— Functionarea_closing(image, [maxtree]; min_area=64, connectivity=1) -> Array
Performs an area closing of the image
.
Area closing replaces all dark components of an image that have a surface smaller than min_area
with the brighter value taken from their first ancestral component (in max-tree representation of image
) that has the area no smaller than min_area
.
Details
Area closing is the dual operation to area opening (see area_opening
). It is similar to morphological closings (see closing
), but instead of using a fixed structuring element (e.g. disk) it employs small (less than min_area
) components of the max-tree. Consequently, the area_closing
with min_area = 1
is the identity transformation.
In the binary case, area closing is equivalent to remove_small_holes
; this operator is thus extended to gray-level images.
Arguments
image::GenericGrayImage
: the $N$-dimensional input imagemin_area::Number=64
: the smallest size (in pixels) of the image component to keep intactconnectivity::Integer=1
: the neighborhood connectivity. The maximum number of orthogonal steps to reach a neighbor of the pixel. In 2D, it is 1 for a 4-neighborhood and 2 for a 8-neighborhood.maxtree::MaxTree
: optional pre-built max-tree. Note thatmaxtree
andconnectivity
optional parameters are mutually exclusive.
Returns
An array of the same type and shape as the image
.
See also
area_closing!
, area_opening
, diameter_closing
, MaxTree
, closing
References
- Vincent, L. (1993). Grayscale area openings and closings, their efficient implementation and applications, Proc. of EURASIP Workshop on Mathematical Morphology and its Applications to Signal Processing, Barcelona, Spain, 22-27
- Soille, P. (2003). Chapter 6 Geodesic Metrics of Morphological Image Analysis: Principles and Applications, 2nd edition, Springer.
https://doi.org/10.1007/978-3-662-05088-0
- Salembier, P., Oliveras, A., & Garrido, L. (1998). Antiextensive Connected Operators for Image and Sequence Processing. IEEE Transactions on Image Processing, 7(4), 555-570.
https://doi.org/10.1109/83.663500
- Najman, L., & Couprie, M. (2006). Building the component tree in quasi-linear time. IEEE Transactions on Image Processing, 15(11), 3531-3539.
https://doi.org/10.1109/TIP.2006.877518
- Carlinet, E., & Geraud, T. (2014). A Comparative Review of Component Tree Computation Algorithms. IEEE Transactions on Image Processing, 23(9), 3885-3895.
https://doi.org/10.1109/TIP.2014.2336551
Examples
Creating a test image f
(quadratic function with a minimum in the center and 4 additional local minima):
julia> w = 12;
julia> f = [180 + 0.2*((x - w/2)^2 + (y-w/2)^2) for x in 0:w, y in 0:w];
julia> f[3:4, 2:6] .= 40; f[3:5, 10:12] .= 60; f[10:12, 3:5] .= 80;
julia> f[10:11, 10:12] .= 100; f[11, 11] = 100;
julia> f_aclose = area_closing(f, min_area=8, connectivity=1);
All small minima are removed, and the remaining minima have at least a size of 8.
ImageMorphology.area_closing!
— Methodarea_closing!(output, image, [maxtree];
min_area=64, connectivity=1) -> output
Performs in-place area closing of the image
and stores the result in output
. See area_closing
for the detailed description of the method.
ImageMorphology.area_opening
— Functionarea_opening(image, [maxtree]; min_area=64, connectivity=1) -> Array
Performs an area opening of the image
.
Area opening replaces all bright components of an image that have a surface smaller than min_area
with the darker value taken from their first ancestral component (in max-tree representation of image
) that has the area no smaller than min_area
.
Details
Area opening is similar to morphological opening (see opening
), but instead of using a fixed structuring element (e.g. disk) it employs small (less than min_area
) components of the max-tree. Consequently, the area_opening
with min_area = 1
is the identity transformation.
In the binary case, area opening is equivalent to remove_small_objects
; this operator is thus extended to gray-level images.
Arguments
image::GenericGrayImage
: the $N$-dimensional input imagemin_area::Number=64
: the smallest size (in pixels) of the image component to keep intactconnectivity::Integer=1
: the neighborhood connectivity. The maximum number of orthogonal steps to reach a neighbor of the pixel. In 2D, it is 1 for a 4-neighborhood and 2 for a 8-neighborhood.maxtree::MaxTree
: optional pre-built max-tree. Note thatmaxtree
andconnectivity
optional parameters are mutually exclusive.
Returns
An array of the same type and shape as the image
.
See also
area_opening!
, area_closing
, diameter_opening
, MaxTree
, opening
References
- Vincent, L. (1993). Grayscale area openings and closings, their efficient implementation and applications, Proc. of EURASIP Workshop on Mathematical Morphology and its Applications to Signal Processing, Barcelona, Spain, 22-27
- Soille, P. (2003). Chapter 6 Geodesic Metrics of Morphological Image Analysis: Principles and Applications, 2nd edition, Springer.
https://doi.org/10.1007/978-3-662-05088-0
- Salembier, P., Oliveras, A., & Garrido, L. (1998). Antiextensive Connected Operators for Image and Sequence Processing. IEEE Transactions on Image Processing, 7(4), 555-570.
https://doi.org/10.1109/83.663500
- Najman, L., & Couprie, M. (2006). Building the component tree in quasi-linear time. IEEE Transactions on Image Processing, 15(11), 3531-3539.
https://doi.org/10.1109/TIP.2006.877518
- Carlinet, E., & Geraud, T. (2014). A Comparative Review of Component Tree Computation Algorithms. IEEE Transactions on Image Processing, 23(9), 3885-3895.
https://doi.org/10.1109/TIP.2014.2336551
Examples
Creating a test image f
(quadratic function with a maximum in the center and 4 additional local maxima):
julia> w = 12;
julia> f = [20 - 0.2*((x - w/2)^2 + (y-w/2)^2) for x in 0:w, y in 0:w];
julia> f[3:4, 2:6] .= 40; f[3:5, 10:12] .= 60; f[10:12, 3:5] .= 80;
julia> f[10:11, 10:12] .= 100; f[11, 11] = 100;
julia> f_aopen = area_opening(f, min_area=8, connectivity=1);
The peaks with a surface smaller than 8 are removed.
ImageMorphology.area_opening!
— Methodarea_opening!(output, image, [maxtree];
min_area=64, connectivity=1) -> output
Performs in-place area opening of the image
and stores the result in output
. See area_opening
for the detailed description of the method.
ImageMorphology.areas
— Methodareas(maxtree::MaxTree) -> Array{Int}
Computes the areas of all maxtree
components.
Returns
The array of the same shape as the original image. The i
-th element is the area (in pixels) of the component that is represented by the reference pixel with index i
.
See also
ImageMorphology.bothat
— Methodimgbh = bothat(img; dims=coords_spatial(img))
performs bottom hat
of an image, which is defined as its morphological closing minus the original image. dims
allows you to control the dimensions over which this operation is performed.
Examples
julia> img = zeros(7, 7); img[3:5, 3:5] .= 1.; img[4, 4] = 0.; img
7×7 Array{Float64,2}:
0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 1.0 1.0 1.0 0.0 0.0
0.0 0.0 1.0 0.0 1.0 0.0 0.0
0.0 0.0 1.0 1.0 1.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0
julia> bothat(img)
7×7 Array{Float64,2}:
0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 1.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0
ImageMorphology.boundingboxes
— Methodboundingboxes(maxtree::MaxTree) -> Array{NTuple{2, CartesianIndex}}
Computes the minimal bounding boxes of all maxtree
components.
Returns
The array of the same shape as the original image. The i
-th element is the tuple of the minimal and maximal cartesian indices for the bounding box of the component that is represented by the reference pixel with index i
.
See also
ImageMorphology.clearborder
— Functioncleared_img = clearborder(img)
cleared_img = clearborder(img, width)
cleared_img = clearborder(img, width, background)
Returns a copy of the original image after clearing objects connected to the border of the image. Parameters:
- img = Binary/Grayscale input image
- width = Width of the border examined (Default value is 1)
- background = Value to be given to pixels/elements that are cleared (Default value is 0)
ImageMorphology.closing
— Methodimgc = closing(img; dims=coords_spatial(img))
performs the closing
morphology operation, equivalent to erode(dilate(img))
. dims
allows you to control the dimensions over which this operation is performed.
Examples
julia> img = zeros(7, 7); img[3:5, 3:5] .= 1.; img[4, 4] = 0.; img
7×7 Array{Float64,2}:
0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 1.0 1.0 1.0 0.0 0.0
0.0 0.0 1.0 0.0 1.0 0.0 0.0
0.0 0.0 1.0 1.0 1.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0
julia> closing(img)
7×7 Array{Float64,2}:
0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 1.0 1.0 1.0 0.0 0.0
0.0 0.0 1.0 1.0 1.0 0.0 0.0
0.0 0.0 1.0 1.0 1.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0
ImageMorphology.component_boxes
— Methodcomponent_boxes(labeled_array)
-> an array of bounding boxes for each label, including the background label 0
ImageMorphology.component_centroids
— Methodcomponent_centroids(labeled_array)
-> an array of centroids for each label, including the background label 0
ImageMorphology.component_indices
— Methodcomponent_indices(labeled_array)
-> an array of pixels for each label, including the background label 0
ImageMorphology.component_lengths
— Methodcomponent_lengths(labeled_array)
-> an array of areas (2D), volumes (3D), etc. for each label, including the background label 0
ImageMorphology.component_subscripts
— Methodcomponent_subscripts(labeled_array)
-> an array of pixels for each label, including the background label 0
ImageMorphology.convexhull
— Methodchull = convexhull(img)
Computes the convex hull of a binary image and returns the vertices of convex hull as a CartesianIndex array.
ImageMorphology.diameter_closing
— Functiondiameter_closing(image, [maxtree]; min_diameter=8, connectivity=1) -> Array
Performs a diameter closing of the image
.
Diameter closing replaces all dark structures of an image that have the diameter (the widest dimension of their bounding box) smaller than min_diameter
with the brighter value taken from their first ancestral component (in max-tree representation of image
) that has the diameter no smaller than min_diameter
.
Arguments
image::GenericGrayImage
: the $N$-dimensional input imagemin_diameter::Number=8
: the minimal length (in pixels) of the widest dimension of the bounding box of the image component to keep intactconnectivity::Integer=1
: the neighborhood connectivity. The maximum number of orthogonal steps to reach a neighbor of the pixel. In 2D, it is 1 for a 4-neighborhood and 2 for a 8-neighborhood.maxtree::MaxTree
: optional pre-built max-tree. Note thatmaxtree
andconnectivity
optional parameters are mutually exclusive.
Returns
An array of the same type and shape as the image
.
See also
diameter_closing!
, diameter_opening
, area_closing
, MaxTree
, closing
References
- Walter, T., & Klein, J.-C. (2002). Automatic Detection of Microaneurysms in Color Fundus Images of the Human Retina by Means of the Bounding Box Closing. In A. Colosimo, P. Sirabella, A. Giuliani (Eds.), Medical Data Analysis. Lecture Notes in Computer Science, vol 2526, 210-220. Springer Berlin Heidelberg.
https://doi.org/10.1007/3-540-36104-9_23
- Carlinet, E., & Geraud, T. (2014). A Comparative Review of Component Tree Computation Algorithms. IEEE Transactions on Image Processing, 23(9), 3885-3895.
https://doi.org/10.1109/TIP.2014.2336551
Examples
Creating a test image f
(quadratic function with a minimum in the center and 4 additional local minima):
julia> w = 12;
julia> f = [180 + 0.2*((x - w/2)^2 + (y-w/2)^2) for x in 0:w, y in 0:w];
julia> f[3:4, 2:6] .= 40; f[3:5, 10:12] .= 60; f[10:12, 3:5] .= 80;
julia> f[10:11, 10:12] .= 100; f[11, 11] = 100;
julia> f_dclose = diameter_closing(f, min_diameter=3, connectivity=1);
All small minima with a diameter of 2 or less are removed. For the remaining minima the widest bounding box side is at least 3.
ImageMorphology.diameter_closing!
— Methoddiameter_closing!(output, image, [maxtree];
min_diameter=8, connectivity=1) -> output
Performs in-place diameter closing of the image
and stores the result in output
. See diameter_closing
for the detailed description of the method.
ImageMorphology.diameter_opening
— Functiondiameter_opening(image, [maxtree]; min_diameter=8, connectivity=1) -> Array
Performs a diameter opening of the image
.
Diameter opening replaces all bright structures of an image that have the diameter (the widest dimension of their bounding box) smaller than min_diameter
with the darker value taken from their first ancestral component (in max-tree representation of image
) that has the diameter no smaller than min_diameter
.
The operator is also called Bounding Box Opening. In practice, the result is similar to a morphological opening, but long and thin structures are not removed.
Arguments
image::GenericGrayImage
: the $N$-dimensional input imagemin_diameter::Number=8
: the minimal length (in pixels) of the widest dimension of the bounding box of the image component to keep intactconnectivity::Integer=1
: the neighborhood connectivity. The maximum number of orthogonal steps to reach a neighbor of the pixel. In 2D, it is 1 for a 4-neighborhood and 2 for a 8-neighborhood.maxtree::MaxTree
: optional pre-built max-tree. Note thatmaxtree
andconnectivity
optional parameters are mutually exclusive.
Returns
An array of the same type and shape as the image
.
See also
diameter_opening!
, diameter_closing
, area_opening
, MaxTree
, opening
References
- Walter, T., & Klein, J.-C. (2002). Automatic Detection of Microaneurysms in Color Fundus Images of the Human Retina by Means of the Bounding Box Closing. In A. Colosimo, P. Sirabella, A. Giuliani (Eds.), Medical Data Analysis. Lecture Notes in Computer Science, vol 2526, 210-220. Springer Berlin Heidelberg.
https://doi.org/10.1007/3-540-36104-9_23
- Carlinet, E., & Geraud, T. (2014). A Comparative Review of Component Tree Computation Algorithms. IEEE Transactions on Image Processing, 23(9), 3885-3895.
https://doi.org/10.1109/TIP.2014.2336551
Examples
Creating a test image f
(quadratic function with a maximum in the center and 4 additional local maxima):
julia> w = 12;
julia> f = [20 - 0.2*((x - w/2)^2 + (y-w/2)^2) for x in 0:w, y in 0:w];
julia> f[3:4, 2:6] .= 40; f[3:5, 10:12] .= 60; f[10:12, 3:5] .= 80;
julia> f[10:11, 10:12] .= 100; f[11, 11] = 100;
julia> f_dopen = diameter_opening(f, min_diameter=3, connectivity=1);
The peaks with a maximal diameter of 2 or less are removed. For the remaining peaks the widest side of the bounding box is at least 3.
ImageMorphology.diameter_opening!
— Methoddiameter_opening!(output, image, [maxtree];
min_diameter=8, connectivity=1) -> output
Performs in-place diameter opening of the image
and stores the result in output
. See diameter_opening
for the detailed description of the method.
ImageMorphology.diameters
— Methoddiameters(maxtree::MaxTree) -> Array{Int}
Computes the "diameters" of all maxtree
components.
"Diameter" of the max-tree connected component is the length of the widest side of the component's bounding box.
Returns
The array of the same shape as the original image. The i
-th element is the "diameter" of the component that is represented by the reference pixel with index i
.
See also
ImageMorphology.dilate
— Methodimgd = dilate(img; dims=coords_spatial(img))
Perform a max-filter over nearest-neighbors. The default is 8-connectivity in 2d, 27-connectivity in 3d, etc. You can specify the list of dimensions that you want to include in the connectivity, e.g., dims = (1,2)
would exclude the third dimension from filtering.
Examples
julia> img = zeros(5, 5); img[3, 3] = 1.; img
5×5 Array{Float64,2}:
0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
0.0 0.0 1.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
julia> dilate(img)
5×5 Array{Float64,2}:
0.0 0.0 0.0 0.0 0.0
0.0 1.0 1.0 1.0 0.0
0.0 1.0 1.0 1.0 0.0
0.0 1.0 1.0 1.0 0.0
0.0 0.0 0.0 0.0 0.0
julia> dilate(img; dims=1)
5×5 Array{Float64,2}:
0.0 0.0 0.0 0.0 0.0
0.0 0.0 1.0 0.0 0.0
0.0 0.0 1.0 0.0 0.0
0.0 0.0 1.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
ImageMorphology.erode
— Methodimge = erode(img; dims=coords_spatial(img))
perform a min-filter over nearest-neighbors. The default is 8-connectivity in 2d, 27-connectivity in 3d, etc. You can specify the list of dimensions that you want to include in the connectivity, e.g., dims = (1,2)
would exclude the third dimension from filtering.
Examples
julia> img = zeros(5, 5); img[2:4, 2:4] .= 1.; img
5×5 Array{Float64,2}:
0.0 0.0 0.0 0.0 0.0
0.0 1.0 1.0 1.0 0.0
0.0 1.0 1.0 1.0 0.0
0.0 1.0 1.0 1.0 0.0
0.0 0.0 0.0 0.0 0.0
julia> erode(img)
5×5 Array{Float64,2}:
0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
0.0 0.0 1.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
julia> erode(img; dims=1)
5×5 Array{Float64,2}:
0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
0.0 1.0 1.0 1.0 0.0
0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
ImageMorphology.filter_components!
— Functionfilter_components!(output::GenericGrayImage, image::GenericGrayImage,
maxtree::MaxTree, attrs::AbstractVector,
min_attr, all_below_min) -> output
Filters the connected components of the image
and stores the result in output
.
The $output$ is the copy of the $image$ exluding the connected components, whose attribute value is below min_attr
. That is, the pixels of the exluded component are reset to the value of the reference pixel of its first valid ancestor (the connected component with the attribute value greater or equal to min_attr
).
Arguments
maxtree::MaxTree
: pre-built max-tree representation of theimage
attrs::AbstractVector
:attrs[i]
is the attribute value for the $i$-th component of the tree ($i$ being the linear index of its reference pixel)all_below_min
: the value to fill theoutput
if all attributes of all components (including the root one) are belowmin_attr
Details
This function is the basis for area_opening
, diameter_opening
and similar transformations. E.g. for area_opening
the attribute is the area of the components. In this case, the max-tree components of the output
have area no smaller than min_attr
pixels.
The method assumes that the attribute values are monotone with respect to the components hieararchy, i.e. $attrs[i] <= attrs[maxtree.parentindices[i]]$ for each i
.
ImageMorphology.imfill
— Methodfilled_img = imfill(img::AbstractArray{Bool}, interval; dims=coords_spatial(img))
filled_img = imfill(img::AbstractArray{Bool}, interval, connectivity)
Connected components of an image is found using flood-fill algorithm and returns a copy of the original image after filling objects that falls in the range of interval. For filling objects, represent the holes (part to be filled) with true
in your array.
Parameters:
- img = Input image (Boolean array type)
- interval = objects of size (# of voxels) in this range will be filled with
false
- connectivity = a Boolean-valued connectivity pattern, see
label_components
.
Examples
julia> img = Bool[0 0 1 1 0 0;
0 1 0 1 1 0;
0 0 1 1 0 0]
3×6 Matrix{Bool}:
0 0 1 1 0 0
0 1 0 1 1 0
0 0 1 1 0 0
julia> imfill(.!(img), 0:3)
3×6 BitMatrix:
1 1 0 0 1 1
1 0 0 0 0 1
1 1 0 0 1 1
julia> .!(ans)
3×6 BitMatrix:
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
ImageMorphology.label_components
— Methodlabel = label_components(A; bkg = zero(eltype(A)), dims=coords_spatial(A))
label = label_components(A, connectivity; bkg = zero(eltype(A)))
Find the connected components in an array A
. Components are defined as connected voxels that all have the same value distinct from bkg
, which corresponds to the "background" component.
Specify connectivity in one of three ways:
A list indicating which dimensions are used to determine connectivity. For example,
dims = (1,3)
would not test neighbors along dimension 2 for connectivity. This corresponds to just the nearest neighbors, i.e., default 4-connectivity in 2d and 6-connectivity in 3d.An iterable
connectivity
object withCartesianIndex
elements encoding the displacement of each checked neighbor.A symmetric boolean array of the same dimensionality as
A
, of size 1 or 3 along each dimension. Each entry in the array determines whether a given neighbor is used for connectivity analyses. For example, in two dimensionsconnectivity = trues(3,3)
would include all pixels that touch the current one, even the corners.
The output label
is an integer array, where bkg
elements get a value of 0.
Examples
julia> A = [true false false true false;
true false true true true]
2×5 Matrix{Bool}:
1 0 0 1 0
1 0 1 1 1
julia> label_components(A)
2×5 Matrix{Int64}:
1 0 0 2 0
1 0 2 2 2
julia> label_components(A; dims=2)
2×5 Matrix{Int64}:
1 0 0 4 0
2 0 3 3 3
With dims=2
, entries in A
are connected if they are in the same row, but not if they are in the same column.
ImageMorphology.local_maxima
— Functionlocal_maxima(image, [maxtree]; connectivity=1) -> Array
Determines and labels all local maxima of the image
.
Details
The local maximum is defined as the connected set of pixels that have the same value, which is greater than the values of all pixels in direct neighborhood of the set.
Technically, the implementation is based on the max-tree representation of an image. It's beneficial if the max-tree is already computed, otherwise Images.findlocalmaxima
would be more efficient.
Arguments
image::GenericGrayImage
: the $N$-dimensional input imageconnectivity::Integer=1
: the neighborhood connectivity. The maximum number of orthogonal steps to reach a neighbor of the pixel. In 2D, it is 1 for a 4-neighborhood and 2 for a 8-neighborhood.maxtree::MaxTree
: optional pre-built max-tree. Note thatmaxtree
andconnectivity
optional parameters are mutually exclusive.
Returns
An integer array of the same shape as the image
. Pixels that are not local maxima have 0 value. Pixels of the same local maximum share the same positive value (the local maximum id).
See also
MaxTree
, local_maxima!
, local_minima
, Images.findlocalmaxima
Examples
Create f
(quadratic function with a maximum in the center and 4 additional constant maxima):
julia> w = 10;
julia> f = [20 - 0.2*((x - w/2)^2 + (y-w/2)^2) for x in 0:w, y in 0:w];
julia> f[3:5, 3:5] .= 40; f[3:5, 8:10] .= 60; f[8:10, 3:5] .= 80; f[8:10, 8:10] .= 100;
julia> f_maxima = local_maxima(f); # Get all local maxima of `f`
The resulting image contains the 4 labeled local maxima.
ImageMorphology.local_maxima!
— Methodlocal_maxima!(output, image, [maxtree]; connectivity=1) -> output
Detects the local maxima of image
and stores the result in output
. See local_maxima
for the detailed description of the method.
ImageMorphology.local_minima
— Functionlocal_minima(image, [maxtree]; connectivity=1) -> Array
Determines and labels all local minima of the image
.
Details
The local minimum is defined as the connected set of pixels that have the same value, which is less than the values of all pixels in direct neighborhood of the set.
Technically, the implementation is based on the max-tree representation of an image. It's beneficial if the max-tree is already computed, otherwise Images.findlocalminima
would be more efficient.
Arguments
image::GenericGrayImage
: the $N$-dimensional input imageconnectivity::Integer=1
: the neighborhood connectivity. The maximum number of orthogonal steps to reach a neighbor of the pixel. In 2D, it is 1 for a 4-neighborhood and 2 for a 8-neighborhood.maxtree::MaxTree
: optional pre-built max-tree. Note thatmaxtree
andconnectivity
optional parameters are mutually exclusive.
Returns
An integer array of the same shape as the image
. Pixels that are not local minima have 0 value. Pixels of the same local minimum share the same positive value (the local minimum id).
See also
MaxTree
, local_minima!
, local_maxima
, Images.findlocalminima
Examples
Create f
(quadratic function with a minimum in the center and 4 additional constant minimum):
julia> w = 10;
julia> f = [180 + 0.2*((x - w/2)^2 + (y-w/2)^2) for x in 0:w, y in 0:w];
julia> f[3:5, 3:5] .= 40; f[3:5, 8:10] .= 60; f[8:10, 3:5] .= 80; f[8:10, 8:10] .= 100;
julia> f_minima = local_minima(f); # Calculate all local minima of `f`
The resulting image contains the labeled local minima.
ImageMorphology.local_minima!
— Methodlocal_minima!(output, image, [maxtree]; connectivity=1) -> output
Detects the local minima of image
and stores the result in output
. See local_minima
for the detailed description of the method.
ImageMorphology.morphogradient
— Methodimgmg = morphogradient(img; dims=coords_spatial(img))
returns morphological gradient of the image, which is the difference between the dilation and the erosion of a given image. dims
allows you to control the dimensions over which this operation is performed.
Examples
julia> img = zeros(7, 7); img[3:5, 3:5] .= 1.; img
7×7 Array{Float64,2}:
0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 1.0 1.0 1.0 0.0 0.0
0.0 0.0 1.0 1.0 1.0 0.0 0.0
0.0 0.0 1.0 1.0 1.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0
julia> morphogradient(img)
7×7 Array{Float64,2}:
0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 1.0 1.0 1.0 1.0 1.0 0.0
0.0 1.0 1.0 1.0 1.0 1.0 0.0
0.0 1.0 1.0 0.0 1.0 1.0 0.0
0.0 1.0 1.0 1.0 1.0 1.0 0.0
0.0 1.0 1.0 1.0 1.0 1.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0
ImageMorphology.morpholaplace
— Methodimgml = morpholaplace(img; dims=coords_spatial(img))
performs Morphological Laplacian
of an image, which is defined as the arithmetic difference between the internal and the external gradient. dims
allows you to control the dimensions over which this operation is performed.
Examples
julia> img = zeros(7, 7); img[3:5, 3:5] .= 1.; img[4, 4] = 0.; img
7×7 Array{Float64,2}:
0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 1.0 1.0 1.0 0.0 0.0
0.0 0.0 1.0 0.0 1.0 0.0 0.0
0.0 0.0 1.0 1.0 1.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0
julia> morpholaplace(img)
7×7 Array{Float64,2}:
0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 1.0 1.0 1.0 1.0 1.0 0.0
0.0 1.0 -1.0 -1.0 -1.0 1.0 0.0
0.0 1.0 -1.0 1.0 -1.0 1.0 0.0
0.0 1.0 -1.0 -1.0 -1.0 1.0 0.0
0.0 1.0 1.0 1.0 1.0 1.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0
ImageMorphology.opening
— Methodimgo = opening(img; dims=coords_spatial(img))
performs the opening
morphology operation, equivalent to dilate(erode(img))
. dims
allows you to control the dimensions over which this operation is performed.
Examples
julia> img = zeros(5, 5); img[1, 1] = 1.; img[3:5, 3:5] .= 1.; img
5×5 Array{Float64,2}:
1.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
0.0 0.0 1.0 1.0 1.0
0.0 0.0 1.0 1.0 1.0
0.0 0.0 1.0 1.0 1.0
julia> opening(img)
5×5 Array{Float64,2}:
0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
0.0 0.0 1.0 1.0 1.0
0.0 0.0 1.0 1.0 1.0
0.0 0.0 1.0 1.0 1.0
ImageMorphology.rebuild!
— Methodrebuild!(maxtree::MaxTree, image::GenericGrayImage,
neighbors::AbstractVector{CartesianIndex}) -> maxtree
Rebuilds the maxtree
for the image
using neighbors
as the pixel connectivity specification.
Details
The pixels in the connected components generated by the method should be connected to each other by a path through neighboring pixels. The pixels $p_1$ and $p_2$ are neighbors, if neighbors
array contains $d$, such that $p_2 = p_1 + d$.
See also
ImageMorphology.root_index
— Methodroot_index(maxtree::MaxTree) -> Int
Linear index of the root pixel.
ImageMorphology.thinning
— Methodthinning(img::AbstractArray{Bool}; algo::ThinAlgo=GuoAlgo())
Applies a binary blob thinning operation to achieve a skeletization of the input image.
See also: GuoAlgo
ImageMorphology.tophat
— Methodimgth = tophat(img; dims=coords_spatial(img))
performs top hat
of an image, which is defined as the image minus its morphological opening. dims
allows you to control the dimensions over which this operation is performed.
Examples
julia> img = zeros(5, 5); img[1, 1] = 1.; img[3:5, 3:5] .= 1.; img
5×5 Array{Float64,2}:
1.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
0.0 0.0 1.0 1.0 1.0
0.0 0.0 1.0 1.0 1.0
0.0 0.0 1.0 1.0 1.0
julia> tophat(img)
5×5 Array{Float64,2}:
1.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0