How to recover the barcode after the use of imdilate()
1 view (last 30 days)
Show older comments
I was trying to merge the barcode together so that I can remove the background object. After doing so, I was wondering how can I recover back the the barcode. Below are the image and the coding(I know there is a lot of loop holes in the coding).
Orignal Image
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/146466/image.jpeg)
Processed Image
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/146467/image.jpeg)
% Read Image
rgb = imread('barcode.jpg');
% Resize Image
rgb = imresize(rgb,0.33);
% Convert from RGB to Gray
Igray = rgb2gray(rgb);
% Threshold to minimize the intraclass variance
Ibw = im2bw(Igray, graythresh(Igray));
% Inverse Colour
Ibw = ~Ibw;
% Clear Border
Iarea = imclearborder(Ibw);
% Remove Small object
Iarea = bwareaopen(Iarea,50);
masklen = 80;
Imask = zeros(1, masklen);
Imask(ceil(end/2):end) = 1;
rmask = fliplr(Imask);
block = imdilate(Iarea, Imask) & imdilate(Iarea, rmask) ;
block = bwareaopen(block,10000);
imshow(block);
0 Comments
Accepted Answer
Image Analyst
on 10 Jan 2012
Did I already give you code for that in your prior question on this subject? Anyway, just multiply your "block" by "rgb" - here's a new and different way for you (Sean's method):
% Mask the image.
maskedRgbImage = bsxfun(@times, rgb, cast(block,class(rgb)));
More Answers (0)
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!