## How to crop out the barcode??

Kim

### Kim (view profile)

님이 질문을 제출함. 11 Feb 2012
최근 활동 Cedric Wannaz

### Cedric Wannaz (view profile)

님이 편집함. 8 Oct 2013
Chandra Kurniawan

### Chandra Kurniawan (view profile)

님이 답변을 채택함.
I have found out the way to determine the barcode and currently working on cropping out the barcode. How can I write the code so that it can crop out the barcode?? I have paste my original image and my coding below.
Original Image Processed Image % Resize Image
rgb = imresize(rgb,0.33);
%figure(),imshow(rgb);
% Convert from RGB to Gray
Igray = rgb2gray(rgb);
BW2 = edge(Igray,'canny');
%figure(),imshow(BW2);
% Perform the Hough transform
[H, theta, rho] = hough(BW2);
% Find the peak pt in the Hough transform
peak = houghpeaks(H);
% Find the angle of the bars
barAngle = theta(peak(2));
J = imrotate(rgb,barAngle,'bilinear','crop');
%figure(),imshow(J);
Jgray = double(rgb2gray(J));
%if min(dIx(:))<= -100 && max(dIx(:))>=100 || min(dIy(:))<=-100 && max(dIy(:))>=100
if barAngle <= 65 && barAngle >=-65 && min(dIx(:))<= -100
B = abs(dIx) - abs(dIy);
else
B = abs(dIy) - abs(dIx);
end
% Low-Pass Filtering
H = fspecial('gaussian', 20, 10);
C = imfilter(B, H);
C = imclearborder(C);
%figure(),imshow(C);
figure(),imagesc(C);colorbar;

로그인 to comment.

## 답변 수: 3

Chandra Kurniawan

### Chandra Kurniawan (view profile)

님의 답변 12 Feb 2012
채택된 답변

D = C > 20;
Ilabel = bwlabel(D);
stat = regionprops(Ilabel,'boundingbox');
for x = 1 : length(stat)
Icrop{x} = imcrop(J,stat(x).BoundingBox);
end

로그인 to comment.

Image Analyst

### Image Analyst (view profile)

님의 답변 11 Feb 2012

Looks like thresholding at about 20 should do it. Then label and use regionprops to do size filtering and get the bounding box. Then use imcrop to do the cropping.

Kim

### Kim (view profile)

11 Feb 2012
How can I implement this to my coding??
Image Analyst

### Image Analyst (view profile)

12 Feb 2012
Looks like Chandra provided that to you. If you want just the biggest blob though, you'd have to do it slightly differently.

로그인 to comment.

Andrea Carron

### Andrea Carron (view profile)

님의 답변 16 Feb 2012

I tried to use the code posted by Kim with the image above, but I obtained this figure:
How is it possible?

로그인 to comment.