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!