This was a great reference! @David_Tschumperle out of curiosity, where is the source code of fx_extract_foreground
?
I spent a while figuring out how to create the image with labeled points. So here is my code for reference. I’m using the Python bindings:
import gmic
import numpy
from enum import Enum
class Labels(Enum):
ZERO = 0
BACKGROUND = 1
FOREGROUND = 2
g = gmic.Gmic()
image_results = []
g.run("input input.jpg", image_results)
input_image = image_results[0]
zero_image = gmic.GmicImage(width=input_image._width,
height=input_image._height, spectrum=1)
# Have to copy the array because the to_numpy() result is read-only
arr = zero_image.to_numpy().copy()
bg_points = [(967, 1651), (1656, 1588), (2068, 3636), (649, 3675),
(1107, 2093)]
fg_points = [(1323, 1665), (1173, 1710), (1167, 1879), (1110, 2263),
(933, 2331), (630, 2671), (757, 2506), (1230, 3600),
(964, 3487), (1236, 1788), (1065, 2281), (1217, 2173),
(1140, 1842), (991, 2231)]
for bg_x, bg_y in bg_points:
arr[bg_x, bg_y] = Labels.BACKGROUND.value
for fg_x, fg_y in fg_points:
arr[fg_x, fg_y] = Labels.FOREGROUND.value
labeled = gmic.GmicImage.from_numpy(arr)
image_results.append(labeled)
# Do permutation here because using GmicImage.from_numpy_helper(arr
# permute='yxzc') is not working.
g.run("permute[1] yxzc", image_results)
g.run("+_x_segment[0] +watershed[1] [-1]", image_results)
g.run("display", image_results)
Here is the result: