Class EditingMaskStage<R extends bg.codexio.ai.openai.api.payload.images.request.ImageRequest,​E extends RuntimeSelectionStage>

  • All Implemented Interfaces:
    IntermediateStage

    public class EditingMaskStage<R extends bg.codexio.ai.openai.api.payload.images.request.ImageRequest,​E extends RuntimeSelectionStage>
    extends ImageConfigurationStage<R>
    implements IntermediateStage

    A stage to specify the editable areas of the image.

    You can choose to:

    • Choose unmasked option, which will automatically make only the purely white areas of the image editable
    • Upload a custom mask for the file with the transparent areas
    • Specify the are that should be editable by color. If you select this option, you'll have to choose ColorDeviation level and provide a color in one of the following forms:
      • Decimal
      • Hexadecimal
      • RBG
      • From the predefined colors selection in PopularColor
    • Method Detail

      • areColorsSimilar

        protected static boolean areColorsSimilar​(int left,
                                                  int right,
                                                  double tolerance)
      • unmasked

        public ChoicesStage<R,​E> unmasked()
        Skips the masking stage.
        Returns:
        ChoicesStage to configure the choices count.
      • masked

        public ChoicesStage<R,​E> masked​(File mask)
        Parameters:
        mask - file with the desired mask image. Sets a custom mask from the file provided.

        Important note: The mask must be a valid PNG file, less than 4MB, and have the same dimensions as the original image for editing. The fully transparent areas of the mask will be the areas of the original image that will be edited.

        If any of those conditions is not followed, it will result in an error response.

        Returns:
        ChoicesStage to configure the choices count.
      • masked

        public ChoicesStage<R,​E> masked​(int alphaZeroHex,
                                              ColorDeviation deviation)
        Parameters:
        alphaZeroHex - decimal value of the color that indicates the editable areas
        deviation - ColorDeviation level of deviation - the similarity of the colors that should be marked as editable
        Returns:
        ChoicesStage to configure the choices count.
      • masked

        public ChoicesStage<R,​E> masked​(PopularColor color)
        Parameters:
        color - PopularColor choice of color that indicates the editable ares

        In this case, the color deviation is automatically set to the lowest value, which means that only the specific color with no deviations will be marked for editing.

        Returns:
        ChoicesStage to configure the choices count.
      • masked

        public ChoicesStage<R,​E> masked​(int alphaZeroHex)
        Parameters:
        alphaZeroHex - decimal value of the color that indicates the editable areas

        In this case, the color deviation is automatically set to the lowest value, which means that only the specific color with no deviations will be marked for editing.

        Returns:
        ChoicesStage to configure the choices count.
      • masked

        public ChoicesStage<R,​E> masked​(int red,
                                              int green,
                                              int blue,
                                              ColorDeviation deviation)
        Parameters:
        red - the amount of red in RGB color scale for marking the editable area
        green - the amount of green in RGB color scale for marking the editable area
        blue - the amount of blue in RGB color scale for marking the editable area
        deviation - ColorDeviation level of deviation - the similarity of the colors that should be marked as editable
        Returns:
        ChoicesStage to configure the choices count.
      • masked

        public ChoicesStage<R,​E> masked​(int red,
                                              int green,
                                              int blue)
        Parameters:
        red - the amount of red in RGB color scale for marking the editable area
        green - the amount of green in RGB color scale for marking the editable area
        blue - the amount of blue in RGB color scale for marking the editable area

        In this case, the color deviation is automatically set to the lowest value, which means that only the specific color with no deviations will be marked for editing.

        Returns:
        ChoicesStage to configure the choices count.
      • masked

        public ChoicesStage<R,​E> masked​(String colorHex,
                                              ColorDeviation deviation)
        Parameters:
        colorHex - hexadecimal value of the color that indicates the editable areas
        deviation - ColorDeviation level of deviation - the similarity of the colors that should be marked as editable
        Returns:
        ChoicesStage to configure the choices count.
      • masked

        public ChoicesStage<R,​E> masked​(String colorHex)
        Parameters:
        colorHex - hexadecimal value of the color that indicates the editable areas

        In this case, the color deviation is automatically set to the lowest value, which means that only the specific color with no deviations will be marked for editing.

        Returns:
        ChoicesStage to configure the choices count.
      • smallTransparency

        public ChoicesStage<R,​E> smallTransparency()
        This choice is almost the same as unmasked, but will handle more shades of white expanding the editable areas in comparison to the other option
        Returns:
        ChoicesStage to configure the choices count.
      • hasAlphaChannel

        protected boolean hasAlphaChannel​(BufferedImage image)
      • resetImageWithAlpha

        protected void resetImageWithAlpha​(BufferedImage image,
                                           int alphaZeroHex,
                                           double deviation)