-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
def extract_tile(image_dir, tile_size, x, y, width, height):
x_start_tile = x // tile_size
y_start_tile = y // tile_size
x_end_tile = (x + width) // tile_size
y_end_tile = (y + height) // tile_size
tmp_image = np.ones(
((y_end_tile - y_start_tile + 1) * tile_size, (x_end_tile - x_start_tile + 1) * tile_size, 3),
np.uint8) * 240
for y_id, col in enumerate(range(x_start_tile, x_end_tile + 1)):
for x_id, row in enumerate(range(y_start_tile, y_end_tile + 1)):
img_path = os.path.join(image_dir, '{:04d}_{:04d}.jpg'.format(row, col))
if not os.path.exists(img_path):
continue
img = cv2.imread(img_path)
h, w, _ = img.shape
tmp_image[(x_id * tile_size):(x_id * tile_size + h), (y_id * tile_size):(y_id * tile_size + w), :] = img
x_off = x % tile_size
y_off = y % tile_size
output = tmp_image[y_off:y_off + height, x_off:x_off + width]
return output
what's the meaning of 'pos[1] * step' in the below function? why you regard it as x and pass it to function extract_file?
def extract_and_save_tiles(image_dir, slide_save_dir, position_list, tile_size,
imsize, step, invert_rgb=False):
for pos in position_list:
img = extract_tile(image_dir, tile_size, pos[1] * step, pos[0] * step,
imsize, imsize)
if len(img) > 0:
if invert_rgb:
img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
cv2.imwrite(
os.path.join(slide_save_dir, '{:04d}_{:04d}.jpg'.format(pos[1], pos[0])), img)
Metadata
Metadata
Assignees
Labels
No labels