Add the image segmentation node (#1122)

* Add image segmentation node

This is a node which receives as input:
- An image.
- A mask, which consists of colors that define the image segments.

Each unique color in the mask defines an area where a segmen resides.
The node generates a `Vec<ImageFrame>` where the length of the result
is the number of unique colors in the mask.

Signed-off-by: Ică Alexandru-Gabriel <alexandru@seyhanlee.com>

* Add the Index node for image segments

Since the output of the image segmentation node is a `Vec<ImageFrame>`,
we want a way to access the segments individually. The Index node receives
a `Vec<ImageFrame>` as input and an index, and returns the image found
at that index in the vec.

Signed-off-by: Ică Alexandru-Gabriel <alexandru@seyhanlee.com>

* Integrate the image segmentation and index nodes into the editor

Signed-off-by: Ică Alexandru-Gabriel <alexandru@seyhanlee.com>

* Initialize the input of the index node with an empty image frame

Signed-off-by: Ică Alexandru-Gabriel <alexandru@seyhanlee.com>

* Don't expose the parameter for the index node

Signed-off-by: Ică Alexandru-Gabriel <alexandru@seyhanlee.com>

* Don't crash the editor when the number of segments exceeds the accepted limit

Signed-off-by: Ică Alexandru-Gabriel <alexandru@seyhanlee.com>

* Print a warning in the console when the number of segments exceeds the accepted limit

Signed-off-by: Ică Alexandru-Gabriel <alexandru@seyhanlee.com>

* Add a few more checks so that the editor doesn't crash on invalid input

Signed-off-by: Ică Alexandru-Gabriel <alexandru@seyhanlee.com>

* Replace the tagged value for the index node

Signed-off-by: Ică Alexandru-Gabriel <alexandru@seyhanlee.com>

* Fix merge conflicts

---------

Signed-off-by: Ică Alexandru-Gabriel <alexandru@seyhanlee.com>
Co-authored-by: Dennis Kobert <dennis@kobert.dev>
This commit is contained in:
Alexandru Ică 2023-04-16 14:51:33 +03:00 committed by Keavon Chambers
parent ce5b73598c
commit b626d39035
7 changed files with 182 additions and 0 deletions

View file

@ -218,6 +218,8 @@ fn node_registry() -> HashMap<NodeIdentifier, HashMap<NodeIOTypes, NodeConstruct
// Filters
raster_node!(graphene_core::raster::LuminanceNode<_>, params: [LuminanceCalculation]),
raster_node!(graphene_core::raster::LevelsNode<_, _, _, _, _>, params: [f64, f64, f64, f64, f64]),
register_node!(graphene_std::image_segmentation::ImageSegmentationNode<_>, input: ImageFrame<Color>, params: [ImageFrame<Color>]),
register_node!(graphene_core::raster::IndexNode<_>, input: Vec<ImageFrame<Color>>, params: [u32]),
vec![
(
NodeIdentifier::new("graphene_core::raster::BlendNode<_, _, _, _>"),