def save_timepoint_as_tiff(dask_array, idx): # write your saving code here writer = OmeTiffWriter( f"//allen/aics/animated-cell/Dan/LLS2/T{idx}.ome.tif", overwrite_file=True) imgdata = dask_array.compute() writer.save(imgdata, dimension_order="CZYX")
img_rna_smooth = image_smoothing_gaussian_3d(imgs_rna[i], sigma=1) s3_param = [[1, 0.75*t_spots[i]], [2, 0.75*t_spots[i]]] print('Identifying spots...') bw = dot_3d_wrapper(img_rna_smooth, s3_param) # watershed minArea = 4 Mask = morphology.remove_small_objects(bw>0, min_size=minArea, connectivity=1, in_place=False) labeled_mask = measure.label(Mask) print('Performing watershed segmentation...') peaks = feature.peak_local_max(imgs_rna[i],labels=labeled_mask, min_distance=2, indices=False) Seed = morphology.binary_dilation(peaks, selem=morphology.ball(1)) Watershed_Map = -1*distance_transform_edt(bw) seg = morphology.watershed(Watershed_Map, measure.label(Seed), mask=Mask, watershed_line=True) seg = morphology.remove_small_objects(seg>0, min_size=minArea, connectivity=1, in_place=False) print('Exporting mask...') outname = img_name + '_mask^' + g + '.tiff' p_out = os.path.join(outdir, 'masks', outname) seg = seg > 0 out=seg.astype(np.uint8) out[out>0]=255 writer = OmeTiffWriter(p_out, overwrite_file=True) writer.save(out) # output animation print('Exporting animation...') anim_name = img_name + '_mask^' + g + '.gif' su.animate_zstacks([imgs_rna[i].transpose(1,2,0), seg.astype(int).transpose(1,2,0)], vmax=[0.2, 1], gif_name=os.path.join(outdir, 'anim', anim_name))