Trying to determine locations of markers in image
조회 수: 4 (최근 30일)
이전 댓글 표시
I'm trying to obtain the pixel coordinates of the dot pattern image data that is stored in the attached file; I'm using this image to spatially calibrate my camera image. Is there a way to automate the detection of these dots? Thanks in advance for any guidance.
댓글 수: 5
Walter Roberson
2025년 7월 18일
Is the projection unequal? That is, is the distance between dots on (say) the lower left corner different from the distance between dots (say) near the upper right corner? If the distances are always the same, then you only need to locate a small number of dots in order to calculate the distance between pixels. If the distances are not always the same but the change is linear, then you only need to calculate based on a small number of locations. If, however, the projection is non-linear then the task becomes more difficult.
채택된 답변
Mathieu NOE
2025년 7월 18일
hello
maybe this ? not perfect but you may refine it and get as much dots as we / you can
% Read the grayscale image
img = readmatrix('CalImage_Grayscale.txt');
figure
imshow(img);
% Use adaptthresh to determine threshold to use in binarization operation.
T = adaptthresh(img, 0.3);
% Threshold the image to create a binary mask
binaryMask = imbinarize(img,T);
figure
imshow(binaryMask);
% Remove noise , small (and large) objects
cleanMask = bwareafilt(binaryMask, [5, 20]); % Keep objects with area between xx and yy pixels
figure
imshow(cleanMask);
% Label connected components (dots)
[labeledImage, numDots] = bwlabel(cleanMask);
% Display results
figure
imshow(img); hold on;
stats = regionprops(labeledImage, 'Centroid');
for k = 1:numDots
centroid = stats(k).Centroid;
plot(centroid(1), centroid(2), 'r*', 'MarkerSize', 10); % Mark dots
end
title(['Detected Dots: ', num2str(numDots)]);
hold off;
댓글 수: 4
추가 답변 (1개)
Image Analyst
2025년 7월 21일
I recommend you use the code in the other answer to get the "cleanMask" binary image above. Then use regionprops to get the centroids, or weighted centroids, of the dots. The contour and looping stuff is overly complicated and not needed, when regionprops gives you the centroids directly (but it requires the Image Processing Toolbox).
Then for the next step needed for calibration you can use kmeans to get the mean rows and columns of each linear series of dot. If the image is tilted, you might then use that to get the angle of tile and then use imrotate to square it up with the image edges. Then you can sum the binary image vertically and horizontally with sum() to get a 1-D horizontal or vertical profile. Then you can use regionprops to get the row and column numbers of each line of dots. Knowing that you can complete your calibration in terms of millimeters (or whatever) per pixel.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!