how to classify the leukocytes(WBC) using CNN

6 views (last 30 days)
Keerthi  D
Keerthi D on 23 Apr 2021
Commented: Keerthi D on 26 Apr 2021
my project work deals with classification of WBCs and counting of WBCs. here l am k-means clustering is used to segment the WBCs and extract some features using GLCM(mean,SD,correlation,entropy,energy....etc). after that i want to classify the WBCs into its five categories.for that purpose i decided to use the CNN.so i need a help to classify the WBC Using CNN.please help me through the code.
here is the program that i have done:
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);
% Display the original color image.
%subplot(3, 4, 1);
%imshow(rgbImage);
%title('Original color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
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);
%%subplot(3, 4, 5);
%%imshow(noisyRGB);
%%title('Image with Salt and Pepper Noise', 'FontSize', fontSize);
% 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);
%%subplot(3, 4, 9);
%%imshow(rgbFixed);
%%title('Restored Image', 'FontSize', fontSize);
% 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};
% 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
using BLood smear images:

Answers (1)

Shashank Gupta
Shashank Gupta on 26 Apr 2021
Hi Keerthi,
As far as I understood, you want to use CNN to classify the different WBCs, How about you start with this example link. It will give you an idea on how to implement CNN in such cases. You don't necessarily need to use CNNs, you can also give a try tioSVM to get the classification done. Try exploring different such classification model in MATLAB.
I hope this helps.
Cheers.
  1 Comment
Keerthi  D
Keerthi D on 26 Apr 2021
Sir how to classify the wBC using multi svm? Please provide correct code.

Sign in to comment.

Categories

Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!