% Morphological operations

A = zeros(256);
A(78:177,103:152) = ones(100,50);
A(191:200,191:200) = ones(10);

B = strel('disk',20);
C = strel('rectangle',[100,50]); 

% Smoothes the corners of the rectangle and deletes the square
D = imopen(A,B);
% Outputs the centre pixel of the rectangle and deletes the square
E = imerode(A,C);

subplot(1,2,1);
imagesc( A )
colormap( gray ( 256 ) )
axis image
subplot(1,2,2);
imagesc( D )
colormap( gray ( 256 ) )
axis image

figure
subplot(1,2,1);
imagesc( A )
colormap( gray ( 256 ) )
axis image
subplot(1,2,2);
imagesc( E )
colormap( gray ( 256 ) )
axis image