Skip to content

Commit 4b084b2

Browse files
Merge pull request #1131 from qin-yu/compress-tiff
Compress TIFFs on save
2 parents 6398d13 + 84e8589 commit 4b084b2

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

cellpose/gui/io.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@ def _save_flows(parent):
593593
else:
594594
print("ERROR: no flows or cellprob found")
595595

596+
596597
def _save_rois(parent):
597598
""" save masks as rois in .zip file for ImageJ """
598599
filename = parent.filename

cellpose/io.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def imsave(filename, arr):
265265
"""
266266
ext = os.path.splitext(filename)[-1].lower()
267267
if ext == ".tif" or ext == ".tiff":
268-
tifffile.imwrite(filename, arr)
268+
tifffile.imwrite(filename, data=arr, compression="zlib")
269269
else:
270270
if len(arr.shape) > 2:
271271
arr = cv2.cvtColor(arr, cv2.COLOR_BGR2RGB)
@@ -290,7 +290,7 @@ def get_image_files(folder, mask_filter, imf=None, look_one_level_down=False):
290290
ValueError: If no images are found in the specified folder with the supported file extensions.
291291
ValueError: If no images are found in the specified folder without the mask or flow file endings.
292292
"""
293-
mask_filters = ["_cp_output", "_flows", "_flows_0", "_flows_1",
293+
mask_filters = ["_cp_output", "_flows", "_flows_0", "_flows_1",
294294
"_flows_2", "_cellprob", "_masks", mask_filter]
295295
image_names = []
296296
if imf is None:
@@ -427,7 +427,7 @@ def load_images_labels(tdir, mask_filter="_masks", image_filter=None,
427427
labels = []
428428
k = 0
429429
for n in range(nimg):
430-
if (os.path.isfile(label_names[n]) or
430+
if (os.path.isfile(label_names[n]) or
431431
(flow_names is not None and os.path.isfile(flow_names[0]))):
432432
image = imread(image_names[n])
433433
if label_names is not None:
@@ -478,7 +478,7 @@ def masks_flows_to_seg(images, masks, flows, file_names, diams=30., channels=Non
478478
Can be list output (run on multiple images) or single output (run on single image).
479479
480480
Saved to file_names[k]+"_seg.npy".
481-
481+
482482
Args:
483483
images (list): Images input into cellpose.
484484
masks (list): Masks output from Cellpose.eval, where 0=NO masks; 1,2,...=mask labels.
@@ -584,7 +584,7 @@ def save_rois(masks, file_name, multiprocessing=None):
584584
Args:
585585
masks (np.ndarray): masks output from Cellpose.eval, where 0=NO masks; 1,2,...=mask labels
586586
file_name (str): name to save the .zip file to
587-
587+
588588
Returns:
589589
None
590590
"""
@@ -636,7 +636,7 @@ def save_masks(images, masks, flows, file_names, png=True, tif=False, channels=[
636636
save_txt (bool, optional): Save masks as list of outlines for ImageJ. Defaults to False.
637637
save_mpl (bool, optional): If True, saves a matplotlib figure of the original image/segmentation/flows. Does not work for 3D.
638638
This takes a long time for large images. Defaults to False.
639-
639+
640640
Returns:
641641
None
642642
"""
@@ -753,4 +753,4 @@ def save_masks(images, masks, flows, file_names, png=True, tif=False, channels=[
753753
imsave(os.path.join(flowdir, basename + "_flows" + suffix + ".tif"),
754754
(flows[0] * (2**16 - 1)).astype(np.uint16))
755755
#save full flow data
756-
imsave(os.path.join(flowdir, basename + '_dP' + suffix + '.tif'), flows[1])
756+
imsave(os.path.join(flowdir, basename + '_dP' + suffix + '.tif'), flows[1])

0 commit comments

Comments
 (0)