StrokeWidthTransform icon indicating copy to clipboard operation
StrokeWidthTransform copied to clipboard

Bug fix: Ignore rays ending at image boundary

Open elcombato opened this issue 7 years ago • 1 comments

Indexing the ndarray edges with a negative index won't throw an IndexError and therefore a ray ending at the boundary of the image is not ingored.

elcombato avatar Jul 17 '17 14:07 elcombato

Hi, i am getting memory error when trying to run this code in python. This function

def _find_letters( swt, shapes, shape_h, shape_w):

STEP: Discard shapes that are probably not letters

swts = [] heights = [] widths = [] topleft_pts = [] images = []

for label,layer in shapes.items():
    (nz_y, nz_x) = (layer[0],layer[1])
    east, west, south, north = max(nz_x), min(nz_x), max(nz_y), min(nz_y)
    width, height = east - west, south - north

    if width < 4 or height < 4:
        continue

    if width / height > 10 or height / width > 10:
        continue

    diameter = math.sqrt(width * width + height * height)
    median_swt = np.median(swt[(nz_y, nz_x)])
    swts.append([math.log(median_swt, 2)])
    heights.append([math.log(height, 2)])
    topleft_pts.append(np.asarray([north, west]))
    widths.append(width)
     
    fulllayer = np.zeros((shape_w, shape_h), dtype=np.uint16)
    for i in range(len(layer[0])):
        fulllayer[layer[0][i], layer[1][i]] = 1
    images.append(fulllayer)

return swts, heights, widths, topleft_pts, images

soumyajit700 avatar May 05 '19 14:05 soumyajit700