def update_segmentation(toggle, string, s, h, w, children, mode): if len(children) == 0: labs = labels else: labs = np.asarray(children) mask = parse_jsonstring(string, shape=(height, width)) new_labels = modify_segmentation(labs, mask, img=img, mode=mode) return new_labels
def update_data(string): if string: imageArray = parse_jsonstring(string) imageCropped = imageArray[0:width, 0:height] rescaledImageArray = rescale(imageCropped, (0.14, 0.14)) prediction = predict(rescaledImageArray) else: raise PreventUpdate return "Your number is: " + str(prediction)
def update_segmentation(toggle, string, s, h, w, children, mode): print("updating") if len(children) == 0: labs = labels else: labs = np.asarray(children) with open('data.json', 'w') as fp: json.dump(string, fp) mask = parse_jsonstring(string, shape=(height, width)) new_labels = modify_segmentation(labs, mask, img=img, mode=mode) return new_labels
def update_figure_upload(image, string, h, s, w, algorithm): mask = parse_jsonstring(string, shape=(round(h/s), round(w/s))) if mask.sum() > 0: if image is None: im = img image = img else: im = image_string_to_PILImage(image) im = np.asarray(im) seg = segmentation_generic(im, mask, mode=algorithm) else: if image is None: image = img seg = np.zeros((h, w)) return image_with_contour(image, seg, shape=(round(h/s), round(w/s)))
def update_figure_upload(image, string, h, s, w): mask = parse_jsonstring(string, shape=(round(h / s), round(w / s))) if mask.sum() > 0: if image is None: im = img image = img else: im = image_string_to_PILImage(image) im = np.asarray(im) seg = superpixel_color_segmentation(im, mask) else: if image is None: image = img seg = np.ones((h, w)) fill_value = 255 * np.ones(3, dtype=np.uint8) dat = np.copy(im) dat[np.logical_not(seg)] = fill_value return array_to_data_url(dat)