#python #arrays #pandas #numpy
#python #массивы #панды #numpy
Вопрос:
Я пытаюсь получить область сегментированного объекта в пикселях. У меня есть координаты / углы (xmin, ymin, xmax, ymax) ограничивающей рамки и общая площадь ограничивающей рамки, но я намерен получить область instance_segmentation внутри рамки.
то есть
У меня есть общая площадь трех ограничивающих рамок, но я просто хочу светло-синюю (instance_segmentation) область рамки.
Вот как я вычисляю значения с помощью модели Mask-RCNN:
num_detections, detection_boxes, detection_classes, detection_scores,detection_masks, image_info = session.run(
['NumDetections:0', 'DetectionBoxes:0', 'DetectionClasses:0',
'DetectionScores:0', 'DetectionMasks:0', 'ImageInfo:0'],
feed_dict={'Placeholder:0': np_image_string})
num_detections = np.squeeze(num_detections.astype(np.int32), axis=(0,))
detection_boxes = np.squeeze(detection_boxes * image_info[0, 2], axis=(0,))[0:num_detections]
detection_scores = np.squeeze(detection_scores, axis=(0,))[0:num_detections]
detection_classes = np.squeeze(detection_classes.astype(np.int32), axis=(0,))[0:num_detections]
instance_masks = np.squeeze(detection_masks, axis=(0,))[0:num_detections]
ymin, xmin, ymax, xmax = np.split(detection_boxes, 4, axis=-1)
processed_boxes = np.concatenate([xmin, ymin, xmax - xmin, ymax - ymin], axis=-1)
bounding_box_area = (xmax - xmin) * (ymax - ymin)
segmentations = coco_metric.generate_segmentation_from_masks(instance_masks, processed_boxes, height, width)
image_area = width * height
proportion_bounding_box = (bounding_box_area / image_area)*100
Я сохраняю значения в виде фрейма данных в файле csv, переменная instance_mask
хранит массив numpy instance_segmentation
( Segmentation_pixels
столбца), т.е.:
Bounding_box_area Proportion_bounding_box_0_100 Segmentation_pixels
1642.33129882812 0.534613053003947 [4.7484040e-04 4.5633316e-04 1.6710162e-04 2.3344159e-04 2.5755167e-04 4.6265125e-04 7.6070428e-04 1.3544559e-03 2.2647083e-03 3.2545626e-03 4.5210123e-03 5.7159960e-03 9.2931092e-03 1.2325466e-02 2.2079408e-02 3.1557649e-02 4.6984404e-02 5.9772372e-02 8.7075949e-02 9.9743545e-02 1.4587429e-01 1.9804722e-01 2.8083831e-01 3.3062115e-01 3.5633999e-01 2.6223928e-01 1.0667321e-01 4.3513060e-02]
Есть ли способ вычислить площадь сегментированного объекта с помощью массива numpy?
Любые предложения будут очень оценены
Комментарии:
1. Я думаю, у вас есть какая-то (двоичная) маска для каждого обнаруженного объекта, не так ли? Посмотрите на функцию count_nonzero от NumPy и примените ее к вашим (двоичным) маскам, тогда вы должны получить желаемое количество пикселей.
2.@Geovani Бенита использовать
opencv
area = cv2.contourArea(contour)