How can I change color of a circle?

11 次查看(过去 30 天)
imageSizeX = 256;
imageSizeY = 256;
[Imagecolumns, Imagerows] = meshgrid(1:imageSizeX, 1:imageSizeY);
Right_X = imageSizeX / 1.25;
Right_Y = imageSizeY / 2;
Left_X = imageSizeX / 5;
Left_Y = imageSizeY / 2;
radius = 15;
circlePixels = (Imagerows - Right_Y).^2 ...
+ (Imagecolumns - Right_X).^2 <= radius.^2;
circlePixels1 = (Imagerows - Left_Y).^2 ...
+ (Imagecolumns - Left_X).^2 <= radius.^2;
x = imshow(circlePixels|circlePixels1);
colormap([0.6 0.6 0.6 ; 0.3 0.3 0.3]);
axis square;
How can I change the color of one circle?

采纳的回答

Walter Roberson
Walter Roberson 2021-10-28
imageSizeX = 256;
imageSizeY = 256;
[Imagecolumns, Imagerows] = meshgrid(1:imageSizeX, 1:imageSizeY);
Right_X = imageSizeX / 1.25;
Right_Y = imageSizeY / 2;
Left_X = imageSizeX / 5;
Left_Y = imageSizeY / 2;
radius = 15;
circlePixels = (Imagerows - Right_Y).^2 ...
+ (Imagecolumns - Right_X).^2 <= radius.^2;
circlePixels1 = (Imagerows - Left_Y).^2 ...
+ (Imagecolumns - Left_X).^2 <= radius.^2;
x = imshow(circlePixels + 2*circlePixels1, []);
colormap([0.6 0.6 0.6 ; 0.3 0.3 0.3; 1 0 0]);
axis square;

更多回答(1 个)

yanqi liu
yanqi liu 2021-10-28
编辑:yanqi liu 2021-10-29
clc; clear all; close all;
imageSizeX = 256;
imageSizeY = 256;
[Imagecolumns, Imagerows] = meshgrid(1:imageSizeX, 1:imageSizeY);
Right_X = imageSizeX / 1.25;
Right_Y = imageSizeY / 2;
Left_X = imageSizeX / 5;
Left_Y = imageSizeY / 2;
radius = 15;
circlePixels = (Imagerows - Right_Y).^2 ...
+ (Imagecolumns - Right_X).^2 <= radius.^2;
circlePixels1 = (Imagerows - Left_Y).^2 ...
+ (Imagecolumns - Left_X).^2 <= radius.^2;
bw = circlePixels|circlePixels1;
L = bwlabel(bw);
figure; imshow(label2rgb(L));
colormap([0.9 0.2 0.1 ; 0.6 0.6 0.6 ; 0.3 0.3 0.3]);
axis square; axis off;
% gen set color, such as red and green
im1 = 0.6*255*ones(size(bw));
im2 = 0.6*255*ones(size(bw));
im3 = 0.6*255*ones(size(bw));
% red
im1(L==1) = 255; im2(L==1) = 0; im3(L==1) = 0;
% green
im1(L==2) = 0; im2(L==2) = 255; im3(L==2) = 0;
im = uint8(cat(3, im1, im2, im3));
figure; imshow(im, []);

类别

Help CenterFile Exchange 中查找有关 Polar Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by