Class SDImage


  • public class SDImage
    extends SDOps
    • Constructor Detail

      • SDImage

        public SDImage​(SameDiff sameDiff)
    • Method Detail

      • cropAndResize

        public SDVariable cropAndResize​(SDVariable image,
                                        SDVariable cropBoxes,
                                        SDVariable boxIndices,
                                        SDVariable cropOutSize,
                                        double extrapolationValue)
        Given an input image and some crop boxes, extract out the image subsets and resize them to the specified size.
        Parameters:
        image - Input image, with shape [batch, height, width, channels] (NUMERIC type)
        cropBoxes - Float32 crop, shape [numBoxes, 4] with values in range 0 to 1 (NUMERIC type)
        boxIndices - Indices: which image (index to dimension 0) the cropBoxes belong to. Rank 1, shape [numBoxes] (NUMERIC type)
        cropOutSize - Output size for the images - int32, rank 1 with values [outHeight, outWidth] (INT type)
        extrapolationValue - Used for extrapolation, when applicable. 0.0 should be used for the default
        Returns:
        output Cropped and resized images (NUMERIC type)
      • cropAndResize

        public SDVariable cropAndResize​(String name,
                                        SDVariable image,
                                        SDVariable cropBoxes,
                                        SDVariable boxIndices,
                                        SDVariable cropOutSize,
                                        double extrapolationValue)
        Given an input image and some crop boxes, extract out the image subsets and resize them to the specified size.
        Parameters:
        name - name May be null. Name for the output variable
        image - Input image, with shape [batch, height, width, channels] (NUMERIC type)
        cropBoxes - Float32 crop, shape [numBoxes, 4] with values in range 0 to 1 (NUMERIC type)
        boxIndices - Indices: which image (index to dimension 0) the cropBoxes belong to. Rank 1, shape [numBoxes] (NUMERIC type)
        cropOutSize - Output size for the images - int32, rank 1 with values [outHeight, outWidth] (INT type)
        extrapolationValue - Used for extrapolation, when applicable. 0.0 should be used for the default
        Returns:
        output Cropped and resized images (NUMERIC type)
      • cropAndResize

        public SDVariable cropAndResize​(SDVariable image,
                                        SDVariable cropBoxes,
                                        SDVariable boxIndices,
                                        SDVariable cropOutSize)
        Given an input image and some crop boxes, extract out the image subsets and resize them to the specified size.
        Parameters:
        image - Input image, with shape [batch, height, width, channels] (NUMERIC type)
        cropBoxes - Float32 crop, shape [numBoxes, 4] with values in range 0 to 1 (NUMERIC type)
        boxIndices - Indices: which image (index to dimension 0) the cropBoxes belong to. Rank 1, shape [numBoxes] (NUMERIC type)
        cropOutSize - Output size for the images - int32, rank 1 with values [outHeight, outWidth] (INT type)
        Returns:
        output Cropped and resized images (NUMERIC type)
      • cropAndResize

        public SDVariable cropAndResize​(String name,
                                        SDVariable image,
                                        SDVariable cropBoxes,
                                        SDVariable boxIndices,
                                        SDVariable cropOutSize)
        Given an input image and some crop boxes, extract out the image subsets and resize them to the specified size.
        Parameters:
        name - name May be null. Name for the output variable
        image - Input image, with shape [batch, height, width, channels] (NUMERIC type)
        cropBoxes - Float32 crop, shape [numBoxes, 4] with values in range 0 to 1 (NUMERIC type)
        boxIndices - Indices: which image (index to dimension 0) the cropBoxes belong to. Rank 1, shape [numBoxes] (NUMERIC type)
        cropOutSize - Output size for the images - int32, rank 1 with values [outHeight, outWidth] (INT type)
        Returns:
        output Cropped and resized images (NUMERIC type)
      • adjustContrast

        public SDVariable adjustContrast​(SDVariable in,
                                         double factor)
        Adjusts contrast of RGB or grayscale images.
        Parameters:
        in - images to adjust. 3D shape or higher (NUMERIC type)
        factor - multiplier for adjusting contrast
        Returns:
        output Contrast-adjusted image (NUMERIC type)
      • adjustContrast

        public SDVariable adjustContrast​(String name,
                                         SDVariable in,
                                         double factor)
        Adjusts contrast of RGB or grayscale images.
        Parameters:
        name - name May be null. Name for the output variable
        in - images to adjust. 3D shape or higher (NUMERIC type)
        factor - multiplier for adjusting contrast
        Returns:
        output Contrast-adjusted image (NUMERIC type)
      • adjustHue

        public SDVariable adjustHue​(SDVariable in,
                                    double delta)
        Adjust hue of RGB image
        Parameters:
        in - image as 3D array (NUMERIC type)
        delta - value to add to hue channel
        Returns:
        output adjusted image (NUMERIC type)
      • adjustHue

        public SDVariable adjustHue​(String name,
                                    SDVariable in,
                                    double delta)
        Adjust hue of RGB image
        Parameters:
        name - name May be null. Name for the output variable
        in - image as 3D array (NUMERIC type)
        delta - value to add to hue channel
        Returns:
        output adjusted image (NUMERIC type)
      • adjustSaturation

        public SDVariable adjustSaturation​(SDVariable in,
                                           double factor)
        Adjust saturation of RGB images
        Parameters:
        in - RGB image as 3D array (NUMERIC type)
        factor - factor for saturation
        Returns:
        output adjusted image (NUMERIC type)
      • adjustSaturation

        public SDVariable adjustSaturation​(String name,
                                           SDVariable in,
                                           double factor)
        Adjust saturation of RGB images
        Parameters:
        name - name May be null. Name for the output variable
        in - RGB image as 3D array (NUMERIC type)
        factor - factor for saturation
        Returns:
        output adjusted image (NUMERIC type)
      • extractImagePatches

        public SDVariable extractImagePatches​(SDVariable image,
                                              int[] kSizes,
                                              int[] strides,
                                              int[] rates,
                                              boolean sameMode)
        Given an input image, extract out image patches (of size kSizes - h x w) and place them in the depth dimension.
        Parameters:
        image - Input image to extract image patches from - shape [batch, height, width, channels] (NUMERIC type)
        kSizes - Kernel size - size of the image patches, [height, width] (Size: Exactly(count=2))
        strides - Stride in the input dimension for extracting image patches, [stride_height, stride_width] (Size: Exactly(count=2))
        rates - Usually [1,1]. Equivalent to dilation rate in dilated convolutions - how far apart the output pixels in the patches should be, in the input. A dilation of [a,b] means every ath pixel is taken along the height/rows dimension, and every bth pixel is take along the width/columns dimension (Size: AtLeast(min=0))
        sameMode - Padding algorithm. If true: use Same padding
        Returns:
        output The extracted image patches (NUMERIC type)
      • extractImagePatches

        public SDVariable extractImagePatches​(String name,
                                              SDVariable image,
                                              int[] kSizes,
                                              int[] strides,
                                              int[] rates,
                                              boolean sameMode)
        Given an input image, extract out image patches (of size kSizes - h x w) and place them in the depth dimension.
        Parameters:
        name - name May be null. Name for the output variable
        image - Input image to extract image patches from - shape [batch, height, width, channels] (NUMERIC type)
        kSizes - Kernel size - size of the image patches, [height, width] (Size: Exactly(count=2))
        strides - Stride in the input dimension for extracting image patches, [stride_height, stride_width] (Size: Exactly(count=2))
        rates - Usually [1,1]. Equivalent to dilation rate in dilated convolutions - how far apart the output pixels in the patches should be, in the input. A dilation of [a,b] means every ath pixel is taken along the height/rows dimension, and every bth pixel is take along the width/columns dimension (Size: AtLeast(min=0))
        sameMode - Padding algorithm. If true: use Same padding
        Returns:
        output The extracted image patches (NUMERIC type)
      • hsvToRgb

        public SDVariable hsvToRgb​(SDVariable input)
        Converting image from HSV to RGB format
        Parameters:
        input - 3D image (NUMERIC type)
        Returns:
        output 3D image (NUMERIC type)
      • hsvToRgb

        public SDVariable hsvToRgb​(String name,
                                   SDVariable input)
        Converting image from HSV to RGB format
        Parameters:
        name - name May be null. Name for the output variable
        input - 3D image (NUMERIC type)
        Returns:
        output 3D image (NUMERIC type)
      • imageResize

        public SDVariable imageResize​(SDVariable input,
                                      SDVariable size,
                                      boolean preserveAspectRatio,
                                      boolean antialias,
                                      ImageResizeMethod ImageResizeMethod)
        Resize images to size using the specified method.
        Parameters:
        input - 4D image [NHWC] (NUMERIC type)
        size - new height and width (INT type)
        preserveAspectRatio - Whether to preserve the aspect ratio. If this is set, then images will be resized to a size that fits in size while preserving the aspect ratio of the original image. Scales up the image if size is bigger than the current size of the image. Defaults to False.
        antialias - Whether to use an anti-aliasing filter when downsampling an image
        ImageResizeMethod - ResizeBilinear: Bilinear interpolation. If 'antialias' is true, becomes a hat/tent filter function with radius 1 when downsampling. ResizeLanczos5: Lanczos kernel with radius 5. Very-high-quality filter but may have stronger ringing. ResizeBicubic: Cubic interpolant of Keys. Equivalent to Catmull-Rom kernel. Reasonably good quality and faster than Lanczos3Kernel, particularly when upsampling. ResizeGaussian: Gaussian kernel with radius 3, sigma = 1.5 / 3.0. ResizeNearest: Nearest neighbor interpolation. 'antialias' has no effect when used with nearest neighbor interpolation. ResizeArea: Anti-aliased resampling with area interpolation. 'antialias' has no effect when used with area interpolation; it always anti-aliases. ResizeMitchellcubic: Mitchell-Netravali Cubic non-interpolating filter. For synthetic images (especially those lacking proper prefiltering), less ringing than Keys cubic kernel but less sharp.
        Returns:
        output Output image (NUMERIC type)
      • imageResize

        public SDVariable imageResize​(String name,
                                      SDVariable input,
                                      SDVariable size,
                                      boolean preserveAspectRatio,
                                      boolean antialias,
                                      ImageResizeMethod ImageResizeMethod)
        Resize images to size using the specified method.
        Parameters:
        name - name May be null. Name for the output variable
        input - 4D image [NHWC] (NUMERIC type)
        size - new height and width (INT type)
        preserveAspectRatio - Whether to preserve the aspect ratio. If this is set, then images will be resized to a size that fits in size while preserving the aspect ratio of the original image. Scales up the image if size is bigger than the current size of the image. Defaults to False.
        antialias - Whether to use an anti-aliasing filter when downsampling an image
        ImageResizeMethod - ResizeBilinear: Bilinear interpolation. If 'antialias' is true, becomes a hat/tent filter function with radius 1 when downsampling. ResizeLanczos5: Lanczos kernel with radius 5. Very-high-quality filter but may have stronger ringing. ResizeBicubic: Cubic interpolant of Keys. Equivalent to Catmull-Rom kernel. Reasonably good quality and faster than Lanczos3Kernel, particularly when upsampling. ResizeGaussian: Gaussian kernel with radius 3, sigma = 1.5 / 3.0. ResizeNearest: Nearest neighbor interpolation. 'antialias' has no effect when used with nearest neighbor interpolation. ResizeArea: Anti-aliased resampling with area interpolation. 'antialias' has no effect when used with area interpolation; it always anti-aliases. ResizeMitchellcubic: Mitchell-Netravali Cubic non-interpolating filter. For synthetic images (especially those lacking proper prefiltering), less ringing than Keys cubic kernel but less sharp.
        Returns:
        output Output image (NUMERIC type)
      • imageResize

        public SDVariable imageResize​(SDVariable input,
                                      SDVariable size,
                                      ImageResizeMethod ImageResizeMethod)
        Resize images to size using the specified method.
        Parameters:
        input - 4D image [NHWC] (NUMERIC type)
        size - new height and width (INT type)
        ImageResizeMethod - ResizeBilinear: Bilinear interpolation. If 'antialias' is true, becomes a hat/tent filter function with radius 1 when downsampling. ResizeLanczos5: Lanczos kernel with radius 5. Very-high-quality filter but may have stronger ringing. ResizeBicubic: Cubic interpolant of Keys. Equivalent to Catmull-Rom kernel. Reasonably good quality and faster than Lanczos3Kernel, particularly when upsampling. ResizeGaussian: Gaussian kernel with radius 3, sigma = 1.5 / 3.0. ResizeNearest: Nearest neighbor interpolation. 'antialias' has no effect when used with nearest neighbor interpolation. ResizeArea: Anti-aliased resampling with area interpolation. 'antialias' has no effect when used with area interpolation; it always anti-aliases. ResizeMitchellcubic: Mitchell-Netravali Cubic non-interpolating filter. For synthetic images (especially those lacking proper prefiltering), less ringing than Keys cubic kernel but less sharp.
        Returns:
        output Output image (NUMERIC type)
      • imageResize

        public SDVariable imageResize​(String name,
                                      SDVariable input,
                                      SDVariable size,
                                      ImageResizeMethod ImageResizeMethod)
        Resize images to size using the specified method.
        Parameters:
        name - name May be null. Name for the output variable
        input - 4D image [NHWC] (NUMERIC type)
        size - new height and width (INT type)
        ImageResizeMethod - ResizeBilinear: Bilinear interpolation. If 'antialias' is true, becomes a hat/tent filter function with radius 1 when downsampling. ResizeLanczos5: Lanczos kernel with radius 5. Very-high-quality filter but may have stronger ringing. ResizeBicubic: Cubic interpolant of Keys. Equivalent to Catmull-Rom kernel. Reasonably good quality and faster than Lanczos3Kernel, particularly when upsampling. ResizeGaussian: Gaussian kernel with radius 3, sigma = 1.5 / 3.0. ResizeNearest: Nearest neighbor interpolation. 'antialias' has no effect when used with nearest neighbor interpolation. ResizeArea: Anti-aliased resampling with area interpolation. 'antialias' has no effect when used with area interpolation; it always anti-aliases. ResizeMitchellcubic: Mitchell-Netravali Cubic non-interpolating filter. For synthetic images (especially those lacking proper prefiltering), less ringing than Keys cubic kernel but less sharp.
        Returns:
        output Output image (NUMERIC type)
      • nonMaxSuppression

        public SDVariable nonMaxSuppression​(SDVariable boxes,
                                            SDVariable scores,
                                            int maxOutSize,
                                            double iouThreshold,
                                            double scoreThreshold)
        Greedily selects a subset of bounding boxes in descending order of score
        Parameters:
        boxes - Might be null. Name for the output variable (NUMERIC type)
        scores - vector of shape [num_boxes] (NUMERIC type)
        maxOutSize - scalar representing the maximum number of boxes to be selected
        iouThreshold - threshold for deciding whether boxes overlap too much with respect to IOU
        scoreThreshold - threshold for deciding when to remove boxes based on score
        Returns:
        output vectort of shape [M] representing the selected indices from the boxes tensor, where M <= max_output_size (NUMERIC type)
      • nonMaxSuppression

        public SDVariable nonMaxSuppression​(String name,
                                            SDVariable boxes,
                                            SDVariable scores,
                                            int maxOutSize,
                                            double iouThreshold,
                                            double scoreThreshold)
        Greedily selects a subset of bounding boxes in descending order of score
        Parameters:
        name - name May be null. Name for the output variable
        boxes - Might be null. Name for the output variable (NUMERIC type)
        scores - vector of shape [num_boxes] (NUMERIC type)
        maxOutSize - scalar representing the maximum number of boxes to be selected
        iouThreshold - threshold for deciding whether boxes overlap too much with respect to IOU
        scoreThreshold - threshold for deciding when to remove boxes based on score
        Returns:
        output vectort of shape [M] representing the selected indices from the boxes tensor, where M <= max_output_size (NUMERIC type)
      • pad

        public SDVariable pad​(SDVariable input,
                              SDVariable padding,
                              Mode Mode,
                              double padValue)
        Pads an image according to the given padding type
        Parameters:
        input - input array (NUMERIC type)
        padding - padding input (NUMERIC type)
        Mode - padding mode: CONSTANT, REFLECT, SYMMETRIC
        padValue - The value to pad with
        Returns:
        output the padded array (NUMERIC type)
      • pad

        public SDVariable pad​(String name,
                              SDVariable input,
                              SDVariable padding,
                              Mode Mode,
                              double padValue)
        Pads an image according to the given padding type
        Parameters:
        name - name May be null. Name for the output variable
        input - input array (NUMERIC type)
        padding - padding input (NUMERIC type)
        Mode - padding mode: CONSTANT, REFLECT, SYMMETRIC
        padValue - The value to pad with
        Returns:
        output the padded array (NUMERIC type)
      • randomCrop

        public SDVariable randomCrop​(SDVariable input,
                                     SDVariable shape)
        Randomly crops image
        Parameters:
        input - input array (NUMERIC type)
        shape - shape for crop (INT type)
        Returns:
        output cropped array (NUMERIC type)
      • randomCrop

        public SDVariable randomCrop​(String name,
                                     SDVariable input,
                                     SDVariable shape)
        Randomly crops image
        Parameters:
        name - name May be null. Name for the output variable
        input - input array (NUMERIC type)
        shape - shape for crop (INT type)
        Returns:
        output cropped array (NUMERIC type)
      • resizeBiCubic

        public SDVariable resizeBiCubic​(SDVariable input,
                                        SDVariable size,
                                        boolean alignCorners,
                                        boolean alignPixelCenters)
        Resize images to size using the specified method.
        Parameters:
        input - 4D image (NUMERIC type)
        size - the target size to resize to (INT type)
        alignCorners - whether to align corners during resizing. Images are aligned to preserve corners.
        alignPixelCenters - When resizing, assumes pixels are centered at 0.5.
        Returns:
        output Output image (NUMERIC type)
      • resizeBiCubic

        public SDVariable resizeBiCubic​(String name,
                                        SDVariable input,
                                        SDVariable size,
                                        boolean alignCorners,
                                        boolean alignPixelCenters)
        Resize images to size using the specified method.
        Parameters:
        name - name May be null. Name for the output variable
        input - 4D image (NUMERIC type)
        size - the target size to resize to (INT type)
        alignCorners - whether to align corners during resizing. Images are aligned to preserve corners.
        alignPixelCenters - When resizing, assumes pixels are centered at 0.5.
        Returns:
        output Output image (NUMERIC type)
      • resizeBiLinear

        public SDVariable resizeBiLinear​(SDVariable input,
                                         int height,
                                         int width,
                                         boolean alignCorners,
                                         boolean halfPixelCenters)
        Resize images to size using the specified method.
        Parameters:
        input - 4D image (NUMERIC type)
        height - target height for resizing to
        width - target width for resizing to
        alignCorners - whether to align corners during resizing. Images are aligned to preserve corners.
        halfPixelCenters - When resizing, assumes pixels are centered at 0.5.
        Returns:
        output Output image (NUMERIC type)
      • resizeBiLinear

        public SDVariable resizeBiLinear​(String name,
                                         SDVariable input,
                                         int height,
                                         int width,
                                         boolean alignCorners,
                                         boolean halfPixelCenters)
        Resize images to size using the specified method.
        Parameters:
        name - name May be null. Name for the output variable
        input - 4D image (NUMERIC type)
        height - target height for resizing to
        width - target width for resizing to
        alignCorners - whether to align corners during resizing. Images are aligned to preserve corners.
        halfPixelCenters - When resizing, assumes pixels are centered at 0.5.
        Returns:
        output Output image (NUMERIC type)
      • rgbToHsv

        public SDVariable rgbToHsv​(SDVariable input)
        Converting array from HSV to RGB format
        Parameters:
        input - 3D image (NUMERIC type)
        Returns:
        output 3D image (NUMERIC type)
      • rgbToHsv

        public SDVariable rgbToHsv​(String name,
                                   SDVariable input)
        Converting array from HSV to RGB format
        Parameters:
        name - name May be null. Name for the output variable
        input - 3D image (NUMERIC type)
        Returns:
        output 3D image (NUMERIC type)
      • rgbToYiq

        public SDVariable rgbToYiq​(SDVariable input)
        Converting array from RGB to YIQ format
        Parameters:
        input - 3D image (NUMERIC type)
        Returns:
        output 3D image (NUMERIC type)
      • rgbToYiq

        public SDVariable rgbToYiq​(String name,
                                   SDVariable input)
        Converting array from RGB to YIQ format
        Parameters:
        name - name May be null. Name for the output variable
        input - 3D image (NUMERIC type)
        Returns:
        output 3D image (NUMERIC type)
      • rgbToYuv

        public SDVariable rgbToYuv​(SDVariable input)
        Converting array from RGB to YUV format
        Parameters:
        input - 3D image (NUMERIC type)
        Returns:
        output 3D image (NUMERIC type)
      • rgbToYuv

        public SDVariable rgbToYuv​(String name,
                                   SDVariable input)
        Converting array from RGB to YUV format
        Parameters:
        name - name May be null. Name for the output variable
        input - 3D image (NUMERIC type)
        Returns:
        output 3D image (NUMERIC type)
      • yiqToRgb

        public SDVariable yiqToRgb​(SDVariable input)
        Converting image from YIQ to RGB format
        Parameters:
        input - 3D image (NUMERIC type)
        Returns:
        output 3D image (NUMERIC type)
      • yiqToRgb

        public SDVariable yiqToRgb​(String name,
                                   SDVariable input)
        Converting image from YIQ to RGB format
        Parameters:
        name - name May be null. Name for the output variable
        input - 3D image (NUMERIC type)
        Returns:
        output 3D image (NUMERIC type)
      • yuvToRgb

        public SDVariable yuvToRgb​(SDVariable input)
        Converting image from YUV to RGB format
        Parameters:
        input - 3D image (NUMERIC type)
        Returns:
        output 3D image (NUMERIC type)
      • yuvToRgb

        public SDVariable yuvToRgb​(String name,
                                   SDVariable input)
        Converting image from YUV to RGB format
        Parameters:
        name - name May be null. Name for the output variable
        input - 3D image (NUMERIC type)
        Returns:
        output 3D image (NUMERIC type)