how to extract the area, perimeter for the object present in the image?
6 次查看(过去 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.
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;
采纳的回答
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:
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!