Enrollment 28.2.0
Loading...
Searching...
No Matches

Contains image operations. More...

Collaboration diagram for Image:

Classes

class  Image
 Image representation. More...
class  Image::ImageResampler
 Image resampler for DPI-change operations, including upsampling and downsampling. More...
class  Image::BicubicImageResampler
 Image resampler for DPI-change operations, including upsampling and downsampling using bicubic interpolation resampling algorithm. More...
class  Image::AreaImageResampler
 Image resampler for DPI-change operations, including upsampling and downsampling using area interpolation resampling algorithm. More...
class  Image::NISTImageResampler
 Image resampler for DPI-change operations, including upsampling and downsampling using NIST-compliant resampling algorithm provided by NFIR library. More...
class  ImageDpi
 Image DPI. More...
class  RawImage
 Contains plain image data. More...
class  ImageDimensions
 It holds width and height of Image. More...
class  Point
 It holds X and Y coordinates of point. More...
class  Rectangle
 It holds rectangle vertexes, width, height. More...
class  Line
 It holds line points. More...
class  Circle
 It holds circle dimensions. More...
class  Polygon
 It holds polygon points. More...
class  RGB
 It holds RGB colors. More...
class  RGBA
 It holds RGB color with transparency. More...
class  Colors
 It holds color literals. More...
class  ImageEncoderVisitor
 The class is used to visit concrete encoder to get concrete data. More...
class  ImageEncoder
 Interface for image formatting converting to ImageType. More...
class  SupportedImageEncoder
 Encodes raw images into specified supported format, It is used as based class for all supported formats. More...
class  BmpImageEncoder
 Converts image type ImageType::BMP. More...
class  PngImageEncoder
 Converts image type ImageType::PNG. More...
class  JpgImageEncoder
 Converts image type ImageType::JPG. More...
class  TiffImageEncoder
 Converts image type ImageType::TIFF. More...
class  Jp2ImageEncoder
 Converts image type ImageType::JPG2000. More...
class  WebpImageEncoder
 Converts image type ImageType::WEBP. More...
class  WsqImageEncoder
 Converts image type ImageType::WSQ. More...
class  IRawImageEncoder
 Saves RawImage image to memory. More...
class  ImageSaver
 Interface for image saving. More...
class  ImageFileSaver
 Saves image to file. More...
class  ImageException
 Exception for image processing. More...
class  GlobalImageExecutor
 Holds instance of ImageExecutor. More...
class  ImageMaskConfiguration
 Configuration parameters for image masking operations, including mask type, and color. More...
class  ImageMasker
 Interface for image masking operations. More...
class  ImageMask
 Defines the interface for applying mask to the image with a masker. More...
class  CircleImageMask
 Represents an image mask in the shape of a circle. More...
class  PolygonImageMask
 Represents an image mask defined by a polygonal shape. More...
class  ImageShapeAttributes
 It holds shape attributes such as color and line width. More...
class  Shapes
 It holds shape attributes literals. More...
class  ImageShapeDrawer
 It is used by ImageShape to draw its shape. More...
class  ImageShape
 Any type of shape that wants to be drawn. More...
class  RectangleShape
 It holds rectangle and draws it. More...
class  RectanglesShape
 It holds rectangles and draws it as one shape. More...
class  CircleShape
 It holds circle and draws it. More...
class  LineShape
 It holds line and draws it. More...
class  ImageType
 It contains all supported image types. More...

Typedefs

using ImageDimension = unsigned int
 Image dimension.
using ImageHeight = ImageDimension
 Image Height.
using ImageWidth = ImageDimension
 Image Width.
using X = int
 X coordinate.
using Y = int
 Y coordinate.
using Angle = float
 Angle in degrees.
using Radius = unsigned int
 Radius.

Enumerations

enum class  ImageMaskType : uint8_t { OUTSIDE = 0 , INSIDE = 1 }
 Defines the polygon mask application area in image processing. More...
enum class  ImageBlurType : uint8_t { NO_BORDER_BLURRING = 0 , ISO_19794_BORDER_BLURRING = 1 }
 Defines the type of border blurring applied to an image. More...

Detailed Description

Contains image operations.

Overview

Contains image operations. Supported formats are

  • BMP - Raster graphics image file format developed by Microsoft. [18]
  • PNG - PNG supports palette-based images (with palettes of 24-bit RGB or 32-bit RGBA colors), grayscale images (with or without an alpha channel for transparency), and full-color non-palette-based RGB or RGBA images. [14]
  • WSQ - WSQ (Wavelet Scalar Quantization), also known as FBI Print Format, is a raster image file format used for storing images of prints. It uses lossy wavelet compression, and supports only grayscale images.
  • IRAW - The format is IRAW (4 bytes), width (4 bytes, big endian unsigned int), height (4 bytes, big endian unsigned int), dpi (4 bytes, big endian unsigned int), type (4 bytes, big endian unsigned int), data.
  • JPG - JPEG is a commonly used method of lossy compression for digital images, particularly for those images produced by digital photography. The degree of compression can be adjusted, allowing a selectable tradeoff between storage size and image quality. [12]
  • TIFF - TIF is an image file format for storing raster graphics images, popular among graphic artists, the publishing industry, and photographers. [15]
  • JPG2000 - JPEG 2000 (JP2) is an image compression standard and coding system. It was developed from 1997 to 2000 by a Joint Photographic Experts Group committee with the intention of superseding their original JPEG standard (created in 1992) [13]
  • WEBP - It is intended as a replacement for JPEG, PNG, and GIF file formats. It supports both lossy and lossless compression as well as animation and alpha transparency. [16]

The rest library functionality uses Image class as abstraction of supported image formats. The library extension points are

Reading image

Function Image::Decode is used to create Image object. It automatically detects image type. For supported types see ImageType. On error the function will throw exception, e.g. for not supported ImageType.

  • c++
    auto png = Image::Decode(BinaryFile::ReadAll("assets/color.png"));
    auto bmp = Image::Decode(BinaryFile::ReadAll("assets/color.bmp"));
    auto wsq = Image::Decode(BinaryFile::ReadAll("assets/color.wsq"));
    auto raw = Image::Decode(BinaryFile::ReadAll("assets/color.iraw"));
    auto jpg = Image::Decode(BinaryFile::ReadAll("assets/color.jpg"));
    auto jp2 = Image::Decode(BinaryFile::ReadAll("assets/color.jp2"));
    auto webp = Image::Decode(BinaryFile::ReadAll("assets/color.webp"));
    auto tiff = Image::Decode(BinaryFile::ReadAll("assets/color.tiff"));
  • java
    Image png = Image.Decode(BinaryFile.ReadAll("assets/color.png"));
    Image wsq = Image.Decode(BinaryFile.ReadAll("assets/color.wsq"));
    Image bmp = Image.Decode(BinaryFile.ReadAll("assets/color.bmp"));
    Image raw = Image.Decode(BinaryFile.ReadAll("assets/color.iraw"));
    Image jpg = Image.Decode(BinaryFile.ReadAll("assets/color.jpg"));
    Image jp2 = Image.Decode(BinaryFile.ReadAll("assets/color.jp2"));
    Image tiff = Image.Decode(BinaryFile.ReadAll("assets/color.tiff"));
    Image webp = Image.Decode(BinaryFile.ReadAll("assets/color.webp"));
  • csharp
    Image png = Image.Decode(BinaryFile.ReadAll("assets/color.png"));
    Image wsq = Image.Decode(BinaryFile.ReadAll("assets/color.wsq"));
    Image bmp = Image.Decode(BinaryFile.ReadAll("assets/color.bmp"));
    Image raw = Image.Decode(BinaryFile.ReadAll("assets/color.iraw"));
    Image jpg = Image.Decode(BinaryFile.ReadAll("assets/color.jpg"));
    Image jp2 = Image.Decode(BinaryFile.ReadAll("assets/color.jp2"));
    Image tiff = Image.Decode(BinaryFile.ReadAll("assets/color.tiff"));
    Image webp = Image.Decode(BinaryFile.ReadAll("assets/color.webp"));

Function Image::DecodeRawImage is used to create Image object from provided grayscale/BGR/BGRA data.

  • c++
    const RawImage grayscale = {
    3, 2, ImageDpi{ 500 }, RawImage::GRAYSCALE, { 0, 30, 40, 255, 15, 128 }
    };
    auto png = Image::DecodeRawImage(grayscale);
  • java
    RawImage grayscale = new RawImage(3, 2, new ImageDpi(500),
    RawImage.Type.GRAYSCALE,
    new Bytes(new byte[] { 0, 30, 40, -1, 15, -128 }));
    Image img = Image.DecodeRawImage(grayscale);
  • csharp
    RawImage grayscale =
    new RawImage(3, 2, new ImageDpi(500), RawImage.Type.GRAYSCALE,
    new Bytes(new byte[] { 0, 30, 40, 255, 15, 128 }));
    Image img = Image.DecodeRawImage(grayscale);

Writing/Converting image

Function Image::EncodeIn is used to convert image via ImageEncoder.

  • c++
    auto png = Image::Decode(BinaryFile::ReadAll("assets/color.png"));
    // Use encoder of original format
    std::ignore = png->EncodeIn(*png->OriginalEncoder());
    // convert to other format and save by BinaryFile
    BmpImageEncoder bmpEncoder;
    auto encoded = png->EncodeIn(bmpEncoder);
    BinaryFile::WriteAll("output/color_converted.bmp", encoded);
    // convert and save in ImageFileSaver
    ImageFileSaver wsqFileSaver("output/color_converted.wsq");
    png->SaveIn(wsqFileSaver);
    // convert and save in file, with convenient function
    png->SaveAs("output/color_converted.iraw");
    png->SaveAs("output/color_converted.jpg");
    #ifndef __ANDROID__
    // Encoding to jp2 is not working on Android,
    // due to disabled support of filesystem in OpenCV
    png->SaveAs("output/color_converted.jp2");
    #endif
    png->SaveAs("output/color_converted.tiff");
    png->SaveAs("output/color_converted.webp");
  • java
    Image png = Image.Decode(BinaryFile.ReadAll("assets/color.png"));
    // Use encoder of original format
    // convert to other format and use BinaryFile to save
    BmpImageEncoder bmpEncoder = new BmpImageEncoder();
    Bytes encoded = png.EncodeIn(bmpEncoder);
    BinaryFile.WriteAll("output/color_converted.bmp", encoded);
    // Use ImageFileSaver to convert and write
    ImageFileSaver wsqSaver = new ImageFileSaver("output/color_converted.wsq");
    png.SaveIn(wsqSaver);
    // convert and save in file, with convenient function
    png.SaveAs("output/color_converted.iraw");
    png.SaveAs("output/color_converted.jpg");
    if (!"The Android Project".equals(
    System.getProperty("java.specification.vendor"))) {
    // Encoding to jp2 is not working on Android,
    // due to disabled support of filesystem in OpenCV
    png.SaveAs("output/color_converted.jp2");
    }
    png.SaveAs("output/color_converted.tiff");
    png.SaveAs("output/color_converted.webp");
  • csharp
    Image png = Image.Decode(BinaryFile.ReadAll("assets/color.png"));
    // Use encoder of original format
    // convert to other formats and use BinaryFile to write
    BmpImageEncoder bmpEncoder = new BmpImageEncoder();
    Bytes encoded = png.EncodeIn(bmpEncoder);
    BinaryFile.WriteAll("output/color_converted.bmp", encoded);
    // Use ImageFileSaver to convert and write
    ImageFileSaver wsqSaver = new ImageFileSaver("output/color_converted.wsq");
    png.SaveIn(wsqSaver);
    // convert and save in file, with convenient function
    png.SaveAs("output/color_converted.iraw");
    png.SaveAs("output/color_converted.jpg");
    png.SaveAs("output/color_converted.jp2");
    png.SaveAs("output/color_converted.tiff");
    png.SaveAs("output/color_converted.webp");

Resize

Functions Image::Resize and Image::ResizeToMaxDimension are used to resize image.

  • c++
    auto img = Image::Decode(BinaryFile::ReadAll("assets/color.png"));
    auto resized = img->Resize(0.5F);
    auto resizedToMaxDimension = img->ResizeToMaxDimension(img->Width() / 2);
    resized->SaveAs("output/color_resized_half.png");
    resizedToMaxDimension->SaveAs("output/color_resized_half_dimension.png");
  • java
    Image img = Image.Decode(BinaryFile.ReadAll("assets/color.png"));
    Image resized = img.Resize(0.5F);
    Image resizedToMaxDimension = img.ResizeToMaxDimension(img.Width() / 2);
    resized.SaveAs("output/color_resized_half.png");
    resizedToMaxDimension.SaveAs("output/color_resized_half_dimension.png");
  • csharp
    Image img = Image.Decode(BinaryFile.ReadAll("assets/color.png"));
    Image resized = img.Resize(0.5F);
    Image resizedToMaxDimension = img.ResizeToMaxDimension(img.Width() / 2);
    resized.SaveAs("output/color_resized_half.png");
    resizedToMaxDimension.SaveAs("output/color_resized_half_dimension.png");
Resize input
Resize output

Change DPI

Function Image::ChangeDpiTo is used to change DPI of image. The original image is resized with factor targetDPI/originalDPI.

  • c++
    auto img = Image::Decode(BinaryFile::ReadAll("assets/color.png"), 1000);
    auto changed = img->ChangeDpiTo(ImageDpi(500));
    changed->SaveAs("output/color_dpi_500.png");
  • java
    Image img = Image.Decode(BinaryFile.ReadAll("assets/color.png"), 1000);
    Image changed = img.ChangeDpiTo(new ImageDpi(500));
    changed.SaveAs("output/color_dpi_500.png");
  • csharp
    Image img = Image.Decode(BinaryFile.ReadAll("assets/color.png"), 1000);
    Image changed = img.ChangeDpiTo(new ImageDpi(500));
    changed.SaveAs("output/color_dpi_500.png");
DPI change input
DPI change output

Draw shape

For each shape function Image::DrawShape creates new Image to keep current instance immutable. If more shapes need to be drawn in one image, then implement new class with base ImageShape e.g RectanglesShape. Then it is possible to draw into image via ImageShapeDrawer.

Draw input
Draw rectangle output
  • c++
    auto img = Image::Decode(BinaryFile::ReadAll("assets/color.png"));
    const Rectangle rectangle{ { 37, 20 }, { 79, -11 }, { 109, 29 }, { 67, 60 } };
    const RectangleShape shape(rectangle, Shapes::InnoBlue);
    auto drawnImage = img->DrawShape(shape);
    drawnImage->SaveAs("output/color_drawn.bmp");
  • java
    Image img = Image.Decode(BinaryFile.ReadAll("assets/color.png"));
    Rectangle rectangle = new Rectangle(new Point(37, 20), new Point(79, -11),
    new Point(109, 29), new Point(67, 60));
    RectangleShape shape = new RectangleShape(rectangle, Shapes.InnoBlue);
    Image drawnImage = img.DrawShape(shape);
    drawnImage.SaveAs("output/color_drawn.bmp");
  • csharp
    Image img = Image.Decode(BinaryFile.ReadAll("assets/color.png"));
    Rectangle rectangle = new Rectangle(new Point(37, 20), new Point(79, -11),
    new Point(109, 29), new Point(67, 60));
    RectangleShape shape = new RectangleShape(rectangle, Shapes.InnoBlue);
    Image drawnImage = img.DrawShape(shape);
    drawnImage.SaveAs("output/color_drawn.bmp");
Draw circle output
  • c++
    auto img = Image::Decode(BinaryFile::ReadAll("assets/color.png"));
    const CircleShape shape(Circle{ { 30, 45 }, 10 }, Shapes::InnoBlue);
    auto drawnImage = img->DrawShape(shape);
    drawnImage->SaveAs("output/color_drawn_circle.bmp");
  • java
    Image img = Image.Decode(BinaryFile.ReadAll("assets/color.png"));
    CircleShape shape = new CircleShape(
    new Circle(new Point(30, 45), 10), Shapes.InnoBlue);
    Image drawnImage = img.DrawShape(shape);
    drawnImage.SaveAs("output/color_drawn_circle.bmp");
  • csharp
    Image img = Image.Decode(BinaryFile.ReadAll("assets/color.png"));
    CircleShape shape =
    new CircleShape(new Circle(new Point(30, 45), 10), Shapes.InnoBlue);
    Image drawnImage = img.DrawShape(shape);
    drawnImage.SaveAs("output/color_drawn_circle.bmp");

Draw custom shape output
  • c++
    // Define custom shape
    class CustomShape : public ImageShape
    {
    public:
    void DrawIn(ImageShapeDrawer& drawer) const final
    {
    // Draw custom shapes
    drawer.DrawLine({ { 0, 0 }, { 100, 100 } }, { { { 0, 255, 0 }, 50 }, 5 });
    drawer.DrawCircle({ { 0, 0 }, 30 }, { { { 255, 0, 0 }, 100 }, 5 });
    }
    };
    static void DrawCustomShapeInImage()
    {
    auto img = Image::Decode(BinaryFile::ReadAll("assets/color.png"));
    const CustomShape customShape{};
    auto drawnImage = img->DrawShape(customShape);
    drawnImage->SaveAs("output/color_custom_drawn.png");
    }
  • java
    // Define custom shape
    public class CustomShape extends ImageShape {
    @Override
    public void DrawIn(ImageShapeDrawer drawer) {
    // Draw custom shapes
    ImageShapeAttributes attr = new ImageShapeAttributes();
    attr.setRgba(new RGBA((short) 0, (short) 255, (short) 0, (short) 50));
    attr.setThickness((short) 5);
    drawer.DrawLine(new Line(new Point(0, 0), new Point(100, 100)), attr);
    attr.setRgba(new RGBA((short) 255, (short) 0, (short) 0, (short) 100));
    drawer.DrawCircle(new Circle(new Point(0, 0), 30), attr);
    }
    };
    public void DrawCustomShapeInImage() {
    Image img = Image.Decode(BinaryFile.ReadAll("assets/color.png"));
    CustomShape shape = new CustomShape();
    Image drawnImage = img.DrawShape(shape);
    drawnImage.SaveAs("output/color_custom_drawn.png");
    }
  • csharp
    // Define custom shape
    public class CustomShape : ImageShape
    {
    public override void DrawIn(ImageShapeDrawer drawer)
    {
    // Draw custom shapes
    ImageShapeAttributes attr = new ImageShapeAttributes();
    attr.rgba = new RGBA(0, 255, 0, 50);
    attr.thickness = 5;
    drawer.DrawLine(new Line(new Point(0, 0), new Point(100, 100)), attr);
    attr.rgba = new RGBA(255, 0, 0, 100);
    drawer.DrawCircle(new Circle(new Point(0, 0), 30), attr);
    }
    };
    public void DrawCustomShapeInImage()
    {
    Image img = Image.Decode(BinaryFile.ReadAll("assets/color.png"));
    CustomShape shape = new CustomShape();
    Image drawnImage = img.DrawShape(shape);
    drawnImage.SaveAs("output/color_custom_drawn.png");
    }

Mask shape

For each shape function Image::MaskImageBy creates new Image to keep current instance immutable. If more shapes need to be masked in one image, then use custom mask class extending ImageMask where you can add any combination of PolygonImageMask and CircleImageMask. The each mask shape has ImageMaskAttributes

  • masked area
    • INSIDE - Mask is applied to the region inside the shape, preserving the area outside.
    • OUTSIDE - Mask is applied to the region outside the shape, preserving the area inside.
  • blurring mask border after applying mask
  • c++
    const auto img = Image::Decode(BinaryFile::ReadAll("assets/color.png"));
    const Circle circle{ { 60, 60 }, 20 };
    // Mask image by circle - inside
    auto insideMask = CircleImageMask(
    circle,
    ImageMaskConfiguration{ ImageMaskType::INSIDE, Colors::InnoBlue },
    auto maskedInside = img->MaskImageBy(insideMask);
    maskedInside->SaveAs("output/masked_circle_inside.png");
    // Mask image by circle - outside
    auto outsideMask = CircleImageMask(
    circle,
    ImageMaskConfiguration{ ImageMaskType::OUTSIDE, Colors::InnoBlue },
    auto maskedOutside = img->MaskImageBy(outsideMask);
    maskedOutside->SaveAs("output/masked_circle_outside.png");
  • java
    Image img = Image.Decode(BinaryFile.ReadAll("assets/color.png"));
    Circle circle = new Circle(new Point(60, 60), 20);
    // Mask image by circle - inside
    CircleImageMask insideMask = new CircleImageMask(circle,
    new ImageMaskConfiguration(ImageMaskType.INSIDE, Colors.InnoBlue),
    ImageBlurType.NO_BORDER_BLURRING);
    Image maskedInside = img.MaskImageBy(insideMask);
    maskedInside.SaveAs("output/masked_circle_inside.png");
    // Mask image by circle - outside
    CircleImageMask outsideMask = new CircleImageMask(circle,
    new ImageMaskConfiguration(ImageMaskType.OUTSIDE, Colors.InnoBlue),
    ImageBlurType.NO_BORDER_BLURRING);
    Image maskedOutside = img.MaskImageBy(outsideMask);
    maskedOutside.SaveAs("output/masked_circle_outside.png");
  • csharp
    Image img = Image.Decode(BinaryFile.ReadAll("assets/color.png"));
    var circle = new Circle(new Point(60, 60), 20);
    // Mask image by circle - inside
    var insideMask = new CircleImageMask(
    circle, new ImageMaskConfiguration(ImageMaskType.INSIDE, Colors.InnoBlue),
    ImageBlurType.NO_BORDER_BLURRING);
    var maskedInside = img.MaskImageBy(insideMask);
    maskedInside.SaveAs("output/masked_circle_inside.png");
    // Mask image by circle - outside
    var outsideMask = new CircleImageMask(
    circle, new ImageMaskConfiguration(ImageMaskType.OUTSIDE, Colors.InnoBlue),
    ImageBlurType.NO_BORDER_BLURRING);
    var maskedOutside = img.MaskImageBy(outsideMask);
    maskedOutside.SaveAs("output/masked_circle_outside.png");
Circle masked inside
Circle masked outside
  • c++
    const auto img = Image::Decode(BinaryFile::ReadAll("assets/color.png"));
    const Polygon polygon{ { { 50, 20 }, { 80, 80 }, { 20, 80 } } };
    // Mask image by polygon - inside
    auto insideMask = PolygonImageMask(
    polygon,
    ImageMaskConfiguration{ ImageMaskType::INSIDE, Colors::InnoBlue },
    auto maskedInside = img->MaskImageBy(insideMask);
    maskedInside->SaveAs("output/masked_polygon_inside.png");
    // Mask image by polygon - outside
    auto outsideMask = PolygonImageMask(
    polygon,
    ImageMaskConfiguration{ ImageMaskType::OUTSIDE, Colors::InnoBlue },
    auto maskedOutside = img->MaskImageBy(outsideMask);
    maskedOutside->SaveAs("output/masked_polygon_outside.png");
  • java
    Image img = Image.Decode(BinaryFile.ReadAll("assets/color.png"));
    Polygon polygon = new Polygon(new Points(new ArrayList<>(
    Arrays.asList(new Point(50, 20), new Point(80, 80), new Point(20, 80)))));
    // Mask image by polygon - inside
    PolygonImageMask insideMask = new PolygonImageMask(polygon,
    new ImageMaskConfiguration(ImageMaskType.INSIDE, Colors.InnoBlue),
    ImageBlurType.ISO_19794_BORDER_BLURRING);
    Image maskedInside = img.MaskImageBy(insideMask);
    maskedInside.SaveAs("output/masked_polygon_inside.png");
    // Mask image by polygon - outside
    PolygonImageMask outsideMask = new PolygonImageMask(polygon,
    new ImageMaskConfiguration(ImageMaskType.OUTSIDE, Colors.InnoBlue),
    ImageBlurType.ISO_19794_BORDER_BLURRING);
    Image maskedOutside = img.MaskImageBy(outsideMask);
    maskedOutside.SaveAs("output/masked_polygon_outside.png");
  • csharp
    var img = Image.Decode(BinaryFile.ReadAll("assets/color.png"));
    var polygon = new Polygon(new Points(
    new List<Point> { new Point(50, 20), new Point(80, 80), new Point(20, 80) }));
    // Mask image by polygon - inside
    var insideMask = new PolygonImageMask(
    polygon, new ImageMaskConfiguration(ImageMaskType.INSIDE, Colors.InnoBlue),
    ImageBlurType.ISO_19794_BORDER_BLURRING);
    var maskedInside = img.MaskImageBy(insideMask);
    maskedInside.SaveAs("output/masked_polygon_inside.png");
    // Mask image by polygon - outside
    var outsideMask = new PolygonImageMask(
    polygon, new ImageMaskConfiguration(ImageMaskType.OUTSIDE, Colors.InnoBlue),
    ImageBlurType.ISO_19794_BORDER_BLURRING);
    var maskedOutside = img.MaskImageBy(outsideMask);
    maskedOutside.SaveAs("output/masked_polygon_outside.png");
Polygon masked and blurred inside
Polygon masked and blurred outside

  • c++
    // Define custom mask
    class CustomMask : public ImageMask
    {
    public:
    void MaskWith(ImageMasker& masker) const override
    {
    // Create shapes for the custom mask
    const Polygon polygon{ { { 50, 20 }, { 80, 80 }, { 20, 80 } } };
    const Circle circle{ { 60, 60 }, 20 };
    // Define custom mask behaviour
    masker.MaskCircle(
    circle, ImageMaskConfiguration{ ImageMaskType::INSIDE, Colors::White });
    masker.MaskPolygon(
    polygon,
    ImageMaskConfiguration{ ImageMaskType::OUTSIDE, Colors::InnoBlue });
    }
    };
    static void MaskImageWithCombination()
    {
    const auto img = Image::Decode(BinaryFile::ReadAll("assets/color.png"));
    const CustomMask mask;
    auto maskedImage = img->MaskImageBy(mask);
    maskedImage->SaveAs("output/masked_combination.png");
    }
  • java
    // Define custom mask
    public class CustomMask extends ImageMask {
    @Override
    public void MaskWith(ImageMasker masker) {
    // Create shapes for the custom mask
    Polygon polygon = new Polygon(new Points(Arrays.asList(
    new Point(50, 20), new Point(80, 80), new Point(20, 80))));
    Circle circle = new Circle(new Point(60, 60), 20);
    // Define custom mask behaviour
    masker.MaskCircle(circle,
    new ImageMaskConfiguration(ImageMaskType.INSIDE, Colors.White));
    masker.MaskPolygon(polygon,
    new ImageMaskConfiguration(ImageMaskType.OUTSIDE, Colors.InnoBlue));
    masker.AddToBlur(polygon, ImageMaskType.OUTSIDE);
    masker.ApplyBlur(ImageBlurType.ISO_19794_BORDER_BLURRING);
    }
    };
    public void MaskImageWithCombination() {
    Image img = Image.Decode(BinaryFile.ReadAll("assets/color.png"));
    CustomMask mask = new CustomMask();
    Image maskedImage = img.MaskImageBy(mask);
    maskedImage.SaveAs("output/masked_combination.png");
    }
  • csharp
    // Define custom mask
    public class CustomMask : ImageMask
    {
    public override void MaskWith(ImageMasker masker)
    {
    // Create shapes for the custom mask
    var polygon = new Polygon(
    new Points(new List<Point> { new Point(50, 20), new Point(80, 80),
    new Point(20, 80) }));
    var circle = new Circle(new Point(60, 60), 20);
    // Define custom mask behaviour
    masker.MaskCircle(
    circle, new ImageMaskConfiguration(ImageMaskType.INSIDE, Colors.White));
    masker.MaskPolygon(polygon, new ImageMaskConfiguration(ImageMaskType.OUTSIDE,
    Colors.InnoBlue));
    masker.AddToBlur(polygon, ImageMaskType.OUTSIDE);
    masker.ApplyBlur(ImageBlurType.ISO_19794_BORDER_BLURRING);
    }
    }
    public void MaskImageWithCombination()
    {
    var img = Image.Decode(BinaryFile.ReadAll("assets/color.png"));
    var mask = new CustomMask();
    var maskedImage = img.MaskImageBy(mask);
    maskedImage.SaveAs("output/masked_combination.png");
    }
Masked combination

Crop aligned rectangle

Use function Image::CropAlignedRectangle to crop and align rectangle. It Crop rectangle and align given top left rectangle point to coordinates [0,0] in new image.

Crop aligned rectangle input
Crop aligned rectangle output
  • c++
    auto img = Image::Decode(BinaryFile::ReadAll("assets/color.png"));
    // The points MUST be ordered as top left, top right, bottom right, bottom left
    // the rectangle will be aligned to transform top left to coordinate [0,0] in new
    // image
    const Rectangle rectangle{ { 79, -11 }, { 109, 29 }, { 67, 60 }, { 37, 20 } };
    auto copiedImage = img->CropAlignedRectangle(rectangle);
    copiedImage->SaveAs("output/color_copied_align.bmp");
  • java
    Image img = Image.Decode(BinaryFile.ReadAll("assets/color.png"));
    // The points MUST be ordered as top left, top right, bottom right, bottom left
    // the rectangle will be aligned to transform top left to coordinate [0,0] in
    // new image
    Rectangle rectangle = new Rectangle(new Point(79, -11), new Point(109, 29),
    new Point(67, 60), new Point(37, 20));
    Image copiedImage = img.CropAlignedRectangle(rectangle);
    copiedImage.SaveAs("output/color_copied_align.bmp");
  • csharp
    Image img = Image.Decode(BinaryFile.ReadAll("assets/color.png"));
    // The points MUST be ordered as top left, top right, bottom right, bottom left
    // the rectangle will be aligned to transform top left to coordinate [0,0] in new
    // image
    Rectangle rectangle = new Rectangle(new Point(79, -11), new Point(109, 29),
    new Point(67, 60), new Point(37, 20));
    Image copiedImage = img.CropAlignedRectangle(rectangle);
    copiedImage.SaveAs("output/color_copied_align.bmp");

Crop rectangle

Use function Image::CropRectangle to crop rectangle. It Crops a rectangle from the image, using a white background for any extra space.

Crop rectangle input
Crop rectangle output
  • c++
    auto img = Image::Decode(BinaryFile::ReadAll("assets/color.png"));
    const Rectangle rectangle{ { 37, 20 }, { 79, -11 }, { 109, 29 }, { 67, 60 } };
    auto copiedImage = img->CropRectangle(rectangle, Colors::InnoBlue);
    copiedImage->SaveAs("output/color_copied.bmp");
  • java
    Image img = Image.Decode(BinaryFile.ReadAll("assets/color.png"));
    Rectangle rectangle = new Rectangle(new Point(37, 20), new Point(79, -11),
    new Point(109, 29), new Point(67, 60));
    Image copiedImage = img.CropRectangle(rectangle, Colors.InnoBlue);
    copiedImage.SaveAs("output/color_copied.bmp");
  • csharp
    Image img = Image.Decode(BinaryFile.ReadAll("assets/color.png"));
    Rectangle rectangle = new Rectangle(new Point(37, 20), new Point(79, -11),
    new Point(109, 29), new Point(67, 60));
    Image copiedImage = img.CropRectangle(rectangle, Colors.InnoBlue);
    copiedImage.SaveAs("output/color_copied.bmp");

Crop circle

For given circle function Image::CropCircle cut circle from image.

Crop circle input
Crop circle output
  • c++
    auto img = Image::Decode(BinaryFile::ReadAll("assets/color.png"));
    auto copiedImage = img->CropCircle(Circle{ { 30, 45 }, 10 });
    copiedImage->SaveAs("output/color_copied_circle.bmp");
  • java
    Image img = Image.Decode(BinaryFile.ReadAll("assets/color.png"));
    Image copiedImage = img.CropCircle(new Circle(new Point(30, 45), 10));
    copiedImage.SaveAs("output/color_copied_circle.bmp");
  • csharp
    Image img = Image.Decode(BinaryFile.ReadAll("assets/color.png"));
    Image copiedImage = img.CropCircle(new Circle(new Point(30, 45), 10));
    copiedImage.SaveAs("output/color_copied_circle.bmp");

Intersection

Library provides functions Image::RectangleIntersection and Image::CircleIntersection that calculates intersection type with Image.

  • Partial - The Object and Image has intersection.
Partial intersection
  • Inside - Object is fully in Image.
Inside intersection
  • Outside - Image is fully in Object.
Outside intersection
  • Same - Image has same dimensions and vertices coordinates as Object.
Same intersection
  • No - Image and Object has no intersection.
No intersection

Enumeration Type Documentation

◆ ImageBlurType

enum class ImageBlurType : uint8_t
strong

Defines the type of border blurring applied to an image.

Enumerator
NO_BORDER_BLURRING 

No border blurring is applied.

ISO_19794_BORDER_BLURRING 

Applies border blurring according to ISO/IEC 19794-6 standard.

The borders of mask region is smoothed by low-pass filtering. Each image pixel, whose centred 7 x 7 neighbourhood contains at least one mask pixel, is replaced by a weighted sum of a 7 x 7 binomial kernel. The coefficients of this kernel are defined by the outer product, [7] K = 1/(64x64) UUT where: U = [ 1 6 15 20 15 6 1 ]T

◆ ImageMaskType

enum class ImageMaskType : uint8_t
strong

Defines the polygon mask application area in image processing.

Enumerator
OUTSIDE 

Mask is applied to the region outside the shape, preserving the area inside.

INSIDE 

Mask is applied to the region inside the shape, preserving the area outside.