How to get the barcode region to red color??

조회 수: 2 (최근 30일)
Kim
Kim 2012년 1월 26일
How can I write the code to get the red region works on vertical barcode image shown on figure 1(a&b).
Figure 2(a&b) is what I want.
I also attach my coding for your reference.
----
Figure 1a (Original image)
Figure 1b (Processed Image)
Figure 2a (Original Image)
Figure 2b (Processed Image)
Coding
rgb = imread('barcode12.jpg');
% Resize Image
rgb = imresize(rgb,0.33);
figure(),imshow(rgb);
% Convert from RGB to Gray
Igray = rgb2gray(rgb);
Igray = double(Igray);
% Calculate the Gradients
[dIx, dIy] = gradient(Igray);
B = abs(dIx) - abs(dIy);
% Low-Pass Filtering
H = fspecial('gaussian', 20, 10);
C = imfilter(B, H);
figure(),imagesc(C); colorbar;

채택된 답변

Chandra Kurniawan
Chandra Kurniawan 2012년 1월 26일
When use the first image (vertical barcode image),
I just simply try to change the position of abs(dIx) and abs(dIy) into :
B = abs(dIy) - abs(dIx);
But when I use the second image (horizontal barcode image),
I have the same problem.
Then, I decide to use this command :
B = imabsdiff(abs(dIx),abs(dIy));
  댓글 수: 3
Chandra Kurniawan
Chandra Kurniawan 2012년 1월 26일
This is not exact way to do, but I use the max value of C as threshold.
rgb = imread('av672a.jpg');
Iresize = imresize(rgb,0.33);
Igray = double(rgb2gray(Iresize));
[dIx dIy] = gradient(Igray);
B = imabsdiff(abs(dIx),abs(dIy));
H = fspecial('gaussian', 20, 10);
C = imfilter(B, H);
Th = max(C(:));
D = C < Th-10;
figure, imagesc(D); colorbar;
Then you can remove the rest of unwanted objects will bwareaopen.
Kim
Kim 2012년 1월 27일
After I did a 'imfilter(B, H)' , how can I convert the image to the colorbar image so that I can do a bwareaopen. Thereafter, draw a box or a line across to determine the barcode. I don't know whether my idea is it good or not.
Anyway, thanks for the code, really appreciate it! Just that not the thing that I wanted.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Chandra Kurniawan
Chandra Kurniawan 2012년 1월 27일
Hi, Kim
I agree with you. To determine the barcode just use boundingbox from regionprops :)
Irgb = imread('15wmqe9.jpg');
Irgb = imread('av672a.jpg');
Iresize = imresize(Irgb,0.33);
Igray = double(rgb2gray(Iresize));
[dIx dIy] = gradient(Igray);
B = imabsdiff(abs(dIx),abs(dIy));
H = fspecial('gaussian', 20, 10);
C = imfilter(B, H);
Th = max(C(:));
D = C < Th-10;
stat = regionprops(~D,'Area','BoundingBox');
for i = 1 : numel(stat),
Iarea(i) = stat(i).Area;
end
[C I] = max(Iarea);
bb = stat(I).BoundingBox;
imshow(Iresize); hold on
rectangle('position',bb,'edgecolor','r');
  댓글 수: 2
Elysi Cochin
Elysi Cochin 2012년 10월 17일
i'm not getting it... my error is
??? Index exceeds matrix dimensions.
Error in ==> Untitled6 at 20 bb = stat(I).BoundingBox;
please can u rectify for me..
Image Analyst
Image Analyst 2012년 10월 17일
This is not a robust algorithm. It's fine tuned for these particular images. It may need to be tweaked for your images. Reply to the thread you started with the URL to your image.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Image Segmentation and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by