draw a white circle on an binary image?

조회 수: 3 (최근 30일)
sara
sara 2014년 9월 25일
답변: Matthew Eicholtz 2016년 1월 29일
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
m=imread('img2.tif');
imshow(m);imellipse(gca,[168.673621460507 309.997019374069 50 50]);
end
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??

채택된 답변

Image Analyst
Image Analyst 2014년 9월 25일
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
clc;
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.
return;
end
end
% Display images to prepare for the demo.
monochromeImage = imread('cameraman.tif');
subplot(2, 2, 1);
imshow(monochromeImage);
title('Original Image');
subplot(2, 2, 2);
imshow(monochromeImage);
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);
imshow(binaryImage);
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);
imshow(monochromeImage);
title('New image with ellipse burned into image');
See attached demo for one that also does a line.

추가 답변 (1개)

Matthew Eicholtz
Matthew Eicholtz 2016년 1월 29일
You can also try using insertShape, which was introduced in R2014a.

카테고리

Help CenterFile Exchange에서 Image and Video Ground Truth Labeling에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by