MATLAB: Putting two circles on the same image

digital image processingimageimage processinguser defined functions

I am trying to obtain a car figure with using two circles and one rectangle image. Firstly, I need to create the circles. How can I put two circles in the same image with the code below? Thanks in advance.
function [outimg, outimg1] = CircleIm(radius)
SizeX = 256;
SizeY = 256;
[C, R] = meshgrid(1:SizeX, 1:SizeY);
centerX = 64;
centerY = 64;
centerX1 = 192;
centerY1 = 192;
circle = (R - centerY).^2 + (C - centerX).^2 <= radius.^2;
circle1 = (R - centerY1).^2 + (C - centerX1).^2 <= radius.^2;
outimg=image(circle);
hold on;
outimg1=image(circle1);
colormap([0 0 0.4; 1 1 1]);
end

Best Answer

Try the following
function [outimg] = CircleIm(radius)
SizeX = 256;
SizeY = 256;
[C, R] = meshgrid(1:SizeX, 1:SizeY);
centerX = 64;
centerY = 64;
centerX1 = 192;
centerY1 = 192;
circle = (R - centerY).^2 + (C - centerX).^2 <= radius.^2;
circle1 = (R - centerY1).^2 + (C - centerX1).^2 <= radius.^2;
circles = circle|circle1;
outimg=image(circle|circle1);
colormap([0 0 0.4; 1 1 1]);
end
your method of hold on will make draw the new image on top of the last image. You need to or both images together to retain both circles. The following are drawn with a radius of 20.
%