algorithm - 如何生成强度在[0.5 1.5]范围内缓慢变化的圆圈?

标签 algorithm matlab image-processing

我想生成一个圆,其强度(在圆中)在 [0.5 1.5] 中缓慢变化,如下图(无边界线)。这意味着 x 方向的数据来自 0.5, 0.505, 0.51,....,1.5(假设,它可能是非线性变化的,即 cos 或 sine 函数作为我的代码)。我只是在 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,[]);

enter image description here

最佳答案

您可以使用 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

结果是这张图:

enter image description here

关于algorithm - 如何生成强度在[0.5 1.5]范围内缓慢变化的圆圈?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36237864/

相关文章:

java - Java中用于存储图形的数组

c++ - 调用迭代函数的次数

MATLAB:如何在同一张图上绘制多个函数的图形?

matlab - 如何通过 MATLAB 使最小二乘线与散点图中相应数据集的颜色相同?

python - 对两个数组进行排序以查看它们是否具有相同的值,但它只会发现数组中有 2/3 的值相同

java - 是否可以使用分形来计算软件的复杂性?

Matlab错误: Too many output arguments

java - setRGB() 似乎没有改变颜色

algorithm - 将 2d 点排序为矩阵

javascript - 如何将纯黑白图像转换为多边形集合?