简体   繁体   English

在Matlab /八度音阶中使图像遵循螺旋/方程的路径

[英]Making an image follow the path of a spiral / an equation in matlab / octave

I know I can make spirals with the example code below but how do I get an image to follow the spiral path of an equation like the one below. 我知道我可以使用下面的示例代码制作螺旋形,但是如何获得图像以遵循以下方程式的螺旋形路径。

t = linspace(0,4*pi,400);
x = t.*cos(t);
y = t.*sin(t);
plot(x,y)

螺旋图像

Example: I have an image (RGB) see below and I convert it to a 1 x N matrix. 示例:我有一个图像(RGB),请参见下面,并将其转换为1 x N矩阵。 My thoughts were to make a 1 XN matrix and have that matrix follow the path of the spiral. 我的想法是制作一个1 XN的矩阵,并使该矩阵遵循螺旋的路径。 How can I get the image to follow the path of a spiral equation? 如何使图像遵循螺旋方程的路径?

f=imread('/tmp/rgb_line.png');
[Frows Fcols Fdims]=size(f)

f=double(f); %need to convert to double to do math functions on it

for ii=1:Fdims
  img(:,:,ii)=reshape(f(:,:,ii)',1,numel(f(:,:,ii))); %reshape array as one row and 3 dimensions 
end

Rainbow line (input/reshaped matrix): 彩虹线(输入/重塑矩阵):

彩虹线图像

So the rainbow spiral output would look something like this. 因此彩虹螺旋输出看起来像这样。 Please note that the order of the colours are not correct due to the fact that this was the closest image I could find that showed what I'm trying to do. Please note that the order of the colours are not correct ,原因是这是我能找到的最接近的图像,显​​示了我要执行的操作。

彩虹螺旋输出

PS: I'm using Octave 4.0 which is similar to Matlab PS:我正在使用与Matlab相似的Octave 4.0

you can try something like this: 您可以尝试这样的事情:

rgb1 = jet(256);
len1 = size(rgb1,1);
RGB1 = permute(rgb1,[3 1 2]);
figure; imshow(RGB1);
len2 = 400;
t = linspace(0,4*pi,len2);
x = t.*cos(t);
y = t.*sin(t);
rgb2 = interp1(1:len1,rgb1,linspace(1,len1,len2));
[xg,yg] = meshgrid([-t(end:-1:2) t],[-t(end:-1:2) t]);
RGB2 = zeros([size(xg) 3]);
% interpolate for the desired coordinates
for c = 1:3
    RGB2(:,:,c) = griddata(x,y,rgb2(:,c),xg,yg);
end
figure; imshow(RGB2)

then you need to eliminate unwanted pixels using some sort of mask. 那么您需要使用某种遮罩消除不必要的像素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM