Skip to content

Commit

Permalink
Update segment_images.py
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeLeGoc committed Jan 13, 2025
1 parent d419a72 commit c161518
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions scripts/segmentation/segment_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import tifffile
from tqdm import tqdm

import cuisto as hq
import cuisto

pd.options.mode.copy_on_write = True # prepare for pandas 3

Expand Down Expand Up @@ -356,9 +356,9 @@ def process_directory(
write_parameters(param_file, parameters, filters, original_pixelsize)

# convert parameters to pixels in probability map
pixelsize = hq.seg.get_pixelsize(images_list[0]) # get pixel size
pixelsize = cuisto.seg.get_pixelsize(images_list[0]) # get pixel size
edge_dist = int(edge_dist / pixelsize)
filters = hq.seg.convert_to_pixels(filters, pixelsize)
filters = cuisto.seg.convert_to_pixels(filters, pixelsize)

# get rescaling factor
rescale_factor = pixelsize / original_pixelsize
Expand Down Expand Up @@ -387,9 +387,9 @@ def process_directory(
img = tifffile.imread(imgpath, key=target_channel)
if (edge_dist > 0) & (len(masks_dir) != 0):
mask = tifffile.imread(os.path.join(masks_dir, geoname + "." + masks_ext))
mask = hq.seg.pad_image(mask, img.shape) # resize mask
mask = cuisto.seg.pad_image(mask, img.shape) # resize mask
# apply mask, eroding from the edges
img = img * hq.seg.erode_mask(mask, edge_dist)
img = img * cuisto.seg.erode_mask(mask, edge_dist)

# image processing
pbar.set_description(f"{geoname}: IP...")
Expand All @@ -401,15 +401,15 @@ def process_directory(
pbar.set_description(f"{geoname}: Segmenting...")

if seg_method == "lines":
collection = hq.seg.segment_lines(
collection = cuisto.seg.segment_lines(
img,
geojson_props,
minsize=filters["length_low"],
rescale_factor=rescale_factor,
)

elif seg_method == "polygons":
collection = hq.seg.segment_polygons(
collection = cuisto.seg.segment_polygons(
img,
geojson_props,
area_min=filters["area_low"],
Expand All @@ -420,7 +420,7 @@ def process_directory(
)

elif seg_method == "points":
collection = hq.seg.segment_points(
collection = cuisto.seg.segment_points(
img,
geojson_props,
area_min=filters["area_low"],
Expand Down

0 comments on commit c161518

Please sign in to comment.