3939function _lbp (img:: AbstractArray{T, 2} , points:: Integer , offsets:: Array , method:: Function = lbp_original) where T<: Gray
4040 uniform_params = PatternCache (points)
4141 lbp_image = zeros (UInt, size (img))
42+ imgitp = bilinear_interpolator (img, offsets)
4243 R = CartesianIndices (size (img))
4344 bit_pattern = falses (length (offsets))
4445 for I in R
45- for (i, o) in enumerate (offsets) bit_pattern[i] = img[I] >= bilinear_interpolation (img, I[1 ] + o[1 ], I[2 ] + o[2 ]) end
46+ for (i, o) in enumerate (offsets) bit_pattern[i] = img[I] >= T ( imgitp ( I[1 ] + o[1 ], I[2 ] + o[2 ]) ) end
4647 lbp_image[I], uniform_params = method (bit_pattern, uniform_params)
4748 end
4849 lbp_image
@@ -62,11 +63,12 @@ lbp(img::AbstractArray{T, 2}, points::Integer, radius::Number, method::Function
6263function _modified_lbp (img:: AbstractArray{T, 2} , points:: Integer , offsets:: Array , method:: Function = lbp_original) where T<: Gray
6364 uniform_params = PatternCache (points)
6465 lbp_image = zeros (UInt, size (img))
66+ imgitp = bilinear_interpolator (img, offsets)
6567 R = CartesianIndices (size (img))
6668 bit_pattern = falses (length (offsets))
6769 for I in R
68- avg = (sum (bilinear_interpolation (img, I[1 ] + o[1 ], I[2 ] + o[2 ]) for o in offsets) + img[I]) / (points + 1 )
69- for (i, o) in enumerate (offsets) bit_pattern[i] = avg >= bilinear_interpolation (img, I[1 ] + o[1 ], I[2 ] + o[2 ]) end
70+ avg = (sum (imgitp ( I[1 ] + o[1 ], I[2 ] + o[2 ]) for o in offsets) + img[I]) / (points + 1 )
71+ for (i, o) in enumerate (offsets) bit_pattern[i] = avg >= imgitp ( I[1 ] + o[1 ], I[2 ] + o[2 ]) end
7072 lbp_image[I], uniform_params = method (bit_pattern, uniform_params)
7173 end
7274 lbp_image
@@ -76,15 +78,16 @@ modified_lbp(img::AbstractArray{T, 2}, method::Function = lbp_original) where {T
7678
7779modified_lbp (img:: AbstractArray{T, 2} , points:: Integer , radius:: Number , method:: Function = lbp_original) where {T<: Gray } = _modified_lbp (img, points, circular_offsets (points, radius), method)
7880
79- function _direction_coded_lbp (img:: AbstractArray{T, 2} , offsets:: Array ) where T
81+ function _direction_coded_lbp (img:: AbstractArray{T, 2} , offsets:: Array ) where T<: Union{Normed,AbstractGray{<:Normed}}
8082 lbp_image = zeros (UInt, size (img))
8183 R = CartesianIndices (size (img))
8284 p = Int (length (offsets) / 2 )
8385 raw_img = convert (Array{Int}, rawview (channelview (img)))
86+ imgitp = bilinear_interpolator (raw_img, offsets)
8487 neighbours = zeros (Int, length (offsets))
8588 for I in R
8689 for (i, o) in enumerate (offsets)
87- neighbours[i] = Int ( bilinear_interpolation (img, I[1 ] + o[1 ], I[2 ] + o[2 ]). val . i )
90+ neighbours[i] = round (Int, imgitp ( I[1 ] + o[1 ], I[2 ] + o[2 ]))
8891 end
8992 lbp_image[I] = sum (((neighbours[j] - raw_img[I]) * (neighbours[j + p] - raw_img[I]) >= 0 ) * (2 ^ (2 * p - 2 * j + 1 )) +
9093 (abs (neighbours[j] - raw_img[I]) >= abs (neighbours[j + p] - raw_img[I])) * (2 ^ (2 * p - 2 * j)) for j in 1 : p)
@@ -100,19 +103,19 @@ function direction_coded_lbp(img::AbstractArray{T, 2}, points::Integer, radius::
100103end
101104
102105function multi_block_lbp (img:: AbstractArray{T, 2} , tl_y:: Integer , tl_x:: Integer , height:: Integer , width:: Integer ) where T<: Gray
103- int_img = integral_image (img)
106+ int_img = IntegralArray (img)
104107 h, w = size (img)
105108
106109 @assert (tl_y + 3 * height - 1 <= h) && (tl_x + 3 * width - 1 <= w) " Rectangle Grid exceeds image dimensions."
107110
108111 center = [tl_y + height, tl_x + width]
109- central_sum = boxdiff ( int_img, tl_y + height : tl_y + 2 * height - 1 , tl_x + width : tl_x + 2 * width - 1 )
112+ central_sum = int_img[ tl_y + height .. tl_y + 2 * height - 1 , tl_x + width .. tl_x + 2 * width - 1 ]
110113 lbp_code = 0
111114
112115 for (i, o) in enumerate (original_offsets)
113116 cur_tl_y = center[1 ] + o[1 ] * height
114117 cur_tl_x = center[2 ] + o[2 ] * width
115- cur_window_sum = boxdiff ( int_img, cur_tl_y : cur_tl_y + height - 1 , cur_tl_x : cur_tl_x + height - 1 )
118+ cur_window_sum = int_img[ cur_tl_y .. cur_tl_y + height - 1 , cur_tl_x .. cur_tl_x + height - 1 ]
116119 lbp_code += (cur_window_sum > central_sum ? 1 : 0 ) * 2 ^ (8 - i)
117120 end
118121 lbp_code
@@ -129,8 +132,8 @@ function _create_descriptor(img::AbstractArray{Gray{T}, 2}, yblocks::Integer = 4
129132 for j in 1 : yblocks
130133 lbp_image = lbp_type (img[(j- 1 )* blockh+ 1 : j* blockh, (i- 1 )* blockw+ 1 : i* blockw], args... )
131134 lbp_norm = lbp_image
132- _, hist = imhist (lbp_image, edges)
133- append! (descriptor, hist[2 : end - 1 ])
135+ _, hist = build_histogram (lbp_image, edges)
136+ append! (descriptor, hist[1 : end - 1 ])
134137 end
135138 end
136139 descriptor
0 commit comments