This page is optimized for mobile devices, if you would prefer the desktop version just click here

Segmentation

the real segmentation

clear

% folder containing images

folder = 'pics\Cropped Feature Test Pics\';

celltype = {'neutrophil'

'monocyte'

'lymphocyte'

'eosinophil'

'basophil'};

for j = 1:5

for i = 1:5

% filename of relevant pictures

pic = strcat(folder, celltype{j}, '_', num2str(i), '.tif');

picf = imread(pic);

[AAfilnuc Afin] = trial3(picf,1);

figure(10+j)

subplot(2,3,i)

%figure(10*j+i)

%clf

% saves matrix containing picture values to text file

%dlmwrite(strcat(folder, celltype{j},num2str(i), '_nucleus', 'bw'),AAfilnuc)

% saves image; change AAfilnuc (crop) to Afin (composite)

imwrite(AAfilnuc,strcat(folder, celltype{j},num2str(i), '_nucleus', 'crop.bmp'))

imshow(Afin)

[AAfilcell Afin] = trial3(picf,4);

figure(15+j)

subplot(2,3,i)

%figure(10*j+i+5)

%clf

% saves matrix containing picture values to text file

%dlmwrite(strcat(folder, celltype{j},num2str(i), '_cell', 'bw'),AAfilcell)

% saves image; change AAfilnuc (crop) to Afin (composite)

imwrite(AAfilcell,strcat(folder, celltype{j},num2str(i), '_cell', 'crop.bmp'))

imshow(Afin)

%figure(20+j)

%subplot(2,3,i)

%AAfilcomp =times(AAfilcell,AAfilnuc);

%Afin =times(AAfilcomp,picf(:,:,2));

%imshow(Afin)

end

end

figure(1)

close

figure(2)

close

figure(3)

close

figure(4)

close

figure(5)

close

figure(6)

close

function [AAfil Afin] = trial3(pic,cellnuc)

A = pic;

A1=A(:,:,1);%red,not very informative

A2=A(:,:,2);%green, the channel that we're using

A3=A(:,:,3);%blue, not very informative

figure(1)

imshow(A2)

h = uint8(ones(2,2));

%imshow(A1)%red, not using

figure(2)

imshow(A2)%greenchannel

figure(3)

%imshow(A3)%blue,not using

thresh=multithresh(A2,5);%use autothresholding to get the threshold value.

thresh = thresh(cellnuc); %thresh(1) for nucleus; thresh(2) for cell

%separate red blood cell from the white blood cells

AA=A2<thresh;%get the WBC into bright, RBC into black

imshow(AA) %show the binary image

x = 50;

nm = size(A2);

SE=strel('disk',10,0);

B = regionprops(AA, 'Centroid','PixelIdxList');

for i = 1:length(B);

if B(i).Centroid(1)<x || B(i).Centroid(2)<x || B(i).Centroid(1)>nm(1) - x || B(i).Centroid(2)>nm(2) - x

AA(B(i).PixelIdxList)=0;

imshow(AA)

end

end

AAfill = imfill(AA, 'holes'); %fill the holes in the image

%function extra_jw

%figure(4), imshow(AAfill);

SE=strel('disk',10,0);%use disk to dilate the image. the radius should be

%modified to a smaller value so that no extra stuff is included out of the

figure(4)

clf

AAfil=bwareaopen(AAfill,2); %delete the pixel clusters that have less than 2

%pixels in the image

%replace B6 with AAfil to use picture instead of differential

Bfil=imclose(AAfil,SE);%use the same disk size to get closed image

if sum(sum(Bfil))<2000

Bfil = imclose(AAfill,SE);

end

% deletes objects with centroid within distance x from border

x = 50;

nm = size(A2);

%for i = 1:10 % erode and dilate to smoothen (for whole cell only)

Bfil = imerode(Bfil,SE);

B = regionprops(Bfil, 'Centroid','PixelIdxList');

for i = 1:length(B);

if B(i).Centroid(1)<x || B(i).Centroid(2)<x || B(i).Centroid(1)>nm(1) - x || B(i).Centroid(2)>nm(2) - x

Bfil(B(i).PixelIdxList)=0;

imshow(Bfil)

end

end

Bfil = imdilate(Bfil,SE);

%end

figure(5)

imshow(Bfil)

AAfil=uint8(Bfil);

Afin=times(AAfil,A2);%extract from original image

%Afin = AAfil*255;

figure(6)

imshow(Afin)

end

<< Chapter < Page Page > Chapter >>

Read also:

OpenStax, Automatic white blood cell classification using svm and neural networks. OpenStax CNX. Dec 16, 2015 Download for free at http://legacy.cnx.org/content/col11924/1.5
Google Play and the Google Play logo are trademarks of Google Inc.
Jobilize.com uses cookies to ensure that you get the best experience. By continuing to use Jobilize.com web-site, you agree to the Terms of Use and Privacy Policy.