
function [circles] = circleDetect(capture1)
    capture = rgb2gray(capture1);

    level = graythresh(capture);
    disp(level)
    capture_bw = im2bw(capture,level);
    capture_bw = 1 - capture_bw;

    image = bwlabel (capture_bw);
    [height, width] = size(image);

    Properties = regionprops (image, 'BoundingBox');
    NumberOfBoxes = size(Properties,1);
    figure;
    imshow(capture1);
    i=1;
    for k = 1:NumberOfBoxes
        Box = Properties(k).BoundingBox;
      if ((Box(3) >= Box(4)*0.9 && Box(4) >= Box(3)*0.9) ||(Box(4) >= Box(3)*0.5)) && Box(4) > height * 0.1 && Box(4) < height * 0.6;
         
            rectangle('Position', [Box(1), Box(2), Box(3), Box(4),],...
                            'EdgeColor', 'r', 'LineWidth', 1.5);

            circles{i} = imcrop(capture1,Box);
%            figure;
%            imshow(circles{i});
            

            [width1, height1,z] = size(circles{i});
            if (height1/width1)>0.4
                centerX= width1/2
                centerY= height1/2

                if(height1> width1)
                    rad = width1/2;
                else
                    rad = height1/2;
                end

                rad = rad*0.94;

                for x= 1:Box(4)
                    for y=1:Box(3)
                        D = sqrt((x-centerX) .^ 2 + (y-centerY) .^ 2);

                        if (D > rad)
                            circles{i}(x,y,:)= 0;
                        end
                    end

                end
%                figure;
%                imshow(circles{i});
                i=i+1;
            end
        end
    end
end