Polar Plot Axis is Off Center from and not Scaled with Background Image

조회 수: 2 (최근 30일)
Nicholas Nobile
Nicholas Nobile 2022년 3월 22일
답변: yanqi liu 2022년 3월 23일
I am trying to plot acceptable values of saturation on an HSV Color Wheel, but the polar plot is not centered on the background image. Anyone have any good ways to get the radius right and improve the plot to be centered on the background?
minS = 15;
maxS = 30;
minH = 50; %because yellow is apparently yucky
c = (-1*minS+maxS)/2;
a = maxS-c;
ellipticity = c/a;
parameter = a*(1-ellipticity^2);
theta = 0:0.1:360;
rho = parameter./(1-ellipticity.*cosd(theta - minH + 180));
rows = 500;
columns = 500;
midX = columns / 2;
midY = rows / 2;
% Construct v image as uniform.
v = ones(rows, columns);
s = zeros(size(v)); % Initialize.
h = zeros(size(v)); % Initialize.
% Construct the h image as going from 0 to 1 as the angle goes from 0 to 360.
% Construct the S image going from 0 at the center to 1 at the edge.
for c = 1 : columns
for r = 1 : rows
% Radius goes from 0 to 1 at edge, a little more in the corners.
radius = sqrt((r - midY)^2 + (c - midX)^2) / min([midX, midY]);
s(r, c) = min(1, radius); % Max out at 1
h(r, c) = atan2d((r - midY), (c - midX));
end
end
% Flip h right to left.
h = fliplr(mat2gray(h));
% Construct the hsv image.
hsv = cat(3, h, s, v);
rgbImage = hsv2rgb(hsv);
% Display the RGB image.
fig = figure;
subplot(1,1,1);
imshow(rgbImage, []);
drawnow;
polaraxes("Color","none");
hold on;
theta_radians = deg2rad(theta);
polarplot(theta_radians,rho,'black');
rlim([0, 100]);

답변 (1개)

yanqi liu
yanqi liu 2022년 3월 23일
minS = 15;
maxS = 30;
minH = 50; %because yellow is apparently yucky
c = (-1*minS+maxS)/2;
a = maxS-c;
ellipticity = c/a;
parameter = a*(1-ellipticity^2);
theta = 0:0.1:360;
rho = parameter./(1-ellipticity.*cosd(theta - minH + 180));
rows = 500;
columns = 500;
midX = columns / 2;
midY = rows / 2;
% Construct v image as uniform.
v = ones(rows, columns);
s = zeros(size(v)); % Initialize.
h = zeros(size(v)); % Initialize.
% Construct the h image as going from 0 to 1 as the angle goes from 0 to 360.
% Construct the S image going from 0 at the center to 1 at the edge.
for c = 1 : columns
for r = 1 : rows
% Radius goes from 0 to 1 at edge, a little more in the corners.
radius = sqrt((r - midY)^2 + (c - midX)^2) / min([midX, midY]);
s(r, c) = min(1, radius); % Max out at 1
h(r, c) = atan2d((r - midY), (c - midX));
end
end
% Flip h right to left.
h = fliplr(mat2gray(h));
% Construct the hsv image.
hsv = cat(3, h, s, v);
rgbImage = hsv2rgb(hsv);
% Display the RGB image.
fig = figure;set(gca, 'units','normalized','position',[0,0,1,1])
imshow(rgbImage, []);
drawnow;
polaraxes("Color","none");
hold on;
theta_radians = deg2rad(theta);
hp2 = polarplot(theta_radians,rho,'black');
rlim([0, 100]);

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by