为两个圆圈之间的重叠区域分配特定颜色
assign a specific color to the overlapping area between two circles
我正在使用此代码绘制两个 circles.It 随机为最终图像中的区域着色。但我想为圆圈分配特定的灰色阴影,为重叠区域分配不同的阴影。
% size of image
sz = [800 800];
% generate coordinates
y = 1:sz(1);
x = 1:sz(2);
[xx, yy] = meshgrid(x, y);
% draw circles
ci1 = (xx-300).^2 + (yy-400).^2 <= 200^2;
ci2 = (xx-500).^2 + (yy-400).^2 <= 200^2;
% draw image containing circles
imagesc (ci1 + ci2 );
colormap(gray);
您可以使用不同区域的二进制编码以及自定义颜色图:
% draw image containing circles
imagesc (ci1 + 2 * ci2 );
caxis([-0.5, 3.5])
colormap([0 0 0 % background: black
1 0 0 % circle 1: red
0 1 0 % circle 2: green
0 0 1]) % overlap: blue
绘制的数据包含背景为 0,圆 1 为 1,圆 2 为 2,重叠部分为 3。 caxis
和 colormap
命令将数字 0、1、2、3 映射到指定为 RGB 三元组的黑色、红色、绿色、蓝色。调整颜色图中的条目以获得您想要的特定灰色阴影。
注意:您的代码缺少一行 [xx, yy] = meshgrid(x, y);
我正在使用此代码绘制两个 circles.It 随机为最终图像中的区域着色。但我想为圆圈分配特定的灰色阴影,为重叠区域分配不同的阴影。
% size of image
sz = [800 800];
% generate coordinates
y = 1:sz(1);
x = 1:sz(2);
[xx, yy] = meshgrid(x, y);
% draw circles
ci1 = (xx-300).^2 + (yy-400).^2 <= 200^2;
ci2 = (xx-500).^2 + (yy-400).^2 <= 200^2;
% draw image containing circles
imagesc (ci1 + ci2 );
colormap(gray);
您可以使用不同区域的二进制编码以及自定义颜色图:
% draw image containing circles
imagesc (ci1 + 2 * ci2 );
caxis([-0.5, 3.5])
colormap([0 0 0 % background: black
1 0 0 % circle 1: red
0 1 0 % circle 2: green
0 0 1]) % overlap: blue
绘制的数据包含背景为 0,圆 1 为 1,圆 2 为 2,重叠部分为 3。 caxis
和 colormap
命令将数字 0、1、2、3 映射到指定为 RGB 三元组的黑色、红色、绿色、蓝色。调整颜色图中的条目以获得您想要的特定灰色阴影。
注意:您的代码缺少一行 [xx, yy] = meshgrid(x, y);