Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

## Area of Instance Segmented Object Using Yolov8 instance model #12907

Open
1 task done
divyvijay opened this issue May 20, 2024 · 1 comment
Open
1 task done

## Area of Instance Segmented Object Using Yolov8 instance model #12907

divyvijay opened this issue May 20, 2024 · 1 comment
Labels
question Further information is requested

Comments

@divyvijay
Copy link

Search before asking

Question

Hi, I need to find out the area of the instance segmented object using the Yolov8 instance model. Is there any way to figure out using yolo models? I perfectly trained my model to predict the object, but I am having difficulties calculating the area of the predicted object. Also how to get the mask from the results.All I get the cropped imaged along with labels.

predicted
1

Additional

No response

@divyvijay divyvijay added the question Further information is requested label May 20, 2024
@glenn-jocher
Copy link
Member

@divyvijay hi there! 👋

To calculate the area of an instance-segmented object using a YOLOv8 instance model, you can utilize the segmentation masks that the model provides. Here's a quick guide on how to extract the mask and compute the area:

  1. Extract the Mask: After running inference, the Results object will contain a masks attribute if your model supports segmentation. You can access it like this:

    results = model(source)  # source can be an image or video frame
    masks = results.masks  # This will give you the segmentation masks
  2. Calculate the Area: You can calculate the area of the segmented object by summing up the pixels in the mask:

    # Assuming `masks` is not empty and you're interested in the first detected object
    object_mask = masks[0].numpy()  # Convert to numpy array if not already
    area = object_mask.sum()  # Each '1' in the mask represents a pixel in the original image
    print(f"Area of the segmented object: {area} pixels")

This should give you the area of your segmented object in terms of pixel count. If you need the area in physical units (like square cm), you'll need to know the scaling factors from pixels to real-world units based on your specific setup.

Hope this helps! Let us know if you have any more questions. 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants