How can I crop a circle in image

I want to crop a circle in image with imageproc or image-rs.
But I don't know how to use this lib for cropping a circle in image.
Thank you.

You can do it manually: define a function that returns the distance from the center of the circle f(x, y) = sqrt((x - cx)^2 + (y - cy)^2) where (cx, cy) is the center of the circle. Then pick a border width b and the circle radius r.

Then for each pixel compute s = f(x, y) then check if s < r if so set alpha to 0, if it is less than r + b multiply alpha by (s - b) / b else don't touch it.

2 Likes

Tank you :slight_smile:

Note that f(x, y) = sqrt((x - cx)^2 + (y - cy)^2) is included as a built in function in the standard library under the name hypot as f64::hypot(x - cx, y - cy).

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.