Helper functions

Let's assume we have the following code example, which is loading an image and running Felzenszwalb algorithms on an image:

using Images, ImageSegmentation
img = load("sample-images/cat-3352842_640.jpg");
segments = felzenszwalb(img, 75, 350)

What do you think is the output of the algorithm? Or in other words, what is stored in the segments variables? Let's check by typing segments in Julia REPL:

Main> segments
Segmented Image with:
labels map: 426×640 Array{Int64,2}
number of labels: 5

We see a well-formatted response, which does not expose any other information except the image size and number of labels or segments. In order to retrieve the information from the segments variable, we have been using the following set of functions:

You should be able to use the preceding functions with most of the algorithms from the Julia ImageSegmentation package.

A very good example of using all of these functions together is the segment_to_image function, which you may have seen and used before. It iterates over every pixel of an image, identifies its segment number, and converts it to the mean intensity of the segment. This is shown in the following code:

segment_to_image(segments) = map(i->segment_mean(segments, i), labels_map(segments))