Ejemplo n.º 1
0
def main():
    args = get_args(sys.argv[1:])
    in_dir = args['in_directory']
    out_dir = args['out_directory']

    onlyjpg = extract_target_files(in_dir, 'jpg')

    for jpg in onlyjpg:
        sample_path = in_dir + jpg
        output_path = out_dir + 'filtered_' + jpg
        pil_img = Image.open(sample_path)
        np_img = np.asarray(pil_img)
        filtered_np_img = apply_image_filters(np_img,
                                              slide_num=None,
                                              info=None,
                                              save=False,
                                              display=False)
        filtered_pil_img = np_to_pil(filtered_np_img)
        filtered_pil_img.save(output_path)
Ejemplo n.º 2
0
def save_filtered_image(np_img, slide_num, filter_num, filter_text):
  """
  Save a filtered image to the file system.

  Args:
    np_img: Image as a NumPy array.
    slide_num:  The slide number.
    filter_num: The filter number.
    filter_text: Descriptive text to add to the image filename.
  """
  t = Time()
  filepath = slide.get_filter_image_path(slide_num, filter_num, filter_text)
  pil_img = util.np_to_pil(np_img)
  pil_img.save(filepath)
  print("%-20s | Time: %-14s  Name: %s" % ("Save Image", str(t.elapsed()), filepath))

  t1 = Time()
  thumbnail_filepath = slide.get_filter_thumbnail_path(slide_num, filter_num, filter_text)
  slide.save_thumbnail(pil_img, slide.THUMBNAIL_SIZE, thumbnail_filepath)
  print("%-20s | Time: %-14s  Name: %s" % ("Save Thumbnail", str(t1.elapsed()), thumbnail_filepath))
Ejemplo n.º 3
0
def apply_filters_to_image(slide_num, save=True, display=False):
  """
  Apply a set of filters to an image and optionally save and/or display filtered images.

  Args:
    slide_num: The slide number.
    save: If True, save filtered images.
    display: If True, display filtered images to screen.

  Returns:
    Tuple consisting of 1) the resulting filtered image as a NumPy array, and 2) dictionary of image information
    (used for HTML page generation).
  """
  t = Time()
  print("Processing slide #%d" % slide_num)

  info = dict()

  if save and not os.path.exists(slide.FILTER_DIR):
    os.makedirs(slide.FILTER_DIR)
  img_path = slide.get_training_image_path(slide_num)
  np_orig = slide.open_image_np(img_path)
  filtered_np_img = apply_image_filters(np_orig, slide_num, info, save=save, display=display)

  if save:
    t1 = Time()
    result_path = slide.get_filter_image_result(slide_num)
    pil_img = util.np_to_pil(filtered_np_img)
    pil_img.save(result_path)
    print("%-20s | Time: %-14s  Name: %s" % ("Save Image", str(t1.elapsed()), result_path))

    t1 = Time()
    thumbnail_path = slide.get_filter_thumbnail_result(slide_num)
    slide.save_thumbnail(pil_img, slide.THUMBNAIL_SIZE, thumbnail_path)
    print("%-20s | Time: %-14s  Name: %s" % ("Save Thumbnail", str(t1.elapsed()), thumbnail_path))

  print("Slide #%03d processing time: %s\n" % (slide_num, str(t.elapsed())))

  return filtered_np_img, info
Ejemplo n.º 4
0
                                                       np_img.shape[1],
                                                       ROW_TILE_SIZE,
                                                       COL_TILE_SIZE, 0.5)

    img_mask_path = get_mask_image_path(img_num)
    np_img_mask = slide.open_image_np(img_mask_path)

    for t in tile_indices:
        r_s, r_e, c_s, c_e = t

        np_tile = np_img[r_s:r_e, c_s:c_e]

        np_tile_mask = np_img_mask[r_s:r_e, c_s:c_e]

        score = tiles.unique_count_app(
            np_tile_mask)  #do not use unique this is not acceptable

        if (score > 0):
            count += 1

            patch = util.np_to_pil(np_tile)

            patch_path = get_patch_path("train", score, count)

            dir = os.path.dirname(patch_path)
            if not os.path.exists(dir):
                os.makedirs(dir)
            patch.save(patch_path)

    #print(img_path)