Code covered by the BSD License  

Highlights from
Simple DIP demos

image thumbnail

Simple DIP demos

by

 

03 Sep 2002 (Updated )

Simple DIP demo using MATLAB 6.1, Image Processing Toolbox and NN Toolbox.

[complete_rivets,incomplete_rivets]=project(x)
function [complete_rivets,incomplete_rivets]=project(x)
% Group 4 
% 1. Mohammed Hayder AL Mansoori (GS09507) 
% 2. Soo Mun Yeong (GS08924) 
% 3. Tan Chin Luh (GS11259) 



% Read the image
I=x;
% I = imread ('rivets.bmp');

% dilate the image using 'disk' structure inorder to connect the disconnected components on rivets
% f = strel ('disk', 1, 0);
I2 = I; %imdilate(I, f);

% Labeled the components in dilated image (8-connected)
[labeled,numObjects] = bwlabel(I2,8);

% Get the Area of each components
stats = regionprops(labeled,'Area');
allArea = [stats.Area];

% For the components which area is less than '80', ignore them!
idx = find([stats.Area] > 80);
I3 = ismember(labeled,idx);

% Label and get the Bounding Box for each components in new image
[labeled2,numObjects2] = bwlabel(I3,8);
stats2 = regionprops(labeled2,'BoundingBox','Image');

% Looking for the complete components
for cnt = 1:numObjects2
    temp_pic = stats2(cnt).Image;
    conn = [0 1 0; 1 1 1 ; 0 1 0] ;
    marker = temp_pic;
    idx = cell(1,ndims(temp_pic));
    for k = 1:ndims(temp_pic)
        idx{k} = 2:(size(temp_pic,k) - 1);
    end
    marker(idx{:}) = 1;
    temp_pic2 = imreconstruct((marker == 0), ~temp_pic, conn);
    num(cnt) = sum(sum(temp_pic2 == temp_pic));


%     marker(idx{:}) = 1;
%     temp_pic2 = imcomplement(imreconstruct(imcomplement(marker), imcomplement(temp_pic), conn));
%     num(cnt) = sum(sum(imsubtract(temp_pic2,temp_pic)));
   
end
num = num>80;    

% Create boxes for the components
boxes=[stats2.BoundingBox];
boxes = reshape(boxes,[4,numObjects2])';

% Display the result: Complete components in green boxes. Incomplete components in red boxes
imshow(I,[]);

for cnt = 1:numObjects2
    
    hold on;
    if num(cnt)==1
        rectangle('Position',[boxes(cnt,:)],'edgecolor','g')
    else
        rectangle('Position',[boxes(cnt,:)],'edgecolor','r')
    end
end

complete_rivets = sum(num);
incomplete_rivets = length(num)-complete_rivets;

Contact us