image-rs / imageproc

Image processing operations
MIT License
755 stars 148 forks source link

intersection_points function in hough.rs has bug if intersection point is in image corner. #533

Closed alanthinker closed 5 months ago

alanthinker commented 1 year ago

need check two point is not a same point.

should be:

    if right_y >= 0.0 && right_y <= h {
        let right_intersect = (w, right_y);
        if let Some(s) = start {
            if right_intersect != s {
                return Some((s, right_intersect));
            }
        }
        start = Some(right_intersect);
    }

    if left_y >= 0.0 && left_y <= h {
        let left_intersect = (0.0, left_y);
        if let Some(s) = start {
            if left_intersect != s {
                return Some((s, left_intersect));
            }
        }
        start = Some(left_intersect);
    }

    if bottom_x >= 0.0 && bottom_x <= w {
        let bottom_intersect = (bottom_x, h);
        if let Some(s) = start {
            if bottom_intersect != s {
                return Some((s, bottom_intersect));
            }
        }
        start = Some(bottom_intersect);
    }

    if top_x >= 0.0 && top_x <= w {
        let top_intersect = (top_x, 0.0);
        if let Some(s) = start {
            if top_intersect != s {
                return Some((s, top_intersect));
            }
        }
    }
theotherphil commented 5 months ago

With the current behaviour an intersection point at the corner of the image is counted twice. Under your proposal it's not counted at all. The function could be changed to return a list of intersection points and only return one point for a corner intersection but I think the current behaviour is reasonable.