I was given this function:
import matplotlib.patches as mpatches
from skimage.measure import regionprops
import math
facteurforme = lambda r: (4 * math.pi * r.area) / (r.perimeter * r.perimeter)
circ = lambda r: (r.perimeter)/(r.equivalent_diameter)
I should complete the code to detect just the rectangles in image made of circles and rectangles and then put the detected shapes in a box using Python 3
.
I'd know how to use facteurforme
.
Help please!.
facteurforme
is a lambda
Lambda expressions (sometimes called lambda forms) are used to create anonymous functions. The expression lambda parameters: expression yields a function object. The unnamed object behaves like a function object defined with:
def <lambda>(parameters): return expression
As you're supposed to use regionprops and facteurforme
uses r.area
and r.perimeter
which are properties of regionprops it is obvious that you should use a set of region properties as the lambda's argument.
facteureforme calculates the isoperimetric quotient for a given set of region properties.
This quotient is only 1 for a circle (or very close to 1 in a non-theoretical case) and less for anything else. You can use this value to distinguish between circles and rectangles.
Also see Shape Factor: Circularity
r.equivalent_diameter
should be renamed r.equivalent_diameterfloat
btw.
To get started with your homework I suggest you search the web for regionprops tutorials / examples
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.