how to calculate the geometric feature of wBC using matlab

3 views (last 30 days)
hi ,i have worked on classification of WBC(white blood cell) .i have got segmented image of WBC using k-means clustering.after the segmentation i need to extract feature 3 different sets of features including:
geometric feature : area,centroid,circularity,perimeter
statistical features :arithmetic mean,standard deviation, variance,skewness, root mean square...etc
textural features : correlation,energy, entropy, contrast, ..etc
i have got statistical and textural features.
how i will do the geometric features of WBC? please provide me matlab code to find area ,circularity,centroid,and perimeter of a WBC image.
my code :
clc; % Clear command window.
clear; % Delete all variables.
close all; % Close all figure windows except those created by imtool.
imtool close all; % Close all figure windows created by imtool.
workspace; % Make sure the workspace panel is showing.
fontSize = 15;
[filename, pathname] = uigetfile({'*.*';'*.bmp';'*.jpg';'*.gif'}, 'Pick a Leaf Image File');
rgbImage = imread([pathname,filename]);
rgbImage = imresize(rgbImage,[256,256]);
%%image noise removal using median filter
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows columns numberOfColorBands] = size(rgbImage);
set(gcf, 'Position', get(0,'Screensize'));
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Generate a noisy image. This has salt and pepper noise independently on
% each color channel so the noise may be colored.
noisyRGB = imnoise(rgbImage,'salt & pepper', 0.05);
% Extract the individual red, green, and blue color channels.
redChannel = noisyRGB(:, :, 1);
greenChannel = noisyRGB(:, :, 2);
blueChannel = noisyRGB(:, :, 3);
% Median Filter the channels:
redMF = medfilt2(redChannel, [3 3]);
greenMF = medfilt2(greenChannel, [3 3]);
blueMF = medfilt2(blueChannel, [3 3]);
% Find the noise in the red.
noiseImage = (redChannel == 0 | redChannel == 255);
% Get rid of the noise in the red by replacing with median.
noiseFreeRed = redChannel;
noiseFreeRed(noiseImage) = redMF(noiseImage);
% Find the noise in the green.
noiseImage = (greenChannel == 0 | greenChannel == 255);
% Get rid of the noise in the green by replacing with median.
noiseFreeGreen = greenChannel;
noiseFreeGreen(noiseImage) = greenMF(noiseImage);
% Find the noise in the blue.
noiseImage = (blueChannel == 0 | blueChannel == 255);
% Get rid of the noise in the blue by replacing with median.
noiseFreeBlue = blueChannel;
noiseFreeBlue(noiseImage) = blueMF(noiseImage);
% Reconstruct the noise free RGB image
rgbFixed = cat(3, noiseFreeRed, noiseFreeGreen, noiseFreeBlue);
% Enhance Contrast
rgbFixed = imadjust(rgbFixed,stretchlim(rgbFixed));
%image sharpening using Gaussian un-sharp mask
%create unsharp mask
H = padarray(2,[2,2])-fspecial('gaussian',[5 5],2);
% create a sharpened version of the image using that mask
sharpened = imfilter(rgbFixed,H);
%% L*a*b Color Space
%inputImLAB = rgb2lab(scale);
%subplot(1,2,2);
%imshow(inputImLAB);
cform = makecform('srgb2lab');
% Apply the colorform
lab_he = applycform(sharpened,cform);
% Extract a* and b* channels and reshape
ab = double(lab_he(:,:,2:3));
nrows = size(ab,1);
ncols = size(ab,2);
ab = reshape(ab,nrows*ncols,2);
nColors = 4;
[cluster_idx cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean', ...
'Replicates',3);
%[cluster_idx cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean','Replicates',3);
% Label every pixel in tha image using results from K means
pixel_labels = reshape(cluster_idx,nrows,ncols);
%figure,imshow(pixel_labels,[]), title('Image Labeled by Cluster Index');
% Create a blank cell array to store the results of clustering
segmented_images = cell(1,3);
% Create RGB label using pixel_labels
rgb_label = repmat(pixel_labels,[1,1,3]);
for k = 1:nColors
colors = rgbFixed;
colors(rgb_label ~= k) = 0;
segmented_images{k} = colors;
end
figure; subplot(4,1,1);imshow(segmented_images{1});
%title('Cluster 1');
subplot(4,1,2);imshow(segmented_images{2});
%title('Cluster 2');
subplot(4,1,3);imshow(segmented_images{3});
%title('Cluster 3');
subplot(4,1,4);imshow(segmented_images{4});
%title('Cluster 4')
set(gcf, 'Position', get(0,'Screensize'));
% Feature Extraction
x = inputdlg('Enter the cluster no. containing the ROI only:');
i = str2double(x);
% Extract the features from the segmented image
seg_img = segmented_images{i};
%image compression using DCT
% Convert to grayscale if image is RGB
if ndims(seg_img) == 3
img = rgb2gray(seg_img);
end
%figure, imshow(img); title('Gray Scale Image');
%img = rgb2gray(seg_img)
J=dct2(img);
imshow(log(abs(J)),[]);
%colormap parula
%colorbar
J(abs(J)<10) =0;
K= idct2(J);
K=rescale(K);
%montage({I,K})
%title('Orginal Grayscale Image(left) and processed Image(Right)');
% Create the Gray Level Cooccurance Matrices (GLCMs)
glcms = graycomatrix(K);
% Derive Statistics from GLCM
stats = graycoprops(glcms,'Contrast Correlation Energy Homogeneity');
Contrast = stats.Contrast
Correlation = stats.Correlation
Energy = stats.Energy
Homogeneity = stats.Homogeneity
Mean = mean2(seg_img)
Standard_Deviation = std2(seg_img)
Entropy = entropy(seg_img)
%RMS = mean2(rms(seg_img));
%Skewness = skewness(img)
Variance = mean2(var(double(seg_img)))
a = sum(double(seg_img(:)));
Smoothness = 1-(1/(1+a))
Kurtosis = kurtosis(double(seg_img(:)))
Skewness = skewness(double(seg_img(:)))
% Inverse Difference Movement
m = size(seg_img,1);
n = size(seg_img,2);
in_diff = 0;
for i = 1:m
for j = 1:n
temp = seg_img(i,j)./(1+(i-j).^2);
in_diff = in_diff+temp;
end
end
IDM = double(in_diff)
feat_disease = [Contrast,Correlation,Energy,Homogeneity, Mean, Standard_Deviation, Entropy, Variance, Smoothness, Kurtosis, Skewness, IDM];
%%end
data set:
segmented images:

Answers (1)

Clayton Gotberg
Clayton Gotberg on 24 Apr 2021
Try out the regionprops command. Area, centroid, circularity and perimeter are all possible outputs for the function.
stats = regionprops('table',bw,'Centroid',...
'MajorAxisLength','MinorAxisLength');
You need to use black and white images, but since you have found the zones with and without WBCs getting that should not be difficult. For example,
bw_image =true(256); % establish size of black and white matrix
bw_image(colors == 0) = 0; % set area where WBC does not appear to 0
I'm having some trouble interpreting your code so if you can put it in a code block I would appreciate it. I might be able to get a better understanding for what exactly is happening with your erarly image processing.

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!