Esempio n. 1
0
    def get_preprocessed_image(self, color_threshold=225):
        im = self.im

        if im.mode != 'L':
            im = im.convert('L')

        im = self.im.filter(ImageFilter.SHARPEN)
        im = threshold(im, color_threshold)
        im = im.filter(ImageFilter.FIND_EDGES)
        im = ImageOps.invert(im)
        return im
Esempio n. 2
0
 def split(self, output_dir, **kwargs):
     """Split an image that contains a table into per-cell images"""
     for box in self.get_boxes(**kwargs):
         col, row, left, upper, right, lower = box
         region = self.im.crop((left, upper, right, lower))
         region = self.transform(region, col, row)
         # Increase contrast.  Whiteish regions become absolute white
         region = threshold(region, 200)
         output_filename = cell_basename(self.filename, col, row) + ".tiff"
         output_path = os.path.join(output_dir, output_filename)
         region.save(output_path)
         md5 = md5sum(output_path)
         split_image.send(self, input_filename=self.filename,
             input_md5=self.md5, filename=output_filename, md5=md5,
             column=col, row=row, left=left, upper=upper, right=right,
             lower=lower)