我想生成一个圆,其强度(在圆中)在[0.5 1.5]中缓慢变化,如下图所示(没有边界线)。这意味着x方向的数据来自0.5, 0.505, 0.51,....,1.5
(只是假设,它可能是非线性变化,即cos或正弦函数作为我的代码)我只在Matlab中创建了一个圆。你能帮我继续完成任务吗?
这是我的代码,它只成功地生成了一个圆
rows=160;
columns=180;
circleCenterX = round(columns/2);
circleCenterY = round(rows/2); % square area 0f 500*500
circleRadius1 = 50; % big circle radius
circle1 = false(rows, columns);
[x, y] = meshgrid(1:columns, 1:rows);
circle1((x - circleCenterX).^2 + (y - circleCenterY).^2 <= circleRadius1.^2) = true;
%% Slowly changed
t1 = 0:pi/(rows.*1.2):pi/1.2;
t2 = 0:pi/(cols.*1.2):pi/1.2;
data_x=sin(t1);
data_x(end)=[];
data_y=cos(t2);
data_y(end)=[];
%% Re-scale in range [0.5 1.5]
x = data_x(:);
y = data_y(:);
alpha=0.5;
up_range=1+alpha;
down_range=1-alpha;
data_scale_x = (x - min(x)) * (up_range - down_range) / (max(x) - min(x)) + down_range;
%% Same with y
data_scale_y = (y - min(y)) * (up_range - down_range) / (max(y) - min(y)) + down_range;
%% Assign to image
[X,Y] = meshgrid(data_scale_x,data_scale_y);
image=[X];
imshow(circle1,[]);
最佳答案
您可以使用fill
完成此操作,并设置适当的属性,如
r = 1;
center = [0 0];
% generate the circle points
num_points = 100;
t = linspace(0,2*pi,num_points);
x = r*sin(t+pi/2) + center(1);
y = r*cos(t+pi/2) + center(2);
%generate the color values
color = interp1([0 round(num_points/2) num_points],[1 0 1],1:num_points);
%plot the filled circle and set the appropriate colormap
colormap('gray')
fill(x,y,color,'EdgeColor','none')
%save with a given resolution and size
set(gca,'Visible','off');
set(gca, 'position', [0 0 1 1]);
set(gcf,'PaperUnits','inches');
set(gcf,'PaperPosition',[0 0 160 180]);
print 'test.bmp' -dbmp -r1
结果是:
关于algorithm - 如何生成强度在[0.5 1.5]内缓慢变化的圆?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36237864/