draw a white circle on an binary image?
11 次查看(过去 30 天)
显示 更早的评论
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??
0 个评论
采纳的回答
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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Computer Vision with Simulink 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!