0

I am using pytorch for image segmentation. I want to calculate the masked area in the segmented picture below. My question is it it possible to calculate the masked area? If so how can i do that.

1

used torchvision. I want to know if there is any way to calculate the masked area of the boat in the segmented picture?

4
  • what do you mean, "calculate"? the areas are right there. you don't calculate them. what more do you need? you could calculate specific information on those areas. you didn't say that though. -- welcome. tour, How to Ask, minimal reproducible example Commented Dec 19, 2022 at 2:56
  • In this image you can clearly see that the model segmented areas representing a boat, a person, and probably the background. To get the same result you need to train an image segmentation model where it can predict for each pixel whether it belongs to one of the known classes. Commented Dec 19, 2022 at 3:01
  • lets say the image is 255*255. Then what portion of the image is Boat . Is there any way i can count the pixels for the boat and determine the area of it compared to the total image. Commented Dec 19, 2022 at 4:08
  • this question looks similar to another question you ask in the future: stackoverflow.com/questions/74936584/… Commented Jan 4, 2023 at 2:12

1 Answer 1

1

Let say you have a predicition output of the same shape as the input of shape [height, width] of type torch.long or torch.int where each element is the class index of its corresponding pixel:

seg_output = ...
BOAT_INDEX = ...

boat_area = torch.sum(seg_output == BOAT_INDEX)
boat_area_propotion = boat_area / (height * width)
Sign up to request clarification or add additional context in comments.

3 Comments

could you please explain further on this. Thanks.
Just compare the output with the index of the "boat" categories, then sum the number of true predicted points to get the area.
Thank you for your generous comment. I am new to this. But I am unsure how to get the index. I am sharing the code link. Could you please help me on this? stackoverflow.com/questions/74936584/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.