Class MPSImageCanny

  • All Implemented Interfaces:
    NSCoding, NSCopying, NSSecureCoding, NSObject

    public class MPSImageCanny
    extends MPSUnaryImageKernel
    MPSImageCanny The MPSImageCanny implements the Canny edge detection algorithm. When the color model of the source and destination textures match, the filter is applied to each channel seperately. If the destination is monochrome but source multichannel, the source will be converted to grayscale using the linear gray color transform vector (v). Luminance = v[0] * pixel.x + v[1] * pixel.y + v[2] * pixel.z; The canny edge detection algorithm consists of 5 steps: 1. Blur the source image using a Gaussian blur with a sigma parameter 2. Use horizontal and vertical Sobel filters to find a gradient magnitude and direction. G = sqrt(Sx^2 + Sy^2) G_ang = arctan(Sy / Sx) 3. Perform non-maximum suppression to thin edges to single pixel widths. A pixel is considered to be a maxium along the edge if it has the largest gradient magnitude along the positive and negatve gradient direction. That is, if the gradient direction is 90°, if the gradient magnitude of a pixel is greater than its neighbors at -90° and 90° it is the maximum. Any pixel which is not a maximum will have its value suppressed, by setting it's magnitude to 0. 4. Double thresholding is preformed with two values ht and lt with ht > lt to classify a pixel as part of a weak or strong edge. A pixel with gradient value G is classified as: Strong edge: G > ht Weak edge: ht >= G > lt Not an edge: lt >= G 5. Edge tracking is performed along all weak edges to determine if they are part of a strong edge. Any weak edges which are connected to a strong edge are labelled true edges, along with strong edges themselves. A pixel can be connected through any of its 8 neighbors. Any pixel marked as a true edge is output with a high value, and all others are considered background and output with a low value.
    • Constructor Detail

      • MPSImageCanny

        protected MPSImageCanny​(org.moe.natj.general.Pointer peer)
    • Method Detail

      • accessInstanceVariablesDirectly

        public static boolean accessInstanceVariablesDirectly()
      • allocWithZone

        public static java.lang.Object allocWithZone​(org.moe.natj.general.ptr.VoidPtr zone)
      • automaticallyNotifiesObserversForKey

        public static boolean automaticallyNotifiesObserversForKey​(java.lang.String key)
      • cancelPreviousPerformRequestsWithTarget

        public static void cancelPreviousPerformRequestsWithTarget​(java.lang.Object aTarget)
      • cancelPreviousPerformRequestsWithTargetSelectorObject

        public static void cancelPreviousPerformRequestsWithTargetSelectorObject​(java.lang.Object aTarget,
                                                                                 org.moe.natj.objc.SEL aSelector,
                                                                                 java.lang.Object anArgument)
      • classFallbacksForKeyedArchiver

        public static NSArray<java.lang.String> classFallbacksForKeyedArchiver()
      • classForKeyedUnarchiver

        public static org.moe.natj.objc.Class classForKeyedUnarchiver()
      • colorTransform

        public org.moe.natj.general.ptr.ConstFloatPtr colorTransform()
        [@property] colorTransform Returns a pointer to the array of three floats used to convert RGBA, RGB or RG images to the destination format when the destination is monochrome. Value is readonly and user should not modify or free.
      • debugDescription_static

        public static java.lang.String debugDescription_static()
      • description_static

        public static java.lang.String description_static()
      • hash_static

        public static long hash_static()
      • highThreshold

        public float highThreshold()
        [@property] highThreshold Read-write value used to set the high threshold for double thresholding, value is normalized. Default is 0.4
      • initWithCoderDevice

        public MPSImageCanny initWithCoderDevice​(NSCoder aDecoder,
                                                 java.lang.Object device)
        NSSecureCoding compatability While the standard NSSecureCoding/NSCoding method -initWithCoder: should work, since the file can't know which device your data is allocated on, we have to guess and may guess incorrectly. To avoid that problem, use initWithCoder:device instead.
        Overrides:
        initWithCoderDevice in class MPSUnaryImageKernel
        Parameters:
        aDecoder - The NSCoder subclass with your serialized MPSKernel
        device - The MTLDevice on which to make the MPSKernel
        Returns:
        A new MPSKernel object, or nil if failure.
      • initWithDevice

        public MPSImageCanny initWithDevice​(java.lang.Object device)
        Initialize a Canny filter on a given device using the default color transform and default sigma value for Gaussian blur. Default transform: BT.601/JPEG {0.299f, 0.587f, 0.114f} Default sigma: sqrt(2) For non-default parameters, use -initWithDevice:linearGrayColorTransform:sigma:
        Overrides:
        initWithDevice in class MPSUnaryImageKernel
        Parameters:
        device - The device the filter will run on
        Returns:
        A valid object or nil, if failure.
      • initWithDeviceLinearToGrayScaleTransformSigma

        public MPSImageCanny initWithDeviceLinearToGrayScaleTransformSigma​(MTLDevice device,
                                                                           org.moe.natj.general.ptr.ConstFloatPtr transform,
                                                                           float sigma)
        Initialize a Canny filter on a given device with a non-default color transform and non-default sigma. [@code] Luminance = transform[0] * pixel.x + transform[1] * pixel.y + transform[2] * pixel.z; [@endcode] [@code] w(i) = 1/sqrt(2*pi*sigma) * exp(-n^2/2*sigma^2) [@endcode] If we take cut off at 1% of w(0) (max weight) beyond which weights are considered 0, we have [@code] ceil (sqrt(-log(0.01)*2)*sigma) ~ ceil(3.7*sigma) [@endcode] as rough estimate of filter width
        Parameters:
        device - The device the filter will run on
        transform - Array of three floats describing the rgb to gray scale color transform.
        sigma - The standard deviation of gaussian blur filter. Gaussian weight, centered at 0, at integer grid n is given as
        Returns:
        A valid object or nil, if failure.
      • instanceMethodSignatureForSelector

        public static NSMethodSignature instanceMethodSignatureForSelector​(org.moe.natj.objc.SEL aSelector)
      • instancesRespondToSelector

        public static boolean instancesRespondToSelector​(org.moe.natj.objc.SEL aSelector)
      • isSubclassOfClass

        public static boolean isSubclassOfClass​(org.moe.natj.objc.Class aClass)
      • keyPathsForValuesAffectingValueForKey

        public static NSSet<java.lang.String> keyPathsForValuesAffectingValueForKey​(java.lang.String key)
      • lowThreshold

        public float lowThreshold()
        [@property] lowThreshold Read-write value used to set the low threshold for double thresholding, value is normalized. Default is 0.2
      • new_objc

        public static java.lang.Object new_objc()
      • resolveClassMethod

        public static boolean resolveClassMethod​(org.moe.natj.objc.SEL sel)
      • resolveInstanceMethod

        public static boolean resolveInstanceMethod​(org.moe.natj.objc.SEL sel)
      • setHighThreshold

        public void setHighThreshold​(float value)
        [@property] highThreshold Read-write value used to set the high threshold for double thresholding, value is normalized. Default is 0.4
      • setLowThreshold

        public void setLowThreshold​(float value)
        [@property] lowThreshold Read-write value used to set the low threshold for double thresholding, value is normalized. Default is 0.2
      • setUseFastMode

        public void setUseFastMode​(boolean value)
        [@property] useFastMode Read-write value used to change algorithm to an approximation of the true Canny Edge detection Algorithm. When true, a limit is placed on how far a single strong edge can extend. The result will be similar to a true output but some edges may terminate early, resulting in minor differences for cases with long, weak edges. The performance for the approximate canny implementation is improved and should provide similar enough results for most cases. Extra tuning of the high and low thresholds as well as sigma may help achieve a more similar output in this mode. Default is YES
      • setVersion_static

        public static void setVersion_static​(long aVersion)
      • sigma

        public float sigma()
        [@property] sigma Read-only sigma value used in performing Gaussian blur of the image
      • superclass_static

        public static org.moe.natj.objc.Class superclass_static()
      • supportsSecureCoding

        public static boolean supportsSecureCoding()
      • _supportsSecureCoding

        public boolean _supportsSecureCoding()
        Description copied from interface: NSSecureCoding
        This property must return YES on all classes that allow secure coding. Subclasses of classes that adopt NSSecureCoding and override initWithCoder: must also override this method and return YES. The Secure Coding Guide should be consulted when writing methods that decode data.
        Specified by:
        _supportsSecureCoding in interface NSSecureCoding
        Overrides:
        _supportsSecureCoding in class MPSUnaryImageKernel
      • useFastMode

        public boolean useFastMode()
        [@property] useFastMode Read-write value used to change algorithm to an approximation of the true Canny Edge detection Algorithm. When true, a limit is placed on how far a single strong edge can extend. The result will be similar to a true output but some edges may terminate early, resulting in minor differences for cases with long, weak edges. The performance for the approximate canny implementation is improved and should provide similar enough results for most cases. Extra tuning of the high and low thresholds as well as sigma may help achieve a more similar output in this mode. Default is YES
      • version_static

        public static long version_static()