Hizyan Hanum Hi
Murk Hassan Memon Hi
let me try answer your question.
If you want me to further develop any specific part of my answer just let me know.
If find it useful please mark it as Accepted Answer, thanks in advance:
1.
Capture
A=imread('sample1.jpg');
title('initial image');
2.
sometimes the variance between RGB layers shows a clear boundary
figure(5);varA=surf(var(double(A),0,3));
.
B=varA.CData;
B(B<1000)=0;
B(B>=1000)=255;
figure(6);imshow(B)
.
3.
RGB split
Because with the variance the cells look 'dehydrated', the RGB split shows
ColorList={'Red' 'Green' 'Blue'};
N=255;gr=0:1/(N-1):1;
figure(1);imshow(A);
cMap=zeros(N,3);cMap(:,1)=gr;
figure(2);hr=imshow(ind2rgb(A(:,:,1),cMap));title(ColorList{1});
cMap=zeros(N,3);cMap(:,2)=gr;
figure(3);hg=imshow(ind2rgb(A(:,:,2),cMap));title(ColorList{2});
cMap=zeros(N,3);cMap(:,3)=gr;
figure(4);hb=imshow(ind2rgb(A(:,:,3),cMap));title(ColorList{3});
C=hg.CData;
figure(7);imshow(C);
C=C(:,:,2);C=255*C;
C(C>150)=255;
C(C<150)=0;
figure(8);imshow(C);
.
4.
total area, in pixels
area in pixels
numel(nonzeros(~C))
=
6172
same as
[cx,cy]=find(~C);
numel(cx)
=
6172
in percentage
100*numel(nonzeros(~C))/numel(C)
=
3.106815664955200
there is a 3.1% are of red tagged cells
5.
and following the MATLAB example using RGB to L*a*b and K-means clustering
A=imread('sample1.jpg');
figure(1);imshow(A)
cform = makecform('srgb2lab');
lab_he = applycform(A,cform);
ab = double(lab_he(:,:,2:3));
nrows = size(ab,1);
ncols = size(ab,2);
ab = reshape(ab,nrows*ncols,2);
nColors = 3;
[cluster_idx, cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean', 'Replicates',3);
pixel_labels = reshape(cluster_idx,nrows,ncols);
figure(2);imshow(pixel_labels,[]), title('image labeled by cluster index');
segmented_images = cell(1,3);
rgb_label = repmat(pixel_labels,[1 1 3]);
for k = 1:nColors
color = A;
color(rgb_label ~= k) = 0;
segmented_images{k} = color;
end
figure(3);imshow(segmented_images{1}), title('objects in cluster 1');
figure(4);imshow(segmented_images{2}), title('objects in cluster 2');
. If the tagging has caught all the cells of interest and only the cells of interest (assuming the small specks do not contain red tagging) then a more accurate area percentage would be
C=segmented_images{2};
C1=C(:,:,1);imshow(C1)
C1(C1>100)=255;C1(C1<100)=0;
100*numel(nonzeros(C1))/numel(C1)
=
2.281787979462398
thanks for time and attention, any feedback welcome awaiting answer
John BG