Image Processing - How to separate barcode from the background
17 views (last 30 days)
I'm wondering how to separate the barcode from background itself, and I have tried some different to remove the unwanted object but cannot remove fully , anybody has an idea!
RGB = imread('barcode.jpg');
RGB = imresize(RGB, 0.33);
%Convert from RGB to Gray
Gray = rgb2gray(RGB);
%Threshold Image to black and white
Threshold = graythresh(Gray);
BW = im2bw(Gray, Threshold);
BW2 = bwareaopen(BW,25000);
Chandra Kurniawan on 22 Dec 2011
Here I have the code to do segmentation on your barcode image.
I hope this helps
rgb = imread('barcode.jpg');
rgb = imresize(rgb,0.33);
Ibw = im2bw(Igray, graythresh(Igray));
Iarea = bwareaopen(Ibw,25000);
Iarea = imfill(Iarea,'holes');
stat = regionprops(Iarea,'boundingbox');
for cnt = 1 : length(stat)
area(cnt) = stat(cnt).BoundingBox(3) * stat(cnt).BoundingBox(4);
[C I] = min(area);
Icropped = imcrop(Ibw,stat(I).BoundingBox);
Original Image :
Cropped Image :
More Answers (2)
noosa on 25 Jan 2012
I am trying to run this code but I get this error :
??? Error using ==> area at 44 Must supply Y data or X and Y data as first argument(s).
Can you help me please???
mostafa alhamdany on 4 Dec 2015
hi this code is not working and the error is : Error using area (line 35) Must supply Y data or X and Y data as first argument(s).
Error in barcode (line 15) [C I] = min(area); can anyone help me to solve it , please