calculate area and parameter cell
Ältere Kommentare anzeigen
i have sputum image. after segmentation, i need to count the area and parameter. this is my coding. after that i dont know how to start calculate area of my image.please help me
%get image from file
image = imread ('C:\Users\acer\Pictures\USM16.jpg');
image1 =image;
figure(1),subplot(3,3,1),imshow(image1),title('original image');
%to grayscale
red=image1(:,:,1);
green=image1(:,:,2);
blue=image1(:,:,3);
image_gray = rgb2gray(image);
figure (1),subplot (3,3,2), imshow(image_gray), title('grayscale');
%tobinary
level = graythresh(image_gray);
BW = im2bw (image_gray,level);
figure(1),subplot(3,3,3),imshow(BW), title('binary');
%closing
se = strel('disk',10);
afterclosing = imclose(BW,se);
figure(1), subplot (3,3,4), imshow(afterclosing), title('closing');
%opening
afteropen = imopen(afterclosing,se);
figure(1), subplot (3,3,5),imshow(afteropen), title('opening');

Akzeptierte Antwort
Weitere Antworten (4)
Image Analyst
am 15 Mär. 2015
See my Image Segmentation Tutorial http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862 and you'll know how to do things like:
labeledImage = bwlabel(afteropen);
measurements = regionprops(labeledImage, 'Area', 'Perimeter');
allAreas = [measurements.Area];
allPerimeters = [measurements.Perimeters];
4 Kommentare
Image Analyst
am 15 Mär. 2015
By the way, don't call your variable image since that is the name of a built in function. By the way, there are other problems with your code. You don't do anything with image1, red, blue, or green. You convert the image to gray scale. You use graythresh() and im2bw - not good unless you know for certain that there are a significant number of red cells in the picture. It's better to use a fixed threshold. That will work for any amount of red cells from 0% to 100% area fraction of red cells.
Looks like you're trying to smooth the boundaries with a single pass of an alternating sequential filter You can also use activecontour() for that - demo attached.
izyan hanum
am 16 Mär. 2015
Image Analyst
am 16 Mär. 2015
I gave you a full script in your duplicate question.
izyan hanum
am 17 Mär. 2015
murk hassan memon
am 10 Feb. 2017
0 Stimmen
I want code for the infected cells from blood sample images if any one have any idea regarding this topic then kindly help me out
Natalia Matviychuk
am 27 Dez. 2019
0 Stimmen
Anyone knows how to calculate the cytoplasm area (all area- nucleus area)??
Help me please
3 Kommentare
Image Analyst
am 27 Dez. 2019
Did you try the image segmentation tutorial in my answer? If not, why not? It shows you how to use regionprops to measure areas.
Natalia Matviychuk
am 28 Dez. 2019
Yes, the tutorial is very nice, I understand how to measure all area of the coin but I wanted to measure a cytoplasm area(not all area of the cell). For example i have this image, and I need to measure the grey area

Image Analyst
am 28 Dez. 2019
I think you didn't try to adjust the thresholds, did you? See this code, which produces:
allreas =
3440 3987
% Initialization steps.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 22;
% Check that user has the Image Processing Toolbox installed.
hasIPT = license('test', 'image_toolbox');
if ~hasIPT
% User does not have the toolbox installed.
message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
% User said No, so exit.
return;
end
end
%===============================================================================
% Read in a demo image.
folder = pwd
baseFileName = '37NT.bmp';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
fprintf('This image is RGB. I will change it to gray scale.\n');
grayImage = grayImage(:, :, 2);
end
% Display the original image.
subplot(1, 2, 1);
imshow(grayImage);
axis('on', 'image');
caption = sprintf('Original Image : "%s"', baseFileName);
title(caption, 'FontSize', fontSize);
impixelinfo;
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0.1, 1, 0.9], ...
'Name', 'Demo by Image Analyst', 'NumberTitle', 'Off');
% Get gray stuff only.
binaryImage = grayImage > 112 & grayImage < 240;
% Display the original image.
subplot(1, 2, 2);
imshow(binaryImage);
axis('on', 'image');
caption = sprintf('Binary Image');
title(caption, 'FontSize', fontSize);
impixelinfo;
% Make area measurements.
props = regionprops(binaryImage, 'Area');
allreas = [props.Area]

Natalia Matviychuk
am 28 Dez. 2019
0 Stimmen
Thank you sooo much! And could you explain me please why did you used values 112 and 240 ?
binaryImage = grayImage > 112 & grayImage < 240;
1 Kommentar
Image Analyst
am 28 Dez. 2019
I just took values that were half way between the gray and black, and the gray and white. I could have just said
binaryImage = grayImage == 235;
but that image didn't look like a read limage - it looked like computer graphics. Perhaps a synthetic image you made up for testing, and if so, a real image would not be just at one single gray level but would have a range of gray levels. So I took a range of gray levels to try to let it work should you ever get a real image. Of course you can adjust those values however you need to.
Kategorien
Mehr zu Image Processing Toolbox finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



