フィルターのクリア

How to plot a variable density spiral(or any other mathematical 2D- graphs ) on to a image( 512* 512, zero matrix)?

3 ビュー (過去 30 日間)
N_k = 64^2; % number of k-samples
t = linspace(0,sqrt(0.5),N_k)'; % dummy variable to parameterise spiral
k_x = (1 + randn(N_k,1)/20).*t.^2.*cos(2*pi*32*t); % spiral kx-coords
k_y = (1 + randn(N_k,1)/20).*t.^2.*sin(2*pi*32*t); % spiral ky-coords
% show scatterplot of trajectory
figure();
z = scatter(k_x,k_y,5, 'filled'); grid off;
OUTPUT:
% now i want to plot this onto a image space for example, zeros(512x512)
EXPECTED OUTPUT:
% basically i wanted to apply mathematical plots such as ( variable density spiral , radial spiral ) on to a kspace image matrix to sample it on those plot points.

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 3 月 6 日
Here is an way by translating and scaling the random numbers.
N_k = 64^2; % number of k-samples
t = linspace(0,sqrt(0.5),N_k)'; % dummy variable to parameterise spiral
k_x = (1 + randn(N_k,1)/20).*t.^2.*cos(2*pi*32*t); % spiral kx-coords
k_y = (1 + randn(N_k,1)/20).*t.^2.*sin(2*pi*32*t); % spiral ky-coords
% translate and scale the numbers to make them in range [0 512]
k_x = 256 + 300*k_x;
k_y = 256 + 300*k_y;
% show scatterplot of trajectory
img = zeros(512, 512);
fig = figure();
ax = axes();
ax.Visible = 'off';
hold(ax);
imshow(img)
scatter(ax, k_x, k_y, 3, 'w', 'filled')
  2 件のコメント
Sahil
Sahil 2020 年 3 月 7 日
Thank you the plot is accurate.
However I realised i wanted a matrix containg the plot , sicne i wanted to spatially flter the a ksapce
N_k = 64^2; % number of k-samples
t = linspace(0,sqrt(0.5),N_k)'; % dummy variable to parameterise spiral
k_x = (1 + randn(N_k,1)/20).*t.^2.*cos(2*pi*32*t); % spiral kx-coords
k_y = (1 + randn(N_k,1)/20).*t.^2.*sin(2*pi*32*t); % spiral ky-coords
% translate and scale the numbers to make them in range [0 512]
k_x = 256 + 300*k_x;
k_y = 256 + 300*k_y;
% show scatterplot of trajectory
spiral = zeros(512, 512);
k_x = ceil(k_x);
k_y = ceil(k_y);
for i = 1:size(k_x)
spiral(k_x(i), k_y(i)) = 1;
end
figure('Name','Variable-density spiral matrix','NumberTitle','off');
imshow(spiral,[])
Ameer Hamza
Ameer Hamza 2020 年 3 月 7 日
編集済み: Ameer Hamza 2020 年 3 月 7 日
Yes, the general idea is the same. However, you are just converting a single pixel to white color in this case. If this is your intended result, then good; otherwise, you might consider using other functions in Matlab to draw a circle on an image with a given radius. For example check the answer here: https://www.mathworks.com/matlabcentral/answers/483147-draw-points-on-a-image or this function https://www.mathworks.com/help/vision/ref/insertshape.html

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by