Removing some specific bright circles in the image after knowing the location

3 views (last 30 days)
I am tracking 10 small robots (two different types) in a circular arena. I am using gaussian code to track them. So, I want to track a specific kind of robots (count = 5) among all those robots and ignore the other 5 robots. I know the x and y locations, radius of the other 5 robots I want to ignore. I am trying to find a way so that I can remove those 5 bright robots from the picture and only track the other 5 of the robots with gaussian code. How can I make specific location of an image dimmer?

Accepted Answer

Image Analyst
Image Analyst on 29 Jun 2022
Try this:
% 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 = 40;
%--------------------------------------------------------------------------------------------------------
% READ IN IMAGE
folder = pwd;
baseFileName = 'robots.png';
% baseFileName = 'org.jpg';
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
rgbImage = 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(rgbImage)
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 = rgbImage(:, :, 3);
else
grayImage = rgbImage;
end
%--------------------------------------------------------------------------------------------------------
% Display the image.
subplot(2, 2, 1);
imshow(grayImage);
impixelinfo;
axis('on', 'image');
title('Original Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Maximize window.
g = gcf;
g.WindowState = 'maximized';
drawnow;
%--------------------------------------------------------------------------------------------------------
% Display histogram
subplot(2, 2, 2);
histogram(grayImage, 256);
grid on;
title('Histogram of Image', 'FontSize', fontSize, 'Interpreter', 'None');
%--------------------------------------------------------------------------------------------------------
% Binarize the image to get a mask.
threshold = 100;
mask = grayImage > threshold;
% Get convex hull
mask = bwconvhull(mask, "objects");
% Display mask image.
subplot(2, 2, 3);
imshow(mask);
axis('on', 'image');
drawnow;
caption = sprintf('Mask using a threshold of %.1f', threshold);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
%--------------------------------------------------------------------------------------------------------
% Mask the image.
maskedImage = grayImage; % Initialize.
maskedImage(mask) = 0; % Erase robots.
subplot(2, 2, 4);
imshow(maskedImage);
axis('on', 'image');
drawnow;
title('Masked Image', 'FontSize', fontSize, 'Interpreter', 'None');
  2 Comments
Image Analyst
Image Analyst on 29 Jun 2022
You can use bwareafilt
Also check out my Image Segmentation Tutorial where I do some size filtering.
Let me know if you still can't figure it out and let me know which are the robots you want to remove, which you want to keep, and which blobs are not robots at all.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 29 Jun 2022
You forgot to attach an image.
You can threshold to find bright things and then erase them. Assuming a gray scale image
mask = grayImage > someThreshold;
grayImage(mask) = 0; % Make bright things black.
Or if you know the locations you can use poly2mask with the circle (x,y) perimeter coordinates to create a mask.
  1 Comment
Sulagna Saha
Sulagna Saha on 29 Jun 2022
Attached is an image. I want to get rid of the small robots. Brightness does not work fine, because sometimes big robots have the same brightness value. Can you clarify a little bit how can I use poly2mask for the circles? I have x,y location,radius of the mini robots.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by