draw a white circle on an binary image?

17 views (last 30 days)
hi I want to draw a white cirle on an image ..my image is binary and I want to draw a withe circle on it : I have cordinate and radius of this: I use this code
if true
imshow(m);imellipse(gca,[168.673621460507 309.997019374069 50 50]);
and my result is like this:
how can I make a white circle before using it on this image and then use this circle on it??

Accepted Answer

Image Analyst
Image Analyst on 25 Sep 2014
Try this:
% Demo to write an ellipse into the overlay of an image,
% and then to burn those overlays into the image.
%----- Initializing steps -----
% Clean up
clear all;
close all;
workspace; % Display the workspace panel.
hasIPT = license('test', 'image_toolbox');
if ~hasIPT
% User does not have the toolbox installed.
message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
% User said No, so exit.
% Display images to prepare for the demo.
monochromeImage = imread('cameraman.tif');
subplot(2, 2, 1);
title('Original Image');
subplot(2, 2, 2);
title('Original Image with ellipse in overlay');
set(gcf, 'units','normalized','outerposition',[0 0 1 1]); % Maximize figure.
set(gcf,'name','Image Analysis Demo','numbertitle','off')
%----- Burn ellipse into image -----
% Create elliptical mask, h, as an ROI object over the second image.
subplot(2, 2, 2);
hEllipse = imellipse(gca,[10 10 50 150]); % Second argument defines ellipse shape and position.
% Create a binary image ("mask") from the ROI object.
binaryImage = hEllipse.createMask();
% It's solid now. If you want the perimeter, call bwperim
binaryImage = bwperim(binaryImage);
% Display the ellipse mask.
subplot(2, 2, 3);
title('Binary mask of the ellipse');
% Let's try to add some text. (Doesn't work)
% hText = text(50, 100, 'Line of Text');
% textMask = hText.createMask();
% binaryImage = binaryImage & textMask;
% imshow(binaryImage);
% Burn ellipse into image by setting it to 255 wherever the mask is true.
monochromeImage(binaryImage) = 255;
% Display the image with the "burned in" ellipse.
subplot(2, 2, 4);
title('New image with ellipse burned into image');
See attached demo for one that also does a line.

More Answers (1)

Matthew Eicholtz
Matthew Eicholtz on 29 Jan 2016
You can also try using insertShape, which was introduced in R2014a.

Community Treasure Hunt

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

Start Hunting!