Spaces:
Sleeping
Sleeping
Commit ·
9754079
1
Parent(s): c39487a
add watershed
Browse files104 unmodified lines10510610710810911061 unmodified lines172173174175176177178104 unmodified linescompactness=0.00001,sigma=1,)else:raise ValueError("algorithm should be kmeans, felzenszwalb or slic")print("Done")61 unmodified lineswith gr.Row():with gr.Column():image_input = gr.Image(label="Input Image")algorithm = gr.Radio(['KMeans', 'Felzenszwalb', 'SLIC'], label="Algorithm", value="SLIC")scale = gr.Slider(0.1, 1.0, 0.5, label="Scale")run_button = gr.Button("Run")with gr.Column():104 unmodified lines10510610710810911011111211311411511611711811912012112212312461 unmodified lines186187188189190191192104 unmodified linescompactness=0.00001,sigma=1,)elif algorithm == 'watershed':from skimage.segmentation import watershedfrom skimage.feature import peak_local_maxfrom scipy import ndimage as ndisobel = busam.sobel_from_pred(pred, size)sobel = sobel.cpu().numpy() if isinstance(sobel, torch.Tensor) else sobel# contrast stretch sobel with 5% largestsobel = np.clip(sobel / np.percentile(sobel, 95), 0, 1)distance = ndi.distance_transform_edt(sobel < 1) # distance to the borderscoords = peak_local_max(distance, min_distance=int(1+100*scale), labels=sobel<1)mask = np.zeros(sobel.shape, dtype=bool)mask[tuple(coords.T)] = Truemarkers, _ = ndi.label(mask)labels = watershed(sobel, markers)else:raise ValueError("algorithm should be kmeans, felzenszwalb or slic")print("Done")61 unmodified lineswith gr.Row():with gr.Column():image_input = gr.Image(label="Input Image")algorithm = gr.Radio(['KMeans', 'Felzenszwalb', 'SLIC', 'Watershed'], label="Algorithm", value="SLIC")scale = gr.Slider(0.1, 1.0, 0.5, label="Scale")run_button = gr.Button("Run")with gr.Column():
app.py+15-1