How to get the coordinate of this four points?
Show older comments
Accepted Answer
More Answers (1)
Matt Tearle
on 5 Jan 2012
With such a clean image, you can do it pretty easily:
x = imread('barcode.gif');
y = x<15;
figure
imagesc(y), colormap('gray')
ridx1 = find(any(y,2),1,'first')
cidx1 = find(any(y,1),1,'first')
cidx2 = find(any(y,1),1,'last')
z = y(ridx1:end,cidx1:cidx2);
ridx2 = find(all(~z,2),1,'first') + ridx1 - 2
figure
imagesc(y), colormap('gray')
hold on
plot([cidx1,cidx1,cidx2,cidx2],[ridx1,ridx2,ridx1,ridx2],'r*')
The coordinates you're after being (ridx1,cidx1), (ridx1,cidx2), (ridx2,cidx1), and (ridx2,cidx2). But this won't work so well with a noisy, rotated (etc) image.
EDITED to make the last visualization clearer, a la David Young's approach.
Categories
Find more on Region and Image Properties in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
