14
$\begingroup$

How can I change the formula to detect the barcode in every angle?

Formula

Original Image Processed Image

 rgb = imread('barcode4.jpg');
% Resize Image
rgb = imresize(rgb,0.33);
figure(),imshow(rgb);
% Convert from RGB to Gray
Igray = double(rgb2gray(rgb));
% Calculate the Gradients
[dIx, dIy] = gradient(Igray);
B = abs(dIx) - abs(dIy);
% Low-Pass Filtering
H = fspecial('gaussian', 20, 10);
C = imfilter(B, H);
C = imclearborder(C);
figure(),imagesc(C);colorbar
$\endgroup$

migrated from stackoverflow.com Jan 30 '12 at 18:14

This question came from our site for professional and enthusiast programmers.

8
$\begingroup$

If the filter you have works well enough for you, you could simply use imrotate to create several rotated versions of the source image, and use the filter you have on each of them (make sure to use bilinear to get sensible derivatives)

$\endgroup$
  • $\begingroup$ Thanks for the advice. how can I create several rotated versions?? Sorry, I'm new to MatLab $\endgroup$ – Kim Jan 30 '12 at 16:58
  • $\begingroup$ I manage to get the barcode to vertical or horizontal. However the formula can only detect horizontal barcode. Can I change the formula so that both vertical and horizontal can detect the barcode. $\endgroup$ – Kim Feb 2 '12 at 6:44
  • $\begingroup$ mathworks.com/matlabcentral/fileexchange/31727-barcode-reader you can check out this link $\endgroup$ – vini Apr 8 '12 at 15:40
7
$\begingroup$

Your equation highlights areas where the magnitude of the gradient in the X direction is consistently higher than it is in the Y direction. To make this work in all directions, then you probably want areas where the magnitude of the gradient in any direction is high.

Try using the following:

B = double(sqrt(dIx.^2 + dIy.^2) > 0)

Not that this will basically highlight every edge, but the low-pass filter will mean that you need multiple edges close together.

$\endgroup$
  • $\begingroup$ Thanks for the coding! But I don't know where to put the code as I try replacing the formula, everything went green. $\endgroup$ – Kim Jan 30 '12 at 16:51
  • $\begingroup$ Try my updated version. $\endgroup$ – Nzbuu Jan 30 '12 at 19:27
  • $\begingroup$ But now the whole image turn Red in color!! $\endgroup$ – Kim Jan 31 '12 at 8:34
  • $\begingroup$ I manage to get the barcode to vertical or horizontal. However the formula can only detect horizontal barcode. Can I change the formula so that both vertical and horizontal can detect the barcode. $\endgroup$ – Kim Feb 2 '12 at 6:45
  • $\begingroup$ I test this furmule '' B = double(sqrt(dIx.^2 + dIy.^2) > 0) " it's not work. $\endgroup$ – user4975 Jul 5 '13 at 19:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.