Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add script in preprocessing which can convert jpg to tiff pyramid large image type #5

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions preprocessing/cut_tumor_regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ def get_bbox(points):
x, y, width, height = bbox
tumour_img = wsi_img[y: y + height, x: x + width]

# pass wrong shape of tumour_img
if np.any(np.array(tumour_img.shape) == 0):
continue

# fill irrelevant areas with solid colors
if args.not_filled_other_regions:
mask_array = np.zeros((height, width), dtype=np.uint8)
Expand Down
29 changes: 29 additions & 0 deletions preprocessing/cvt_jpg2tiff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os
import glob
import sys
import pyvips

def cvt_jpg2tiff(src_dir, dst_dir):
if not os.path.exists(dst_dir):
os.makedirs(dst_dir)

src_files = glob.glob(os.path.join(src_dir, '*.jpg'))
for src_file in src_files:
dst_file = os.path.join(dst_dir, os.path.basename(src_file).replace('.jpg', '.tiff'))

# convert jpg to tiff
filename = os.path.splitext(os.path.basename(src_file))[0]
print(filename)
im = pyvips.Image.new_from_file(src_file)
im.write_to_file(dst_file, pyramid=True, tile=True, bigtiff=True, compression="none")
print('Done.')

if __name__ == '__main__':
args = sys.argv
if len(args) != 3:
print('Usage: python cvt_jpg2tiff.py src_dir dst_dir')
sys.exit(0)
src_dir = args[1]
dst_dir = args[2]
cvt_jpg2tiff(src_dir, dst_dir)