text
stringlengths
0
828
for x in range(min_w, image.shape[1] - min_w))]
return sorted(x_c + y_c)"
4259,"def binary_partition_image(image, min_w=1, min_h=1, depth=0, max_depth=-1):
""""""Return a bsp of [pos, axis, [before_node, after_node]] nodes where leaf
nodes == None.
If max_depth < 0 this function will continue until all leaf nodes have
been found, if it is >= 0 leaf nodes will be created at that depth.
min_w and min_h are the minimum width or height of a partition.
""""""
if max_depth >= 0 and depth >= max_depth:
return None
partition = get_best_partition(image, min_w=min_w, min_h=min_h)
if partition is None:
return None
pos, axis = partition
if axis == 0:
p1 = binary_partition_image(
image[pos:], min_w, min_h, depth + 1, max_depth)
p2 = binary_partition_image(
image[:pos], min_w, min_h, depth + 1, max_depth)
elif axis == 1:
p1 = binary_partition_image(
image[:, pos:], min_w, min_h, depth + 1, max_depth)
p2 = binary_partition_image(
image[:, :pos], min_w, min_h, depth + 1, max_depth)
return [pos, axis, [p1, p2]]"
4260,"def find_threshold_near_density(img, density, low=0, high=255):
""""""Find a threshold where the fraction of pixels above the threshold
is closest to density where density is (count of pixels above
threshold / count of pixels).
The highest threshold closest to the desired density will be returned.
Use low and high to exclude undesirable thresholds.
:param img: target image
:type img: 2d :class:`numpy.ndarray`
:param density: target density
:type density: float between 0.0 and 1.0
:param low: min threshold to test
:type low: ubyte
:param migh: max threshold to test
:type low: ubyte
:rtype: ubyte
""""""
size = numpy.size(img)
densities = []
last_t = None
while True:
t = ((high - low) // 2) + low
if t == last_t:
densities.sort(key=lambda x: (abs(x[0] - density), 256 - x[1]))
return densities[0][1]
else:
last_t = t
d = numpy.count_nonzero(img > t) / size
densities.append((d, t))
if d < density:
high = t
elif d >= density: # search away from low
low = t"
4261,"def filter_greys_using_image(image, target):
""""""Filter out any values in target not in image
:param image: image containing values to appear in filtered image
:param target: the image to filter
:rtype: 2d :class:`numpy.ndarray` containing only value in image
and with the same dimensions as target
""""""
maskbase = numpy.array(range(256), dtype=numpy.uint8)
mask = numpy.where(numpy.in1d(maskbase, numpy.unique(image)), maskbase, 0)
return mask[target]"
4262,"def get_swagger_view(title=None, url=None, generator_class=SchemaGenerator):
""""""
Returns schema view which renders Swagger/OpenAPI.
""""""
return schemas.get_schema_view(
title=title,
url=url,
renderer_classes=[
CoreJSONRenderer,
renderers.OpenAPIRenderer,
renderers.SwaggerUIRenderer],
generator_class=generator_class)"
4263,"def __init_defaults(self, config):
""""""Initializes the default connection settings.""""""
provider = self.__provider
if provider == 'sqlite':
config.setdefault('dbname', ':memory:')
config.setdefault('create_db', True)
elif provider == 'mysql':
config.setdefault('port', 3306)
config.setdefault('charset', 'utf8')