How do I fade colors into each other?

7 次查看(过去 30 天)
I'm trying to get red in the top right, purple in the top left, blue in the bottom right, and green in the bottom left. However, instead of fading together the colors are staying separate of each other. What am I doing wrong?
r=256;
c=256;
d=3;
A=zeros(r,c,d);
increase=linspace (0,1,256);
decrease= linspace (1,0,256);
%Top
for i=1:256
%Top
A(1:128,i,1)=1;
A(1:128,i,3)=increase(i);
%Bottom
A(128:256,i,3)=increase(i);
A(128:256,i,2)=decrease(i);
end
imagesc(A)
I add the following into my for loop: %left
A(i,1:128,1)=decrease(i);
A(i,1:128,2)=increase(i);
%right
A(i,128:256,1)=decrease(i);
A(i,128:256,3)=increase(i);
Now I get a weird triangle thing, what am I doing wrong? I want all of them to fade into each other.

采纳的回答

Image Analyst
Image Analyst 2015-10-4
Try this:
rows = 256;
oneColumn = ((rows-1) : -1 : 0)';
redChannel = uint8(repmat(oneColumn, [1, rows]));
blueChannel = uint8(toeplitz((rows-1):-1:0));
greenChannel = uint8(toeplitz(0:(rows-1)));
triangleMask = logical(triu(ones(rows, rows)));
greenChannel(triangleMask) = 0;
rgbImage = cat(3, redChannel, greenChannel, blueChannel);
imshow(rgbImage);
  2 个评论
Krish Desai
Krish Desai 2015-10-4
just trying to understand how this works...how would I move the colors around, for instance how could I switch the red and purple?
Image Analyst
Image Analyst 2015-10-4
Just consider watch color plane one at a time. Then figure out where the 0's need to be and where the 255's need to be and use repmat(), toeplitz(), or the colon operator to replicate a single vector over the whole array.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by