简体   繁体   中英

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. My thoughts were to make a 1 XN matrix and have that matrix follow the path of the spiral. 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.

彩虹螺旋输出

PS: I'm using Octave 4.0 which is similar to Matlab

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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