Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Censure Detector #35

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Adds Filter Stack for OctagonalFilter
  • Loading branch information
mronian authored and tejus-gupta committed Apr 30, 2017
commit 1d4754c68ae44f678ba35414afa0f6e5305c092f
53 changes: 37 additions & 16 deletions src/censure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ abstract BiFilter
type BoxFilter <: BiFilter

filter :: Array{Float64, 2}
m_out :: UInt8
m_in :: UInt8

BoxFilter(mo, mi) = new(ones(Float64, mo, mo), mo, mi)
scale :: UInt8

end

Expand All @@ -18,29 +15,33 @@ type OctagonFilter <: BiFilter
n_out :: UInt8
n_in :: UInt8

OctagonFilter(mo, mi, no, ni) = new(ones(Float64, mo + 2 * no, mo + 2 * no), mo, mi, no, ni)

end

type CENSURE <: Detector

smallest :: Integer
largest :: Integer
filter :: Type
filter_type :: Type
filter_stack :: Array{BiFilter}
responseThreshold :: Number
lineThreshold :: Number

end

function createFilter(OF::OctagonFilter)
area_out = (OF.m_out + 2 * OF.n_out) ^ 2 - 2 * OF.n_out ^ 2
area_in = (OF.m_in + 2 * OF.n_in) ^ 2 - 2 * OF.n_in ^ 2
weight_out = 1.0/(area_out - area_in)
weight_in = 1.0/area_in
OF.filter[:, :] = weight_out
inner_start = Int(0.5 * ((OF.m_out + 2 * OF.n_out) - (OF.m_in + 2 * OF.n_in)))
OF.filter[inner_start + 1 : end - inner_start, inner_start + 1 : end - inner_start] = -1
OF.filter[inner_start + 1 : end - inner_start, inner_start + 1 : end - inner_start] = weight_in

for i in 1:OF.n_in
OF.filter[inner_start + i, inner_start + 1 : inner_start + OF.n_in - i + 1] = 0
OF.filter[inner_start + i, inner_start + OF.n_in + OF.m_in + i : inner_start + OF.m_in + 2 * OF.n_in] = 0
OF.filter[inner_start + OF.m_in + 2 * OF.n_in - i + 1, inner_start + 1 : inner_start + OF.n_in - i + 1] = 0
OF.filter[inner_start + OF.m_in + 2 * OF.n_in - i + 1, inner_start + OF.n_in + OF.m_in + i : inner_start + OF.m_in + 2 * OF.n_in] = 0
OF.filter[inner_start + i, inner_start + 1 : inner_start + OF.n_in - i + 1] = weight_out
OF.filter[inner_start + i, inner_start + OF.n_in + OF.m_in + i : inner_start + OF.m_in + 2 * OF.n_in] = weight_out
OF.filter[inner_start + OF.m_in + 2 * OF.n_in - i + 1, inner_start + 1 : inner_start + OF.n_in - i + 1] = weight_out
OF.filter[inner_start + OF.m_in + 2 * OF.n_in - i + 1, inner_start + OF.n_in + OF.m_in + i : inner_start + OF.m_in + 2 * OF.n_in] = weight_out
end

for i in 1:OF.n_out
Expand All @@ -53,13 +54,33 @@ function createFilter(OF::OctagonFilter)
end

function createFilter(BF::BoxFilter)
inner_start = Int(0.5 * (BF.m_out - BF.m_in))
BF.filter[inner_start + 1 : end - inner_start, inner_start + 1 : end - inner_start] = -1

end

CENSURE(; smallest::Integer = 1, largest::Integer = 7, filter::Type = BoxFilter, responseThreshold::Number = 0.15, lineThreshold::Number = 10) = CENSURE(scale, filter, responseThreshold, lineThreshold)
OctagonFilter(mo, mi, no, ni) = (OF = OctagonFilter(ones(Float64, mo + 2 * no, mo + 2 * no), mo, mi, no, ni); createFilter(OF); OF)
BoxFilter(s) = (BF = BoxFilter(ones(Float64, 4 * s + 1, 4 * s + 1), s); createFilter(BF); BF)

function censure{T}(img::AbstractArray{T, 2}, params::CENSURE)
OctagonFilter_Kernels = [
[5, 3, 2, 0],
[5, 3, 3, 1],
[7, 3, 3, 2],
[9, 5, 4, 2],
[9, 5, 7, 3],
[13, 5, 7, 4],
[15, 5, 10, 5]
]

BoxFilter_Kernels = [1, 2, 3, 4, 5, 6, 7]

Kernels = Dict(BoxFilter => BoxFilter_Kernels, OctagonFilter => OctagonFilter_Kernels)

function getFilterStack(filter_type::Type, smallest::Integer, largest::Integer)
k = Kernels[filter_type]
filter_stack = map(f -> filter_type(f...), k[smallest : largest])
end

CENSURE(; smallest::Integer = 1, largest::Integer = 7, filter::Type = OctagonFilter, responseThreshold::Number = 0.15, lineThreshold::Number = 10) = CENSURE(smallest, largest, filter, getFilterStack(filter, smallest, largest), responseThreshold, lineThreshold)

function censure{T}(img::AbstractArray{T, 2}, params::CENSURE)

end