How to get the coordinate of this four points?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
How to get the coordinate of this four points?
Original Image
2 Kommentare
Jan
am 5 Jan. 2012
Is this a bw image with perfect alignment or a scanned gray-scale image which can be slightly rotated?
Akzeptierte Antwort
David Young
am 5 Jan. 2012
Here's another approach which works with the clean image you've given us. It's not as neat as Matt's approach, but it includes some techniques that you might find helpful when you're working with your more difficult camera images.
The core of this approach is a pair of morphological dilations which merge the bars into each other to form a large rectangular block. It depends on knowing the orientation of the bars, at least approximately.
imraw = imread('2ebx0t2.gif'); % dowloaded image
img = imraw < max(imraw(:)); % binarized
masklen = 21; % max bar spacing in pixels
lmask = zeros(1, masklen); % mask to smear pixels to right
lmask(ceil(end/2):end) = 1;
rmask = fliplr(lmask); % mask to smear pixels to left
block = imdilate(img, lmask) & imdilate(img,rmask); % smear pixels sideways
rprops = regionprops(block, 'BoundingBox', 'Area'); % get measurements
[~, bigblock] = max([rprops.Area]); % select largest block
bbox = rprops(bigblock).BoundingBox; % and get its bounding box
cornersx = bbox([1 1 1 1]) + [0 bbox([3 3]) 0]; % rearrange to get coords
cornersy = bbox([2 2 2 2]) + [0 0 bbox([4 4])];
imshow(imraw, []); % display image
hold on; plot(cornersx, cornersy, 'b+'); hold off; % with corner coordinates
Weitere Antworten (1)
Matt Tearle
am 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.
Siehe auch
Kategorien
Mehr zu Image Segmentation and Analysis finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!