Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
bestchen97 committed Jan 5, 2021
1 parent a5e30e4 commit db39179
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
Binary file added circle.bmp
Binary file not shown.
34 changes: 34 additions & 0 deletions circle.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
m = 250; %设置图片大小
n = 250;
a = zeros(m,n,3);

x = linspace(-n,n,n); %建立图片坐标
y = linspace(m,-m,m);
[X,Y] = meshgrid(x,y);

theta = atan2(-X,-Y); %计算坐标点对应的角度,转化到0~1范围作为h分量
theta = theta - min(min(theta));
theta = theta/max(max(theta));

radius = sqrt(X.^2 + Y.^2); %计算坐标点对应的径向坐标
rmax = radius(round(n/8),round(m/2)); %选取最大半径值
radius(radius>rmax) = 0; %最大半径以外赋值为0,即外圈饱和度为0
r = radius/rmax; %转换到0~1范围作为s分量

value = 1; %设置亮度值范围0~1,亮度只针对园形区域范围内
v = ones(m,n);
v(r>0) = value;

figure(1);
subplot(1,3,1),imshow(theta),title('h'),colorbar;
subplot(1,3,2),imshow(r),title('s'),colorbar;
subplot(1,3,3),imshow(v),title('v'),colorbar;

a(:,:,1) = theta;
a(:,:,2) = r;
a(:,:,3) = v;

a = hsv2rgb(a); %赋值三个分量后转换为rgb
figure(2);
imshow(a);
imwrite(a,'circle.bmp');
Binary file added rectangular.bmp
Binary file not shown.
30 changes: 30 additions & 0 deletions rectangular.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
m = 200; %设置图片大小为m*n
n = 250;
a = zeros(m,n,3);

x = linspace(0,1,n);
y = linspace(1,0,m);
[X,Y] = meshgrid(x,y); %按照坐标生成分量

h = X;
s = Y;
value = 1; %设置亮度分量的值,范围0~1,此时为全图统一亮度情况
v = ones(m,n)*value;

% x = linspace(0,1,n); %此段四行注释为设置亮度分量为渐变值,范围0.4~1,
% y = linspace(1,0.4,m); %此时为全图不统一亮度情况
% [X,Y] = meshgrid(x,y);
% v = ones(m,n).*Y;

figure(1);
subplot(1,3,1),imshow(h),title('h'),colorbar;
subplot(1,3,2),imshow(s),title('s'),colorbar;
subplot(1,3,3),imshow(v),title('v'),colorbar;

a(:,:,1) = h;
a(:,:,2) = s;
a(:,:,3) = v;
a = hsv2rgb(a); %赋值三个分量后转换为rgb
figure(2);
imshow(a);
imwrite(a,'rectangular.bmp');

0 comments on commit db39179

Please sign in to comment.