how to search for a red circle in an image?

4 vues (au cours des 30 derniers jours)
Shoval  Matzner
Shoval Matzner le 7 Déc 2019
so i need to detect the red circle in a speed limit sign image, can someone suggest me an easy way to do that? the program will return the borders of the red circle
Note that i cant use any stored functions that matlab has..
thanks
traffic-sign-boards-500x500.jpg

Réponse acceptée

Image Analyst
Image Analyst le 7 Déc 2019
Modifié(e) : Image Analyst le 7 Déc 2019
Sorry, I can't do it without using any built-in functions, though the functions I use are pretty low level, like imread(), imshow(), bwboundaries(), etc.
Try this:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clearvars;
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 16;
%=======================================================================================
% Have user browse for a file, from a specified "starting folder."
% For convenience in browsing, set a starting folder from which to browse.
% startingFolder = pwd; % or 'C:\wherever';
% if ~exist(startingFolder, 'dir')
% % If that folder doesn't exist, just start in the current folder.
% startingFolder = pwd;
% end
% % Get the name of the file that the user wants to use.
% defaultFileName = fullfile(startingFolder, 'n*.*');
% [baseFileName, folder] = uigetfile(defaultFileName, 'Select a file');
% if baseFileName == 0
% % User clicked the Cancel button.
% return;
% end
folder = pwd;
baseFileName = 'traffic-sign-boards-500x500.jpg';
fullFileName = fullfile(folder, baseFileName);
rgbImage = imread(fullFileName);
% rgbImage = decorrstretch(rgbImage,'tol',0.01);
% imwrite(rgbImage, 'test.png');
% Get the dimensions of the image.
[rows1, columns1, numberOfColorChannels1] = size(rgbImage)
% Display the original image.
subplot(2, 2, 1);
imshow(rgbImage, []);
axis('on', 'image');
caption = sprintf('Original Color Image\n"%s"', baseFileName);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0.05 1 0.95]);
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by Image Analyst', 'NumberTitle', 'Off')
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
mask = redChannel > 128 & greenChannel < 128 & blueChannel < 128;
% Display the mask image.
subplot(2, 2, 2);
imshow(mask, []);
axis('on', 'image');
caption = sprintf('Color Segmentation');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
% Fill holes, and take the largest blob.
subplot(2, 2, 3);
mask = imfill(mask, 'holes');
mask = bwareafilt(mask, 1);
% Display the image.
subplot(2, 2, 3);
imshow(mask, []);
axis('on', 'image');
title('Final Mask Image', 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% Find the border
boundaries = bwboundaries(mask);
boundaries = cell2mat(boundaries); % Convert from cell to double. Format is [rows, columns], which is [y, x]
% Get x and y coordinates.
xBoundary = boundaries(:, 2);
yBoundary = boundaries(:, 1);
% Display the original image with a blue border around it.
subplot(2, 2, 4);
imshow(rgbImage, []);
axis('on', 'image');
caption = sprintf('Original Color Image\nwith Boundary in Blue');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% Plot boundary in blue.
darkGreen = [0, 0.5, 0];
hold on;
plot(xBoundary, yBoundary, 'b-', 'LineWidth', 3);
This works just because your image is pure computer graphics, not a real world scene.
See lots of papers on traffic sign detection here: VisionBib

Plus de réponses (1)

Shoval  Matzner
Shoval Matzner le 7 Déc 2019
okay, thank you so much for your help

Community Treasure Hunt

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

Start Hunting!

Translated by