BloodknightStudios icon

Untitled

BloodknightStudios | PRO | 04/30/17 08:56:22 PM UTC | 0 ⭐ | 7895 👁️ | Never ⏰ | []
MatLab |

4.26 KB

|

None

|

0 👍

/

0 👎

%% Creator Block
%   Marc Chapman 054888139
 
%% Clear Everything
clc; clear all; close all;
 
%% Load original image
image= imread('TopImg0000.bmp');
 
 
%% Segment tray
 
mask = (image > 3);                                 % Create a dirty mask
 
clean1 = bwareaopen(mask, 50);                      % Removes all objects smaller than specified size
clean2 = imfill(clean1, 'holes');                   % Fills all black holes within the masked part of the image
 
se = strel('disk', 50);                             % sets edge cleaning options
TrayMask = imopen(clean2, se);                      % creates new image using edge cleaning poptions
 
tray=regionprops(TrayMask,'boundingbox');           % Creates a struct of all bounding boxes
TrayFinal=imcrop(image, tray.BoundingBox);          % Crops image based on bounding box
 
%% Segment Label
 
Image=TrayFinal;
 
% Iteratively loop until label is very distinct
% TODO: add some kind of dynamic check so that the loop can autodiscover
%       the level of distinction between label and package
for i=1:3
    Image = imadjust(Image,[0.2 0.8],[]);
end
 
%   Repeat the same processes as for segmenting tray
% TODO: Create a function to make code reuse a practical option
mask = (Image > 30);                               
 
clean1 = bwareaopen(mask, 5000);                    
clean2 = imfill(clean1, 'holes');                   
 
se = strel('disk', 50);                             
LabelMask = imopen(clean2, se);                     
 
label=regionprops(LabelMask,'boundingbox');         
LabelFinal=imcrop(TrayFinal, label.BoundingBox);    
 
%% Segment Information
%   This is an extra task not in the brief, since it was decided 
%   that the label itself contains lots of useless data and it is 
%   in fact the product specific printed parts of the label that
%   are of interest to the User
 
Image=LabelFinal;
 
% loop until label data is clear
% TODO: add some kind of dynamic check so that the loop can autodiscover
%       the level of distinction between label and package
for i=1:7
    Image = imadjust(Image,[0.2 0.9],[]);
end
 
%   Repeat the same processes as for segmenting tray
% TODO: Create a function to make code reuse a practical option
mask = (Image > 30);
 
clean1 = bwareaopen(mask, 5000); 
clean2 = imfill(clean1, 'holes');
 
se = strel('disk', 50);
InfoMask = imopen(clean2, se);
 
info=regionprops(InfoMask,'boundingbox');
InfoFinal=imcrop(LabelFinal, info.BoundingBox);
 
%% Display required images
 
figure;
subplot(3,3,1),     imshow(image),              title('Tray Input');
subplot(3,3,2),     imshow(TrayMask),           title('Cleaned Mask');
subplot(3,3,3),     imshow(TrayFinal),          title('Tray Final Image'); 
 
subplot(3,3,4),     imshow(TrayFinal),          title('Label Input');
subplot(3,3,5),     imshow(LabelMask),          title('LabelMask');
subplot(3,3,6),     imshow(LabelFinal),         title('FinalLabel');
 
subplot(3,3,7),     imshow(LabelFinal),         title('Information input');
subplot(3,3,8),     imshow(InfoMask),           title('InfoMask');
subplot(3,3,9),     imshow(InfoFinal),          title('FinalInfo');
 
%% Write images to files
 
imwrite(image,'CV_Assign1_Original.jpg','jpg','comment','Image owned by Marc Chapman 054888139 if found please return');
imwrite(TrayMask,'CV_Assign1_TrayMask.jpg','jpg','comment','Image owned by Marc Chapman 054888139 if found please return');
imwrite(TrayFinal,'CV_Assign1_TrayFinal.jpg','jpg','comment','Image owned by Marc Chapman 054888139 if found please return');
imwrite(LabelMask,'CV_Assign1_LabelMask.jpg','jpg','comment','Image owned by Marc Chapman 054888139 if found please return');
imwrite(LabelFinal,'CV_Assign1_LabelFinal.jpg','jpg','comment','Image owned by Marc Chapman 054888139 if found please return');
imwrite(InfoMask,'CV_Assign1_InfoMask.jpg','jpg','comment','Image owned by Marc Chapman 054888139 if found please return');
imwrite(InfoFinal,'CV_Assign1_InfoFinal.jpg','jpg','comment','Image owned by Marc Chapman 054888139 if found please return');
 
%% Further tasks
 
% Implement a text and QR Code reading function to write out 
% the specific data of the product, this data could then be used 
% for database operations such as productions levels, production speeds
% error counting etc

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎