hall3

Contents

read image

small_area = 500;
rgb = imread('img5.jpg');
sz = size(rgb)
if length(sz)>2
    g = im2double(rgb2gray(rgb));
else
    g = im2double(rgb);
end
imshow(rgb);
sz =

         960        1280           3

Warning: Image is too big to fit on screen; displaying
at 50% 
black = g<0.3;
imshow(black);
Warning: Image is too big to fit on screen; displaying
at 50% 
white = (g>0.5);
imshow(white);
Warning: Image is too big to fit on screen; displaying
at 50% 
se1 = strel('square',7);
b1 = imdilate(black,se1);
w1 = imdilate(white,se1);
bw1 = w1&b1;
bw2 = bwareaopen(bw1,small_area);

imshow(bw2);
Warning: Image is too big to fit on screen; displaying
at 50% 
CC = bwconncomp(bw2);
disp(CC);
L = labelmatrix(CC);
imshow(label2rgb(L));
    Connectivity: 8
       ImageSize: [960 1280]
      NumObjects: 5
    PixelIdxList: {1x5 cell}

Warning: Image is too big to fit on screen; displaying
at 50% 
s = regionprops(CC,'Image','FilledImage','Area','EulerNumber');
areas = [s.Area];
[maxarea idx] = max(areas);
imshow(s(idx).Image);
bw3 = s(idx).FilledImage&~s(idx).Image;
bw4 = bwareaopen(bw3,small_area);
CC2 = bwconncomp(bw4);
L2 = labelmatrix(CC2);
imshow(label2rgb(L2));
s2 = regionprops(CC2,'Area','Centroid');

area = cat(1,s2.Area);
fprintf('number of squares %d\n',length(area));
fprintf('max area %d min area %d\n',max(area),min(area));
fprintf('Euler %d\n',-s(idx).EulerNumber);
number of squares 33
max area 2416 min area 946
Euler 34
pts = reshape([s2.Centroid],2,length(s2));

plot(pts(1,:),pts(2,:),'ko');
hold off
axis ij
axis equal
grid
rgbm = label2RGB(L,'jet','k');
mask = min(rgbm,[],3)==0;
gm = g.*mask;
rgbn = cat(3,gm,gm,gm)+im2double(rgbm);
imshow(rgbn);
Warning: Could not find an exact (case-sensitive) match
for 'label2RGB'.
C:\Program
Files\Matlab\R2010a\toolbox\images\images\label2rgb.m is
a case-insensitive match and will be used instead.
You can improve the performance of your code by using
exact
name matches and we therefore recommend that you update
your
usage accordingly. Alternatively, you can disable this
warning using
warning('off','MATLAB:dispatcher:InexactCaseMatch').
This warning will become an error in future releases. 
Warning: Image is too big to fit on screen; displaying
at 50%