mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-17 07:18:04 +08:00
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:
@@ -513,3 +513,18 @@ fn exposure(color: Color, exposure: f64, offset: f64, gamma_correction: f64) ->
|
||||
// TODO: Remove conversion to linear when the whole node graph uses linear color
|
||||
result.to_gamma_srgb()
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct IndexNode<Index> {
|
||||
pub index: Index,
|
||||
}
|
||||
|
||||
#[node_macro::node_fn(IndexNode)]
|
||||
pub fn index_node(input: Vec<super::ImageFrame<Color>>, index: u32) -> super::ImageFrame<Color> {
|
||||
if (index as usize) < input.len() {
|
||||
input[index as usize].clone()
|
||||
} else {
|
||||
warn!("The number of segments is {} and the requested segment is {}!", input.len(), index);
|
||||
super::ImageFrame::empty()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user