how to extract the area, perimeter for the object present in the image?
12 ビュー (過去 30 日間)
古いコメントを表示
i m in need to measure the features like area, perimetr , length, width of the segmented image.... when i used bwarea to find area, it calculates the total area of the image but it wont gives the area of the object in the image....my segmented image is attached below....i want area bounded inside the green boundary and red region the image that image i attached.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/145520/image.bmp)
6 件のコメント
Image Analyst
2020 年 3 月 17 日
Deepika, try this:
% This demo takes a pseudo-periodic array of shapes (a chain link fence) and determines the "Average" shape and identifies the one with the closest-to-average shape.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 15;
%--------------------------------------------------------------------------------------------------------
% READ IN IMAGE
folder = pwd;
baseFileName = 'image.jpeg';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
% Read in the image from disk. If storedColorMap is not empty, it's an indexed image with a stored colormap.
[grayImage, storedColorMap] = imread(fullFileName);
if ~isempty(storedColorMap)
grayImage = ind2rgb(grayImage, storedColorMap);
end
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage);
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Use weighted sum of ALL channels to create a gray scale image.
grayImage = rgb2gray(grayImage);
% ALTERNATE METHOD: Convert it to gray scale by taking only the green channel,
% which in a typical snapshot will be the least noisy channel.
% grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the image.
hFig = figure;
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize, 'Interpreter', 'None');
impixelinfo;
hFig.WindowState = 'maximized'; % May not work in earlier versions of MATLAB.
drawnow;
% Display the histogram
subplot(2, 2, 2);
imhist(grayImage);
grid on;
title('Histogram of Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
%--------------------------------------------------------------------------------------------------------
% SEGMENTATION
% Binarize the image
binaryImage = imbinarize(grayImage);
% Display the image.
subplot(2, 2, 3);
imshow(binaryImage, []);
title('Initial Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
axis('on', 'image');
% Take the largest blob (the brain) only.
binaryImage = bwareafilt(binaryImage, 1);
% Fill holes.
binaryImage = imfill(binaryImage, 'holes');
% Erase everything except this from the gray scale image.
grayImage(~binaryImage) = 0;
% Threshold at 175 to get the tumors.
tumorMask = grayImage > 175;
[labeledImage, numBlobs] = bwlabel(tumorMask);
% Let's assign each blob a different color to visually show the user the distinct blobs.
coloredLabels = label2rgb (labeledImage, 'hsv', 'k', 'shuffle'); % pseudo random color labels
% coloredLabels is an RGB image. We could have applied a colormap instead (but only with R2014b and later)
subplot(2, 2, 4);
imshow(coloredLabels);
axis('on', 'image'); % Make sure image is not artificially stretched because of screen's aspect ratio.
caption = sprintf('%d blobs that might be tumors', numBlobs);
title(caption, 'FontSize', fontSize);
drawnow;
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/277755/image.png)
採用された回答
Meshooo
2014 年 9 月 26 日
編集済み: Meshooo
2014 年 9 月 26 日
You should change your image from gray scale image to a binary image (1, 0) before finding the properties that you want. It is clear that your gray scale image has two main levels of intensities (dark gray and bright gray).
Find the threshold of each gray level and then remove the other parts using morphological filters. Once you got your object in binary then find the properties.
Please refer to the following examples from Matlab:
Hope that helps you.
2 件のコメント
Meshooo
2014 年 10 月 1 日
As Image Analyst said, you should fill the image and then find the properties. For example, lets say that the image you provided us of the boundaries is f, then:
I = imfill (f); %this will fill the boundaries of your image
Area_I = regionprops (I, 'Area'); % this will find the area
You can also find other parameters like major axis length and etc.
その他の回答 (3 件)
Sean de Wolski
2014 年 9 月 25 日
I would threshold the output of stdfilt (The background has low variance), call imfill('holes') on the thresholded image and then regionprops to calculate all of your stats.
S = regionprops(imfill(stdfilt(I)>1,'holes'))
Image Analyst
2014 年 9 月 25 日
If you have a segmented image, like you said but did not show, then you CAN use bwarea() or regionprops() to find its area. Please attach the segmented image, not the original image, cropped image, or annotated image like you did, but the actual segmented, binary image. If you just said segmented but really meant cropped and not segmented, then say so. Segmented means you have a binary image telling the difference between foreground objects of interest, and backgrouns.
3 件のコメント
Image Analyst
2014 年 9 月 27 日
That's just the edge - it's not the whole cell segmented. You'd need to call imfill() on that to make it solid then call regionprops to make the measurements. It's all detailed in my Image Segmentation Tutorial in my File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
Walter Roberson
2017 年 3 月 22 日
mithlesh arya comments to sou:
how did u find the boundary of nuclies and cytoplasm...
Asnake Eshetu
2017 年 2 月 20 日
Dear all i am working on thyroid images scanned with SPECT for segmentation and quantification the image is very noise and i am using circular averaging filter with disk radius 3 the segmentation procedure become nice but i have a a problem of quantification to calculate the area of left and right lobes. is their any help on this Thanks
1 件のコメント
Image Analyst
2017 年 2 月 20 日
Attach image files so we can see the images right here in the browser. Come on, make it easy for us to help you. Downloading and saving your fig files, then opening them up in MATLAB just to view them is not as easy. Use the brown and green frame icon:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/186244/image.png)
参考
カテゴリ
Help Center および File Exchange で Image Data Workflows についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!