-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
400 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import os | ||
import cv2 | ||
|
||
# Set the paths for the input folders | ||
mask_org_folder = "./training_data/masks_nuclei" | ||
images_org_folder = "./training_data/images_nuclei" | ||
|
||
# Set the paths for the output folders | ||
mask_folder = "./training_data/dapi/masks" | ||
images_folder = "./training_data/dapi/images" | ||
|
||
# Create the output folders if they don't exist | ||
os.makedirs(mask_folder, exist_ok=True) | ||
os.makedirs(images_folder, exist_ok=True) | ||
|
||
# Set the ROI size and step | ||
roi_size = (256, 256) | ||
roi_step = 128 | ||
|
||
# Get the list of file names in the mask_org folder | ||
file_names = [file for file in os.listdir(mask_org_folder) if file.lower().endswith(('.tif', '.tiff'))] | ||
|
||
# Iterate over the file names | ||
for file_name in file_names: | ||
# Read the mask image | ||
mask_path = os.path.join(mask_org_folder, file_name) | ||
mask = cv2.imread(mask_path, cv2.IMREAD_GRAYSCALE) | ||
|
||
# Read the corresponding input image | ||
image_path = os.path.join(images_org_folder, file_name) | ||
image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE | cv2.IMREAD_ANYDEPTH) | ||
|
||
# Get the dimensions of the images | ||
mask_height, mask_width = mask.shape[:2] | ||
image_height, image_width = image.shape[:2] | ||
|
||
# Iterate over the ROI positions | ||
for y in range(0, mask_height - roi_size[0] + 1, roi_step): | ||
for x in range(0, mask_width - roi_size[1] + 1, roi_step): | ||
# Extract the ROI from the mask | ||
roi_mask = mask[y:y+roi_size[0], x:x+roi_size[1]] | ||
|
||
# Extract the ROI from the image | ||
roi_image = image[y:y+roi_size[0], x:x+roi_size[1]] | ||
|
||
# Save the ROI as a new image in the mask folder | ||
new_mask_path = os.path.join(mask_folder, f"{file_name}_{y}_{x}.tif") | ||
cv2.imwrite(new_mask_path, roi_mask) | ||
|
||
# Save the ROI as a new image in the images folder | ||
new_image_path = os.path.join(images_folder, f"{file_name}_{y}_{x}.tif") | ||
cv2.imwrite(new_image_path, roi_image) |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"n_dim": 2, "axes": "YXC", "n_channel_in": 1, "n_channel_out": 33, "train_checkpoint": "weights_best.h5", "train_checkpoint_last": "weights_last.h5", "train_checkpoint_epoch": "weights_now.h5", "n_rays": 32, "grid": [2, 2], "backbone": "unet", "n_classes": null, "unet_n_depth": 3, "unet_kernel_size": [3, 3], "unet_n_filter_base": 32, "unet_n_conv_per_depth": 2, "unet_pool": [2, 2], "unet_activation": "relu", "unet_last_activation": "relu", "unet_batch_norm": false, "unet_dropout": 0.0, "unet_prefix": "", "net_conv_after_unet": 128, "net_input_shape": [null, null, 1], "net_mask_shape": [null, null, 1], "train_shape_completion": false, "train_completion_crop": 32, "train_patch_size": [256, 256], "train_background_reg": 0.0001, "train_foreground_only": 0.9, "train_sample_cache": true, "train_dist_loss": "mae", "train_loss_weights": [1, 0.2], "train_class_weights": [1, 1], "train_epochs": 400, "train_steps_per_epoch": 100, "train_learning_rate": 0.0003, "train_batch_size": 4, "train_n_val_patches": null, "train_tensorboard": true, "train_reduce_lr": {"factor": 0.5, "patience": 40, "min_delta": 0}, "use_gpu": false} |
Binary file added
BIN
+22.4 MB
models/dapi/logs/images/events.out.tfevents.1695132333.UU-N9KR2WKWCL.637.0.v2
Binary file not shown.
Binary file added
BIN
+236 KB
models/dapi/logs/train/events.out.tfevents.1695132333.UU-N9KR2WKWCL.637.1.v2
Binary file not shown.
Binary file added
BIN
+474 KB
models/dapi/logs/validation/events.out.tfevents.1695132347.UU-N9KR2WKWCL.637.2.v2
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"prob": 0.46905075238803473, "nms": 0.3} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from __future__ import print_function, unicode_literals, absolute_import, division | ||
import sys | ||
import numpy as np | ||
import matplotlib | ||
matplotlib.rcParams["image.interpolation"] = 'none' | ||
import matplotlib.pyplot as plt | ||
|
||
from glob import glob | ||
from tifffile import imread | ||
from csbdeep.utils import Path, normalize | ||
from csbdeep.io import save_tiff_imagej_compatible | ||
|
||
from stardist import random_label_cmap, _draw_polygons, export_imagej_rois | ||
from stardist.models import StarDist2D | ||
|
||
np.random.seed(6) | ||
lbl_cmap = random_label_cmap() | ||
|
||
X = sorted(glob('./training_data/images_nuclei/*.tif')) | ||
X = list(map(imread,X)) | ||
|
||
n_channel = 1 if X[0].ndim == 2 else X[0].shape[-1] | ||
axis_norm = (0,1) # normalize channels independently | ||
# axis_norm = (0,1,2) # normalize channels jointly | ||
if n_channel > 1: | ||
print("Normalizing image channels %s." % ('jointly' if axis_norm is None or 2 in axis_norm else 'independently')) | ||
|
||
model = StarDist2D(None, name='dapi', basedir='models') | ||
|
||
img = normalize(X[0], 1,99.8, axis=axis_norm) | ||
labels, details = model.predict_instances(img) | ||
|
||
save_tiff_imagej_compatible('example_image.tif', img, axes='YX') | ||
save_tiff_imagej_compatible('example_labels.tif', labels, axes='YX') | ||
export_imagej_rois('example_rois.zip', details['coord']) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.