-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AccDirectionalNonMaximumSuppressionFilter
- Loading branch information
Showing
5 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
AccImageFilter/AccDirectionalNonMaximumSuppressionFilter.metal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// AccDirectionalNonMaximumSuppressionFilter.metal | ||
// MetalAcc | ||
// | ||
// Created by 王佳玮 on 16/4/5. | ||
// Copyright © 2016年 JW. All rights reserved. | ||
// | ||
|
||
#include <metal_stdlib> | ||
using namespace metal; | ||
kernel void DirectionalNonMaximumSuppression(texture2d<float, access::read> inTexture [[texture(0)]], | ||
texture2d<float, access::write> outTexture [[texture(1)]], | ||
device unsigned int *lowerThreshold [[buffer(0)]], | ||
device unsigned int *upperThreshold [[buffer(1)]], | ||
uint2 gid [[thread_position_in_grid]]) | ||
{ | ||
float3 currentGradientAndDirection = inTexture.read(gid).rgb; | ||
uint2 gradientDirection = uint2((currentGradientAndDirection.gb * 2.0) - 1.0); | ||
float firstSampledGradientMagnitude = inTexture.read(gid + gradientDirection).r; | ||
float secondSampledGradientMagnitude = inTexture.read(gid - gradientDirection).r; | ||
|
||
float multiplier = step(firstSampledGradientMagnitude, currentGradientAndDirection.r); | ||
multiplier = multiplier * step(secondSampledGradientMagnitude, currentGradientAndDirection.r); | ||
|
||
float thresholdCompliance = smoothstep(*lowerThreshold, *upperThreshold, currentGradientAndDirection.r); | ||
multiplier = multiplier * thresholdCompliance; | ||
|
||
float4 outColor = float4(multiplier, multiplier, multiplier, 1.0); | ||
outTexture.write(outColor,gid); | ||
|
||
} | ||
|
19 changes: 19 additions & 0 deletions
19
AccImageFilter/AccDirectionalNonMaximumSuppressionFilter.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// AccDirectionalNonMaximumSuppressionFilter.swift | ||
// MetalAcc | ||
// | ||
// Created by 王佳玮 on 16/4/5. | ||
// Copyright © 2016年 JW. All rights reserved. | ||
// | ||
|
||
public class AccDirectionalNonMaximumSuppressionFilter: AccImageFilter { | ||
public var threshold:(lower:Float,upper:Float)? | ||
override public init(){ | ||
super.init() | ||
self.threshold = (0.1,0.5) | ||
self.name = "DirectionalNonMaximumSuppression" | ||
} | ||
override public func applyFilter() { | ||
addCommandWithFactor([threshold!.lower,threshold!.upper]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters