image-rs / imageproc

Image processing operations
MIT License
735 stars 145 forks source link

Implement L2 Norm for morphology transforms #572

Closed Morgane55440 closed 4 months ago

Morgane55440 commented 4 months ago

this PR has been made following the issue #314 : Implement L2 Norm for morphology transforms

this PR seeks to integrate the L2 Norm for morphology operation, by expanding the Norm Enum to include L2, and updating all the functions which use this Enum to support the change. before :

pub enum Norm {
    /// Defines d((x1, y1), (x2, y2)) to be abs(x1 - x2) + abs(y1 - y2).
    /// Also known as the Manhattan or city block norm.
    L1,
    /// Defines d((x1, y1), (x2, y2)) to be max(abs(x1 - x2), abs(y1 - y2)).
    /// Also known as the chessboard norm.
    LInf,
}

after:

pub enum Norm {
    /// Defines d((x1, y1), (x2, y2)) to be abs(x1 - x2) + abs(y1 - y2).
    /// Also known as the Manhattan or city block norm.
    L1,
    /// Defines d((x1, y1), (x2, y2)) to be sqrt((x1 - x2)^2 + (y1 - y2)^2).
    /// Also known as the euclidian norm.
    /// when working in integer distances, we take the smallest 
    /// greater integer value, also know as 'ceiling'
    /// example : d((0,0),(1,2)) = ceil(sqrt(1+2^2)) = ceil(2.236...) = 3
    L2,
    /// Defines d((x1, y1), (x2, y2)) to be max(abs(x1 - x2), abs(y1 - y2)).
    /// Also known as the chessboard norm.
    LInf,
}

on top of adding tests for the new norm, this PR also adds a couple tests for the other norms, in particular when erode and dilate are called with a distance k of 0.

theotherphil commented 4 months ago

Please can you run cargo fmt on your PR - formatting is checked in the pre-commit tests.

Morgane55440 commented 4 months ago

Please can you run cargo fmt on your PR - formatting is checked in the pre-commit tests.

done - just learned cargo fmt is a thing today

theotherphil commented 4 months ago

After inlining the unnecessary wrapper functions this looks good to me, thanks!

Morgane55440 commented 4 months ago

done !

theotherphil commented 4 months ago

Thanks!