function lab2()

im = imread('d:\comp vision\images\lego2.png');
%show(im);
size(im);
g = rgb2gray(im);
BW = g > 150;  
%show(BW)
BW = ~BW;   % ~ is MATLAB's logical negation operator
%show(BW)
BWL = bwlabel(BW);   % BWL contains the labeled image
%show(BWL)
% imagesc(BWL), colormap(gray), axis image  % You also typically need to
%                                           % specify a colormap to use
%                                           % and the axis display
% ob20 = BWL==20;
% show(ob20, 1)
% pixval on;
% [centroid, thetamin, roundness] = moments(ob20)
% rad2deg(thetamin)

a = rect(70, 100, 100, 100);

size(a)
% show(b);
% pixval on;
% [centroid, thetamin, roundness] = moments([1])
% rad2deg(thetamin)

b = circ(350,170,100);
size(b)
c = rect(200, 500, 200, 50);

size(c)
d = rect(40, 400, 66, 0);

size(d)
e = a + b + c + d;
%e = imrotate(e, 45);
imshow(e)
%pixval on;
 [centroid, thetamin, roundness] = moments(a)
 rad2deg(thetamin)

function deg = rad2deg(rad)
    deg = rad*180/pi;
end

function rectim = rect(xpos, ypos, length, width)
    rectim = zeros(480, 640);
    rectim(xpos:xpos + length, ypos:ypos + width) = 1;
end
    
function circim = circ(xpos, ypos, radii)
    circim = zeros(480, 640);
    circim(xpos - radii: xpos + radii, ypos - radii: ypos + radii) = circularstruct(radii);
end