0

I have the following MATLAB code to localize and read barcodes in pictures (JPG,PNG): ## MATLAB CODE ##

%% Read picture
I = imread("4.png");
%% Gray Version
Igray = rgb2gray(I);  
%% Localisation Sobel-Technique 
[~,threshold] = edge(Igray,'sobel');
fudgeFactor = 0.5;
%Binary image
BWs = edge(Igray,'sobel',threshold * fudgeFactor);
%imshow(BWs)
title('Binary Gradient Mask')
se90 = strel('line',3,90);
se0 = strel('line',3,0);
% cleaned Binary image
BWsdil = imdilate(BWs,[se90 se0]);
%imshow(BWsdil)
title('Dilated Gradient Mask')
% Filled with holes
BWdfill = imfill(BWsdil,'holes');
%imshow(BWdfill)
title('Binary Image with Filled Holes')
% BW image
BWnobord = imclearborder(BWdfill,4);%%% High contrast balck/white area. %%%
imshow(BWnobord), title('BW, Image')
rms = bwareaopen(BWnobord,50);
figure(2), imshow(rms, []), title('Last Update');

This code gives me this result: [https://i.stack.imgur.com/e5ckj.jpg][1]

%% Now the problem is how can I Traite the barcode and eliminate other areas. %% The answer I need is: 130760000102 ("barcodes") %% i don't know how to complete the code.

1 Answers1

0

I have updated this code to gives me the values of the barcodes in the picture:

S = imread('picture.jpg');      % Image
NRows = size(S,1);
NColoms = size(S,2);

S = imcrop(S,[0 NRows/2 NColoms NRows/1.2]);

depth = 10;
horizantalRule=depth+1;
I = rgb2gray(S);   % Gray Image
I = imadjust(I);  
I = im2bw(I);      % Binary Image
imshow(I);  
NumofRows=size(I,1);
NumofColoms=size(I,2);  

%% Localisation Sobel-Technique
% Detection des contours
I_Sobel = rgb2gray(S);
[~,threshold] = edge(I_Sobel,'sobel');
fudgeFactor = 0.5;
% Binarisation
BWs = edge(I_Sobel,'sobel',threshold * fudgeFactor);
se90 = strel('line',3,90);
se0 = strel('line',3,0);
% Elimination des pixels des contours
BWsdil = imdilate(BWs,[se90 se0]);
BWdfill = imfill(BWsdil,'holes');
% Selection du pixels d'intensite maximal dans l'image
BWnobord = imclearborder(BWdfill,4);
% lissage d'image et selection de la region du code barres
remove_small_region = bwareaopen(BWnobord,50);
% Outline mask
BWoutline = bwperim(BWnobord);
Segout = S; 
Segout(BWoutline) = 255; 
%imshow(Segout)
imshow(labeloverlay(S,BWnobord));

This Code do the following: Trait pictures from RGB to binary(BW), and gives the result from pictures that has just barcodes. The question is: How to improve this code to handles any pictures (find the barcode and gives the result)?