clc
imgdata = imread('C:\Users\asus\Desktop\Paper meet 2020\454.jpg');
diff_im = imsubtract(imgdata(:,:,1), rgb2gray(imgdata));
diff_im = medfilt2(diff_im, [3 3]);
diff_im = im2bw(diff_im,0.18);
left_red = bwareaopen(diff_im,300);
bw = bwlabel(left_red, 8);
L_stats = regionprops(bw, 'BoundingBox', 'Centroid');
imshow(left_red)
hold on
for object = 1:length(L_stats)
bb = L_stats(object).BoundingBox;
bc = L_stats(object).Centroid;
rectangle('Position',bb,'EdgeColor','r','LineWidth',2)
plot(bc(1),bc(2), '-m+')
a=text(bc(1)+15,bc(2), strcat('X: ', num2str(round(bc(1))), ' Y: ', num2str(round(bc(2)))));
L_cor(length(L_stats),1)=str2num(num2str(round(bc(1))));
L_cor(length(L_stats),2)=str2num(num2str(round(bc(2)))) ;
set(a, 'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12, 'Color', 'black');
end
hold of