Skip to content

Commit

Permalink
fix(qtrees): Update PaddedMat constructor to handle cases where kerne…
Browse files Browse the repository at this point in the history
…l size is smaller than the input image
  • Loading branch information
guoyongzhi committed Feb 25, 2025
1 parent 0a1abc7 commit f4b128d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Stuffing"
uuid = "4175e07e-e5b7-423e-8796-3ea7f6d48281"
authors = ["guoyongzhi <[email protected]>"]
version = "0.10.2"
version = "0.10.3"

[deps]
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand Down
9 changes: 6 additions & 3 deletions src/qtrees.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,12 @@ mutable struct PaddedMat{T <: AbstractMatrix{UInt8}} <: AbstractMatrix{UInt8}
end

function PaddedMat(l::T, sz::Tuple{Int,Int}=size(l), rshift=0, cshift=0; default=0x00) where {T <: AbstractMatrix{UInt8}}
m = PaddedMat{T}(size(l), sz, rshift, cshift; default=default)
m.kernel[2:end - 2, 2:end - 2] .= l
(sz[1] >= size(l, 1) && sz[2] >= size(l, 2)) || (@warn "PaddedMat cut off: $(size(l))>$sz")
ksz = min.(size(l), sz)
b1, b2 = (size(l) .- ksz) 2
e1, e2 = (b1, b2) .+ ksz
m = PaddedMat{T}(ksz, sz, rshift, cshift; default=default)
m.kernel[2:end - 2, 2:end - 2] .= l[b1+1:e1, b2+1:e2]
m
end
function PaddedMat{T}(kernelsz::Tuple{Int,Int}, sz::Tuple{Int,Int},
Expand Down Expand Up @@ -193,7 +197,6 @@ function ShiftedQTree(pic::PaddedMat{T}) where T
end
function ShiftedQTree(pic::AbstractMatrix{UInt8}, sz::Integer; default=EMPTY)
@assert isinteger(log2(sz))
(sz >= size(pic, 1) && sz >= size(pic, 2)) || (@warn "ShiftedQTree cut off: $(size(pic))>$sz")
ShiftedQTree(PaddedMat(pic, (sz, sz), default=default))
end
function ShiftedQTree(pic::AbstractMatrix{UInt8}; default=EMPTY)
Expand Down

0 comments on commit f4b128d

Please sign in to comment.