How to recover the barcode after the use of imdilate()
2 次查看(过去 30 天)
显示 更早的评论
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
Processed Image
% 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 个评论
采纳的回答
Image Analyst
2012-1-10
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)));
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!