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

lQ₀Q₁Q₂Q₃Q₄Qₓareaperimeter₀perimeter₁
Int64Int64Int64Int64Int64Int64Int64Float64Float64Int64
111203677012786106714030131.42805e54040.414560
222535486944410911055011389.6569.865622
3326436037112376790776.625164.326186
44259439117354145517005503.12539.262616
5526520111472012.87516.727922
66261815270354298248802993.25755.637922
772647134958493560440.125127.296156
882370195131304717256581427076.12193.542562
99265187118712024.87520.727926
10102637625310449125701365.12176.125206
1111265212642106.259.6568512
1212265221400001.02.828434
1313265214541105.1258.2426410
1414265217440003.06.828438
1515265217440003.06.828438
16162649013564311940261.875110.669130
17172646902496203950466.5127.113140
181826519981044014.518.485322
191926519881045015.518.485322
2020265221400001.02.828434
21212651731212820036.026.142132
222226516814161017037.2532.970640
2323265149922540057.62531.899536
242426520142000011.022.828424
2525265215460004.08.8284310
2626265217440003.06.828438
2727265215541004.1258.2426410
2828265216440104.06.828438
292926516415161119040.37534.384842
3030265082183414770110.7556.627466
3131265217440003.06.828438
3232265215541004.1258.2426410
3333265214541105.1258.2426410
34342652057832010.37515.071118
3535265221400001.02.828434
363626515415281314143.87549.213258
3737265217440003.06.828438
383826511214301455085.7549.79958
3939265221400001.02.828434
4040265221400001.02.828434
4141265221400001.02.828434

This usage reads as "analyze_components of the label array components with algorithm alg"

For more advanced usage, please check function reference page.