ImageComponentAnalysis.jl Documentation
A Julia package for analyzing connected components.
Getting started
This package is part of a wider Julia-based image processing ecosystem. If you are starting out, then you may benefit from reading about some fundamental conventions that the ecosystem utilizes that are markedly different from how images are typically represented in OpenCV, MATLAB, ImageJ or Python.
The usage examples in the ImageComponentAnalysis.jl
package assume that you have already installed some key packages. Notably, the examples assume that you are able to load and display an image. Loading an image is facilitated through the FileIO.jl package, which uses QuartzImageIO.jl if you are on MacOS
, and ImageMagick.jl otherwise. Depending on your particular system configuration, you might encounter problems installing the image loading packages, in which case you can refer to the troubleshooting guide.
Image display is typically handled by the ImageView.jl package. However, there are some known issues with this package. For example, on Windows
the package has the side-effect of introducing substantial input lag when typing in the Julia REPL. Also, as of writing, some users of MacOS
are unable to use the ImageView.jl
package.
As an alternative, one can display an image using the Makie.jl plotting package. There is also the ImageShow.jl package which facilitates displaying images in Jupyter
notebooks via IJulia.jl.
Finally, one can also obtain a useful preview of an image in the REPL using the ImageInTerminal.jl package. However, this package assumes that the terminal uses a monospace font, and tends not to produce adequate results in a Windows environment.
Another package that is used to illustrate the functionality in ImageComponentAnalysis.jl
is the TestImages.jl which serves as a repository of many standard image processing test images.
Basic usage
Each connected component analysis algorithm in ImageComponentAnalysis.jl
is an AbstractComponentAnalysisAlgorithm
.
Suppose one wants to determine the size of each connected component. This can be achieved by simply choosing an appropriate algorithm and calling analyze_components
or analyze_components!
on an array of labelled components.
Let's see a simple demo:
using TestImages, ImageComponentAnalysis, ImageBinarization
img = binarize(testimage("cameraman"), Otsu())
components = label_components(img)
measurements = analyze_components(components, BasicMeasurement(area = true, perimeter = true))
41 rows × 10 columns
l | Q₀ | Q₁ | Q₂ | Q₃ | Q₄ | Qₓ | area | perimeter₀ | perimeter₁ | |
---|---|---|---|---|---|---|---|---|---|---|
Int64 | Int64 | Int64 | Int64 | Int64 | Int64 | Int64 | Float64 | Float64 | Int64 | |
1 | 1 | 120367 | 701 | 2786 | 1067 | 140301 | 3 | 1.42805e5 | 4040.41 | 4560 |
2 | 2 | 253548 | 69 | 444 | 109 | 11055 | 0 | 11389.6 | 569.865 | 622 |
3 | 3 | 264360 | 37 | 112 | 37 | 679 | 0 | 776.625 | 164.326 | 186 |
4 | 4 | 259439 | 117 | 354 | 145 | 5170 | 0 | 5503.12 | 539.262 | 616 |
5 | 5 | 265201 | 11 | 4 | 7 | 2 | 0 | 12.875 | 16.7279 | 22 |
6 | 6 | 261815 | 270 | 354 | 298 | 2488 | 0 | 2993.25 | 755.637 | 922 |
7 | 7 | 264713 | 49 | 58 | 49 | 356 | 0 | 440.125 | 127.296 | 156 |
8 | 8 | 237019 | 513 | 1304 | 717 | 25658 | 14 | 27076.1 | 2193.54 | 2562 |
9 | 9 | 265187 | 11 | 8 | 7 | 12 | 0 | 24.875 | 20.7279 | 26 |
10 | 10 | 263762 | 53 | 104 | 49 | 1257 | 0 | 1365.12 | 176.125 | 206 |
11 | 11 | 265212 | 6 | 4 | 2 | 1 | 0 | 6.25 | 9.65685 | 12 |
12 | 12 | 265221 | 4 | 0 | 0 | 0 | 0 | 1.0 | 2.82843 | 4 |
13 | 13 | 265214 | 5 | 4 | 1 | 1 | 0 | 5.125 | 8.24264 | 10 |
14 | 14 | 265217 | 4 | 4 | 0 | 0 | 0 | 3.0 | 6.82843 | 8 |
15 | 15 | 265217 | 4 | 4 | 0 | 0 | 0 | 3.0 | 6.82843 | 8 |
16 | 16 | 264901 | 35 | 64 | 31 | 194 | 0 | 261.875 | 110.669 | 130 |
17 | 17 | 264690 | 24 | 96 | 20 | 395 | 0 | 466.5 | 127.113 | 140 |
18 | 18 | 265199 | 8 | 10 | 4 | 4 | 0 | 14.5 | 18.4853 | 22 |
19 | 19 | 265198 | 8 | 10 | 4 | 5 | 0 | 15.5 | 18.4853 | 22 |
20 | 20 | 265221 | 4 | 0 | 0 | 0 | 0 | 1.0 | 2.82843 | 4 |
21 | 21 | 265173 | 12 | 12 | 8 | 20 | 0 | 36.0 | 26.1421 | 32 |
22 | 22 | 265168 | 14 | 16 | 10 | 17 | 0 | 37.25 | 32.9706 | 40 |
23 | 23 | 265149 | 9 | 22 | 5 | 40 | 0 | 57.625 | 31.8995 | 36 |
24 | 24 | 265201 | 4 | 20 | 0 | 0 | 0 | 11.0 | 22.8284 | 24 |
25 | 25 | 265215 | 4 | 6 | 0 | 0 | 0 | 4.0 | 8.82843 | 10 |
26 | 26 | 265217 | 4 | 4 | 0 | 0 | 0 | 3.0 | 6.82843 | 8 |
27 | 27 | 265215 | 5 | 4 | 1 | 0 | 0 | 4.125 | 8.24264 | 10 |
28 | 28 | 265216 | 4 | 4 | 0 | 1 | 0 | 4.0 | 6.82843 | 8 |
29 | 29 | 265164 | 15 | 16 | 11 | 19 | 0 | 40.375 | 34.3848 | 42 |
30 | 30 | 265082 | 18 | 34 | 14 | 77 | 0 | 110.75 | 56.6274 | 66 |
31 | 31 | 265217 | 4 | 4 | 0 | 0 | 0 | 3.0 | 6.82843 | 8 |
32 | 32 | 265215 | 5 | 4 | 1 | 0 | 0 | 4.125 | 8.24264 | 10 |
33 | 33 | 265214 | 5 | 4 | 1 | 1 | 0 | 5.125 | 8.24264 | 10 |
34 | 34 | 265205 | 7 | 8 | 3 | 2 | 0 | 10.375 | 15.0711 | 18 |
35 | 35 | 265221 | 4 | 0 | 0 | 0 | 0 | 1.0 | 2.82843 | 4 |
36 | 36 | 265154 | 15 | 28 | 13 | 14 | 1 | 43.875 | 49.2132 | 58 |
37 | 37 | 265217 | 4 | 4 | 0 | 0 | 0 | 3.0 | 6.82843 | 8 |
38 | 38 | 265112 | 14 | 30 | 14 | 55 | 0 | 85.75 | 49.799 | 58 |
39 | 39 | 265221 | 4 | 0 | 0 | 0 | 0 | 1.0 | 2.82843 | 4 |
40 | 40 | 265221 | 4 | 0 | 0 | 0 | 0 | 1.0 | 2.82843 | 4 |
41 | 41 | 265221 | 4 | 0 | 0 | 0 | 0 | 1.0 | 2.82843 | 4 |
This usage reads as "analyze_components
of the label array components
with algorithm alg
"
For more advanced usage, please check function reference page.