How to detect marker with specific feature on it?
11 次查看(过去 30 天)
显示 更早的评论
Hi, image processing experts.
I'm having problem with detecting a specific marked marker.
Here's an example photo that i drew.
Marker is circle shaped. But as you know, marker could be ellipse shaped when the camera is not vertical with the marker.
What I want to do is, I want to find a marker with point marked inside the marker.
Want to get advice of detecting specific marker with point on it.
Thanks.
1 个评论
Dyuman Joshi
2023-8-31
Questions about detecting ellipses and detecting points inside a closed region have been asked many times on this forum, you can find answers by searching.
MATLAB Answers Help Point #1 - Search for Questions and Answers
I strongly suggest you do this.
采纳的回答
Image Analyst
2023-9-1
Try this. Note that I only found 2 markers because one of them is not surrounded by a solid black circle -- it has a gap, like a "C". By the way, I'll be traveling the next 5 days and may not answer.
% Demo by Image Analyst
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 16;
markerSize = 20;
%--------------------------------------------------------------------------------------------------------
% READ IN TEST IMAGE
folder = [];
baseFileName = 'jaeyoung.jpeg';
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage)
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
fprintf('It is not really gray scale like we expected - it is color\n');
% Extract the blue channel.
grayImage = grayImage(:, :, 3);
end
%--------------------------------------------------------------------------------------------------------
% Display the image.
subplot(2, 2, 1);
imshow(grayImage, []);
impixelinfo;
axis('on', 'image');
title('Original Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Update the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage)
% Maximize window.
g = gcf;
g.WindowState = 'maximized';
drawnow;
%--------------------------------------------------------------------------------------------------------
subplot(2, 2, 2);
imhist(grayImage);
grid on;
title('Histogram of Image', 'FontSize', fontSize, 'Interpreter', 'None');
%--------------------------------------------------------------------------------------------------------
% Flatten background.
% grayImage = adapthisteq(grayImage);
%--------------------------------------------------------------------------------------------------------
% Get mask by thresholding at 116.
lowThreshold = 136;
highThreshold = 255;
% Interactively and visually set a threshold on a gray scale image.
% https://www.mathworks.com/matlabcentral/fileexchange/29372-thresholding-an-image?s_tid=srchtitle
% [lowThreshold, highThreshold] = threshold(lowThreshold, highThreshold, grayImage)
mask = grayImage >= lowThreshold & grayImage <= highThreshold;
% Draw line at threshold.
xline(lowThreshold, 'Color', 'r', 'LineWidth', 2);
subplot(2, 2, 3);
imshow(mask);
impixelinfo;
axis('on', 'image');
title('Initial Mask Image', 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
% Clean up the initial mask
mask = imclearborder(mask);
% Get rid of blobs smaller than 10k pixels.
mask = bwareaopen(mask, 10000);
% Now the blobs in this mask have very small pinpoint holes in them (like 1-12 pixels).
% But we want only "markers"/"holes" bigger than a certain area, like 300 or so.
% So invert the mask, clear the border, and call bwareaopen
% to extract only those that are big enough
holeMask = imclearborder(~mask);
% Extract only blobs bigger than 300 pixels.
holeMask = bwareaopen(holeMask, 300);
% Find blobs and their areas.
props = regionprops(holeMask, 'Area', 'Centroid');
allHoleAreas = [props.Area]
holeCentroids = vertcat(props.Centroid)
subplot(2, 2, 4);
imshow(holeMask);
impixelinfo;
axis('on', 'image');
caption = sprintf('Found %d Markers', numel(props));
title(caption, 'FontSize',fontSize);
% Plot circles around them
hold on;
for k = 1 : numel(props)
x = holeCentroids(k, 1);
y = holeCentroids(k, 2);
plot(x, y, 'ro', 'MarkerSize', markerSize);
end
1 个评论
Image Analyst
2023-9-1
It's a generic, general purpose demo of how to threshold an image to find blobs, and then measure things about the blobs, and extract certain blobs based on their areas or diameters.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 3-D Volumetric Image Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!