Effacer les filtres
Effacer les filtres

How to find the Area for irregular shape in particular region of image?

36 vues (au cours des 30 derniers jours)
Gowtham
Gowtham le 14 Fév 2023
Commenté : DGM le 20 Fév 2023
I Need to find the area of the water body in this image
  1 commentaire
DGM
DGM le 20 Fév 2023
If you want to save images without losing information, save them using imwrite(), not by creating screenshots or by saving the figure (which is essentially a screenshot).

Connectez-vous pour commenter.

Réponses (2)

Jinal
Jinal le 17 Fév 2023
Hey Gowtham,
I understand that you wish to find the area of the regions covered by water body in the image you have provided.
You can do this by creating a mask (a b&w image) of the given image such that the regions covered by the water body are the objects in focus i.e. the waterbody covered regions will be white while the rest of the image region will be black.
Once you have the mask in the form of a binary image, the area of the regions covered by the waterbody can be calculated using regionprops function. The code for the same is as follows:
props = regionprops(maskbinaryimage, 'Area');
area = [props.Area];
To create the mask of an image you can use the Graph Cut feature in Image Segmenter. To access the Image Segmenter app you will require the Image Processing Toolbox (can be installed using MATLAB Get Add-Ons feature).
After loading the image in MATLAB Workspace, you will be required to open the Image Segmenter app from the Apps tab, under Image Processing and Computer Vision section. You can also open the app using the command : imageSegmenter(image);
Next, follow the steps provided here to create the mask.
After creating the mask save it by clicking Export. This will create two variables –
  1. Mask image data as an array
  2. Mask binary image as a logical array
Pass the binary image (logical array) to regionprops function in order to calculate the required area.
Hope this helps.
  2 commentaires
Gowtham
Gowtham le 17 Fév 2023
i=im2gray(h);
grayImage = i;
uniqueGrayLevels = unique(grayImage(:));
for k = 1:length(uniqueGrayLevels)
thisGrayLevel = uniqueGrayLevels(k);
mask = grayImage == thisGrayLevel;
imshowpair(grayImage, mask)
impixelinfo;
pixelCount = nnz(mask);
% Identify the separate regions' areas.
props = regionprops(mask, 'Area');
allAreas = [props.Area];
caption = sprintf('\nFor Gray Level %d, there are a total of %d pixels in %d regions.', thisGrayLevel, pixelCount, length(allAreas));
title(caption, 'FontSize', 15);
for r = 1 : length(allAreas)
fprintf(' For region %d of graylevel %d, there are %d pixels.\n', r, thisGrayLevel, allAreas(r));
end
pause(0.25)
end
uniqueGrayLevels; % Show again in the command window.
Gowtham
Gowtham le 17 Fév 2023
hi jinal
If this code correct . Can you please check it

Connectez-vous pour commenter.


Image Analyst
Image Analyst le 17 Fév 2023
This looks like a pseudocolored image. Can you attach the original grayscale image(s)?
Then I'd determine the proper threshold using my interactive tool:
If (unfortunately) all you have is the pseudocolored image, I'd use the Color Thresholder on the Apps tab of the tool ribbon to find a mask based on color. Then you can use other functions like bwareafilt(), bwareaopen(), and imfill() to clean up the mask based on the color segmentation alone and get rid of non-water regions that got picked up just because they're the same color.
  2 commentaires
Gowtham
Gowtham le 19 Fév 2023
This is the original grayscale image
Image Analyst
Image Analyst le 20 Fév 2023
How do you know which pixels are water? Just by intensity? Do you want to say that all pixels darker than some gray level are water?
It's a generic, general purpose demo of how to threshold an image to find blobs, and then measure things about the blobs, and extract certain blobs based on their areas or diameters.

Connectez-vous pour commenter.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by