How do I draw overlapping circles wich change color?

6 views (last 30 days)
It shoul look like this

Answers (2)

Image Analyst
Image Analyst on 11 Jul 2020
You can just create an rgb image, and write each circle into the color plane of your choice
redChannel = 255 * ones(rows, columns, 'uint8');
greenChannel = 255 * ones(rows, columns, 'uint8');
blueChannel = 255 * ones(rows, columns, 'uint8');
% Now write the circles into whatever color channel you want.
% Use the FAQ https://matlab.fandom.com/wiki/FAQ#How_do_I_create_a_circle.3F
% Then concatenate them into an RGB image
rgbImage = cat(3, redChannel, greenChannel, blueChannel);

DGM
DGM on 24 Apr 2022
Here's one way:
% image setup
sz = [600 600]; % image size
cim = sz/2; % [y x] center of image
r1 = 100; % radius of small circle
r2 = 150; % radius of large circle
% object positions (small circles)
Pth = [0 90 180 270]; % position angle
Pr = 150; % position radius
cx = Pr*cosd(Pth) + cim(2);
cy = sz(1)-(Pr*sind(Pth) + cim(1));
% create color layers
B = ones(sz);
for k = 1:numel(Pth)
B = B - drawhardcirc(sz,[cy(k) cx(k)],r1);
end
R = 1-drawhardcirc(sz,cim,r2);
G = 1-xor(R,B);
% note that we're working with complements,since the background is white
% the four small circles are negative features in B, not R
% the large circle is a negative feature in R, not B
imshow([R G B])
outpict = cat(3,R,G,B);
imshow(outpict)
% draw circle
function circ = drawhardcirc(sz,c,r)
xx = 1:sz(2);
yy = (1:sz(1)).';
circ = sqrt((xx-c(2)).^2 + (yy-c(1)).^2);
circ = circ <= r;
end
See also:

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!