Spaces:
Sleeping
Sleeping
Update app.py
Browse files69 unmodified lines707172737475767716 unmodified lines9495969798991001011025 unmodified lines10810911011111211311410 unmodified lines12512612712812913013113213313439 unmodified lines17417517617717817918018118269 unmodified linesreturn [int(x1 * width), int(y1 * height), int(x2 * width), int(y2 * height)]def visualize_and_analyze(image, labels_fused, boxes_fused, scale_bar_length_nm, scale_bar_pixels,class_colors, class_labels):if 5 not in labels_fused:st.markdown("""<div style="16 unmodified linesheight, width, _ = image.shapeimage1 = image.copy()for i in range(len(boxes_fused)):box = denormalize_box(boxes_fused[i], width, height)label = labels_fused[i]color = class_colors.get(label, (255, 255, 255))cv2.rectangle(image, (box[0], box[1]), (box[2], box[3]), color, 3)5 unmodified lines# Histogramme de confiancesphere_scores = [s for l, s in zip(labels_fused, scores_fused) if l == 5]fig, ax = plt.subplots(figsize=(10, 6))mean_score = np.mean(sphere_scores)std_dev = np.std(sphere_scores)10 unmodified linesif scale_bar_pixels:pixel_to_nm = scale_bar_length_nm / scale_bar_pixelsobject_sizes_nm = {cls: [] for cls in set(labels_fused) if cls != 4}for i, label in enumerate(labels_fused):if label != 4:x1, y1, x2, y2 = denormalize_box(boxes_fused[i], width, height)dim = ((x2 - x1) + (y2 - y1)) / 2 * pixel_to_nmobject_sizes_nm[label].append(dim)39 unmodified linesimage = np.array(Image.open(uploaded_file))image_name = os.path.splitext(uploaded_file.name)[0]message, labels_fused, boxes_fused, scale_bar_pixels = app.process(image, image_name, scale_bar_length_nm, thresh)if message:st.warning(message)else:visualize_and_analyze(image, labels_fused, boxes_fused, scale_bar_length_nm, scale_bar_pixels, class_colors, class_labels)69 unmodified lines707172737475767716 unmodified lines9495969798991001011025 unmodified lines10810911011111211311410 unmodified lines12512612712812913013113213313439 unmodified lines17417517617717817918018118269 unmodified linesreturn [int(x1 * width), int(y1 * height), int(x2 * width), int(y2 * height)]def visualize_and_analyze(image, labels, boxes, scale_bar_length_nm, scale_bar_pixels,class_colors, class_labels):if 5 not in labels:st.markdown("""<div style="16 unmodified linesheight, width, _ = image.shapeimage1 = image.copy()for i in range(len(boxes)):box = denormalize_box(boxes[i], width, height)label = labels[i]color = class_colors.get(label, (255, 255, 255))cv2.rectangle(image, (box[0], box[1]), (box[2], box[3]), color, 3)5 unmodified lines# Histogramme de confiancesphere_scores = [s for l, s in zip(labels, scores) if l == 5]fig, ax = plt.subplots(figsize=(10, 6))mean_score = np.mean(sphere_scores)std_dev = np.std(sphere_scores)10 unmodified linesif scale_bar_pixels:pixel_to_nm = scale_bar_length_nm / scale_bar_pixelsobject_sizes_nm = {cls: [] for cls in set(labels) if cls != 4}for i, label in enumerate(labels):if label != 4:x1, y1, x2, y2 = denormalize_box(boxes[i], width, height)dim = ((x2 - x1) + (y2 - y1)) / 2 * pixel_to_nmobject_sizes_nm[label].append(dim)39 unmodified linesimage = np.array(Image.open(uploaded_file))image_name = os.path.splitext(uploaded_file.name)[0]message, labels, boxes, scale_bar_pixels = app.process(image, image_name, scale_bar_length_nm, thresh)if message:st.warning(message)else:visualize_and_analyze(image, labels, boxes, scale_bar_length_nm, scale_bar_pixels, class_colors, class_labels)
app.py+11-11