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

Error When Using SMatrix for FIR Separable Filtration #252

Open
RoyiAvital opened this issue Nov 29, 2022 · 2 comments · May be fixed by #254
Open

Error When Using SMatrix for FIR Separable Filtration #252

RoyiAvital opened this issue Nov 29, 2022 · 2 comments · May be fixed by #254

Comments

@RoyiAvital
Copy link

This code works:

using Images;
using StaticArrays;

mA = rand(RGB{Float32}, 2048, 2048);

vW = [0.2f0 -0.5f0 0.3f0];
vW = centered(vW);

imfilter(mA, (vW', vW), "replicate", ImageFiltering.Algorithm.FIR());

Yet with this change:

using Images;
using StaticArrays;

mA = rand(RGB{Float32}, 2048, 2048);

vW = SMatrix{1, 3, Float32}([0.2f0 -0.5f0 0.3f0]);
vW = centered(vW);

imfilter(mA, (vW', vW), "replicate", ImageFiltering.Algorithm.FIR());

It will fail.

Environment information:

  • OS: Windows 10 64 Bit.
  • Julia: 1.8.3.
  • Images.jl: 0.25.2.
  • ImageFiltering.jl: 0.7.2.
@zygmuntszpak
Copy link
Member

I've started looking into this and they key difference between the SMatrix and the standard array happens on line 998 of border.jl

expand(ind::AbstractUnitRange, pad::AbstractUnitRange) = typeof(ind)(first(ind)+first(pad):last(ind)+last(pad))

With a standard array, we have

typeof(ind) == OffsetArrays.IdOffsetRange{Int64, Base.OneTo{Int64}} 

whereas with the static array we have

typeof(ind) ==  OffsetArrays.IdOffsetRange{Int64, SOneTo{3}}

We also have:

first(ind)+first(pad):last(ind)+last(pad)  == -1:1

and it turns out that

OffsetArrays.IdOffsetRange{Int64, Base.OneTo{Int64}}(-1:1)

is valid whereas

OffsetArrays.IdOffsetRange{Int64, SOneTo{3}}(-1:1)

results in DimensionMismatch: -1:1 is inconsistent with SOneTo{3}.

I'm not familiar with the internals of OffsetArrays so would have to study that to understand what OffsetArrays.IdOffsetRange is supposed to do. I think @johnnychen94 contributed to that package, so he might have some insight.

@zygmuntszpak
Copy link
Member

I think I've found a solution. Will try to make a pull-request soon once I confirm it works correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants